Skip to content

Instantly share code, notes, and snippets.

View webdevwilson's full-sized avatar

Kerry Wilson webdevwilson

View GitHub Profile
@webdevwilson
webdevwilson / State.java
Created March 29, 2013 16:38
Enum containing states with abbreviations
import java.util.HashMap;
import java.util.Map;
public enum State {
ALABAMA("Alabama", "AL"), ALASKA("Alaska", "AK"), AMERICAN_SAMOA("American Samoa", "AS"), ARIZONA("Arizona", "AZ"), ARKANSAS(
"Arkansas", "AR"), CALIFORNIA("California", "CA"), COLORADO("Colorado", "CO"), CONNECTICUT("Connecticut", "CT"), DELAWARE(
"Delaware", "DE"), DISTRICT_OF_COLUMBIA("District of Columbia", "DC"), FEDERATED_STATES_OF_MICRONESIA(
"Federated States of Micronesia", "FM"), FLORIDA("Florida", "FL"), GEORGIA("Georgia", "GA"), GUAM("Guam", "GU"), HAWAII(
"Hawaii", "HI"), IDAHO("Idaho", "ID"), ILLINOIS("Illinois", "IL"), INDIANA("Indiana", "IN"), IOWA("Iowa", "IA"), KANSAS(
load('vertx.js');
vertx.fileSystem.mkDir('a/b/c/d', true, function(err, res) {
if (!err) {
vertx.logger.info('Directory created ok');
} else {
vertx.logger.info(err);
}
});
// vert.x version: vert.x-1.3.0.final
@webdevwilson
webdevwilson / js.dart
Created July 22, 2012 19:38
The js.dart library provides simple synchronous JS invocation from Dart in a browser setting (Dartium or via dart2js).
// Copyright 2012, the Dart project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
public class DataSourceModule extends AbstractModule {
private DataSource dataSource;
private final String jndiName;
public DataSourceModule(final String jndiName)
{
this.jndiName = jndiName;
}
@webdevwilson
webdevwilson / DataSource.java
Created February 29, 2012 16:45
JndiDataSource
import com.google.inject.AbstractModule;
import javax.naming.InitialContext;
public class DataSource
{
public static AbstractModule fromJndi(final String jndiName)
{
return new AbstractModule()
{
@webdevwilson
webdevwilson / html-unit-getting-started.java
Created February 4, 2012 20:22
HtmlUnit getting started
// from HtmlUnit getting started
final WebClient webClient = new WebClient();
final HtmlPage page = webClient.getPage("http://htmlunit.sourceforge.net");
final DOMNodeSelector cssSelector = new DOMNodeSelector(page.getDocumentElement());
final Set elements = cssSelector.querySelectorAll("div.section h2");
final Node first = elements.iterator().next();
assertThat(first.getTextContent(), equalTo("HtmlUnit"));
@webdevwilson
webdevwilson / column-priority-sql-search-2
Created February 4, 2012 19:16
column priority sql search #2
SELECT Members.*,
NAME_SRCH.RANK AS rank1, SRCH.RANK AS rank2
FROM Members LEFT OUTER JOIN
FREETEXTTABLE(Members, name, ‘breakfast’) NAME_SRCH ON
Members.memberID = NAME_SRCH.[KEY] LEFT OUTER JOIN
FREETEXTTABLE(Members, *, ‘breakfast’) SRCH ON
Members.memberID = SRCH.[KEY]
ORDER BY rank1 DESC, rank2 DESC
@webdevwilson
webdevwilson / column-priority-sql-search-1.sql
Created February 4, 2012 19:14
column priority sql search 1
SELECT Members.*, SEARCH_TBL.RANK AS rank
FROM Members INNER JOIN
FREETEXTTABLE(Members, *, ‘breakfast’) SEARCH_TBL
ON Members.memberID = SEARCH_TBL.[KEY]
ORDER BY rank DESC
@webdevwilson
webdevwilson / git-ssl.sh
Created February 4, 2012 18:59
Host git over SSL
# on your server (via ssh)
mkdir ~/git/yourprojectname.git
cd ~/git/yourprojectname.git
git --bare init
# in your project directory (on your local machine):
# setup your user info
git config --global user.name "Firstname Lastname"
@webdevwilson
webdevwilson / WebTestBase.java
Created February 4, 2012 18:53
jquery HtmlUnit base class
public class WebTestBase {
protected WebClient webClient;
protected HtmlPage htmlPage;
protected void goTo(final String url){
return (HtmlPage)webClient.getPage(url);
}