• About
  • Everyday Linux Commands

<roughCode/>

~ …so I can find it

Category Archives: Code Samples

A cool row selection

22 Tuesday Jan 2013

Posted by Scott in C#, Code Samples

≈ Comments Off on A cool row selection

Tags

C#

A co-worker had something like this in a project, and I thought it was pretty neat.  A lot cleaner than what I’ve been doing recently:

DataSet ds = GetDataFromSomeWhere();
IEnumerable<DataRow> rows = null;
rows = from row in ds.Tables[0].AsEnumerable()
       where (row.Field<String>("ColumnA").ToUpper() == myValue
       || row.Field<String>("ColumnA").ToUpper() == "SomeOtherValue")
       && row.Field<String>("ColumnB").ToUpper() == aBoolean.ToString().ToUpper()
       && row.Field<String>("ColumnC").ToUpper() == "SomeDifferentValue"
       select row;
foreach (DataRow row in rows)
{
    // stuff
}
Advertisement

C# ASP.Net find index of item in DropDownList by text

18 Friday Jan 2013

Posted by Scott in C#, Code Samples

≈ Comments Off on C# ASP.Net find index of item in DropDownList by text

Tags

asp.net, C#

Another little trick from today — I have the text value of the item, but I need to find the index so I can set it to Selected…

dDList.SelectedIndex = dDList.Items.IndexOf(dDList.Items.FindByText(stringValue));

ASP.net update control in parent page from acsx user control

18 Friday Jan 2013

Posted by Scott in C#, Code Samples

≈ Comments Off on ASP.net update control in parent page from acsx user control

Tags

asp.net, C#

Needed to update a treeview control (oh noes!) on the page from an ascx user control. It was easier than I expected…

// path value for the tree node to update:
string path = string.Format("0/{0}/{1}/{2}", this.Group, this.Trend, this.NID);
// find the treeview control in the page controls collection:
TreeView tvc = Page.FindControl("tvEvents") as TreeView;
//magic!
tvc.FindNode(path).ImageUrl = im;

Find Active Directory user by SMTP Email Address

11 Friday Jan 2013

Posted by Scott in C#, Code Samples

≈ Comments Off on Find Active Directory user by SMTP Email Address

Tags

active directory, C#

We’re always having to look up users in AD by some value or another.  The newest twist was to take an SMTP e-mail address and find the sAMAccountName (LAN login) for that user.  We couldn’t just use the mail value because a lot of users may have more than one SMTP e-mail address…for nick-names and the like.  So, it’s DirectorySearcher to the rescue!  Code after the break uses an OR in the DirectorySearcher’s Filter property to look at PRIMARY SMTP addresses — proxyaddresses=SMTP:{0} OR OTHER SMTP addresses — proxyaddresses=smtp:{0} to find a match.  Notice the case difference there?

Continue reading →

JQuery and Ajax Auto Refresh a DIV

28 Wednesday Nov 2012

Posted by Scott in Code Samples

≈ Comments Off on JQuery and Ajax Auto Refresh a DIV

Tags

ajax, javascript

javascript code below, context to follow:

$(document).ready(function () {

    var showPending = function () {
        // add the progress indicator
        $('#Pending').addClass('loading').show();

        $.ajax({
            type: "POST",
            url: "PortalService.asmx/GetSeasonalCounts",
            dataType: "json",
            data: "{ 'option':'" + "pending" + "' }",
            contentType: "application/json; charset=utf-8",
            success: function (msg) {
                // Hide the fake progress indicator graphic.
                $('#Pending').removeClass('loading');
                // Insert the returned HTML into the <div>.
                $('#Pending').empty();
                $('#Pending').html(msg.d);
            }
        });
        window.setInterval(showPending, 1200000)
    }
}

 

 

DataRepeater (VB Power Pack) Tips and Tricks

23 Friday Nov 2012

Posted by Scott in C#, Code Samples

≈ Comments Off on DataRepeater (VB Power Pack) Tips and Tricks

Tags

C#

Values from a control on the selected item — http://msdn.microsoft.com/en-us/library/microsoft.visualbasic.powerpacks.datarepeater.currentitem.aspx

Also, you can’t bind to an object list, but you can create a dataset from an object and bind to that.

Using TX Text Control

20 Tuesday Nov 2012

Posted by Scott in C#, Code Samples

≈ Comments Off on Using TX Text Control

Tags

C#

Trying out the TX Text Control for a project, and wanted to make some notes on loading and saving RTF data.  Here’s what I’ve got so far using String data.

// a is a generic object with a string property named A
private void button2_Click(object sender, EventArgs e)
{
    string data = "";
    textControl1.Save(out data,TXTextControl.StringStreamType.RichTextFormat);
    a.A = data;
}

private void button3_Click(object sender, EventArgs e)
{
    textControl1.Clear();
    textControl1.Load(a.A,TXTextControl.StringStreamType.RichTextFormat);
}

Since I’ll be saving to and loading from a SQLite database, I’ll be trying again with binary data, but this seems to be a good starting point.


					

C# List to string

26 Friday Oct 2012

Posted by Scott in C#, Code Samples

≈ Comments Off on C# List to string

Tags

C#

This may already be here somewhere, but I use it a lot.
http://www.dotnetperls.com/convert-list-string
given:

List a = new List()
// add some things
string r = string.Join(",", a.ToArray());

 

 

Validate your JAVA_OPT values in a Tomcat instance

04 Thursday Oct 2012

Posted by Scott in Apache Tomcat, Application Servers, Code Samples, Java, Linux / UNIX

≈ Comments Off on Validate your JAVA_OPT values in a Tomcat instance

Tags

jsp, tomcat

Short version (to be edited later) add the code after the jump to a JSP page in your Tomcat instance. I just copied index.jsp in the default ROOT application and added some thing like this (thanks http://threebit.net/mail-archive/tomcat-users/msg09868.html)

Continue reading →

java.lang.UnsatisfiedLinkError: no lwjgl in java.library.path

26 Sunday Aug 2012

Posted by Scott in Code Samples, Java

≈ Comments Off on java.lang.UnsatisfiedLinkError: no lwjgl in java.library.path

Tags

Java, maven

On a team doing a java project (not the one for work. I hate that one and wish I could find a new job, it sucked that much joy out of life) got the java.lang.UnsatisfiedLinkError: no lwjgl in java.library.path error when I tried to run a reference project I was reviewing.

The two answers that I liked the most (because I could have just imported the lwjgl jar, but then the project would have that reference to the path on my Mac, and the source I downloaded had the authors Windows path, so it’s all stupid at this point) were to use a plugin to extend the M2E Maven plugin for Eclipse — see http://maven.40175.n5.nabble.com/How-to-manage-librairy-with-native-dll-in-maven-td5652069.html … basically add the http://mavennatives.googlecode.com/svn/eclipse-update/ location when adding software to eclipse and then add the plugin…

then add the following to your pom.xml:

<plugin>
  <groupId>com.googlecode.mavennatives</groupId>
  <artifactId>maven-nativedependencies-plugin</artifactId>
  <version>0.0.6</version>
  <executions>
    <execution>
      <id>unpacknatives</id>
      <phase>generate-resources</phase>
      <goals>
        <goal>copy</goal>
      </goals>
    </execution>
  </executions>
</plugin>

 

— and then add

-Djava.library.path=target/natives

to the VM arguments in your run configuration — https://groups.google.com/forum/?fromgroups=#!topic/playn/E2t7gNh4ab0 is where I got that one.

And it was all good.  The reference project in questions sucked, but at least I was able to get Maven to do what I think it should do…

← Older posts

Recent Posts

  • Bulk commands to install PHP and MySQL on CentOS 7
  • Four year gap? No, had just been self-hosting for a while
  • winhttpcertcfg.exe Example
  • Configure Tomcat 7 to use HTTPS
  • SCP on Mac (and a tool for Windows)

Archives

  • November 2018
  • October 2018
  • October 2014
  • September 2014
  • August 2014
  • July 2014
  • January 2013
  • December 2012
  • November 2012
  • October 2012
  • September 2012
  • August 2012
  • July 2012

Categories

  • Apache Tomcat
  • Apache Web Server
  • Application Servers
  • C#
  • CMS
  • Code Samples
  • Databases
  • Development Tools
  • Drupal
  • IIS
  • Java
  • Linux / UNIX
  • MS SQL Server
  • Networking
  • Operating Systems
  • Oracle
  • Uncategorized
  • Video Games
  • Windows
  • WordPress

Meta

  • Register
  • Log in
  • Entries feed
  • Comments feed
  • WordPress.com

Create a free website or blog at WordPress.com.

Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here: Cookie Policy
  • Follow Following
    • <roughCode/>
    • Already have a WordPress.com account? Log in now.
    • <roughCode/>
    • Customize
    • Follow Following
    • Sign up
    • Log in
    • Report this content
    • View site in Reader
    • Manage subscriptions
    • Collapse this bar