Skip to content

Instantly share code, notes, and snippets.

View greghelton's full-sized avatar

Greg Helton greghelton

View GitHub Profile
@greghelton
greghelton / unless.clj
Created December 27, 2011 00:12
Clojure: define the unless function and use in examples
(defn unless [test expr] (if-not (eval test) (eval expr)))
(prn (unless (odd? 11) (str "it's good to be " 11)))
(prn (unless (odd? 12) (str "it's good to be " 12)))
(defn only-if-even [x] (unless (odd? x) (str "it's good to be " x)))
(prn (str 6 " " (only-if-even 6)))
(prn (str 5 " " (only-if-even 5)))
@greghelton
greghelton / selectors.html
Created December 27, 2011 00:33
JQuery Selectors
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>JQuery Selectors</title>
</head>
<body>
<p>$("p") selects all <p> elements.</p>
<p>$("p.intro") selects all <p> elements with class="intro".</p>
@greghelton
greghelton / build.xml
Created December 27, 2011 03:33
ANT: Project for Managing a SQLite Database
<project name="sqlite" basedir="." default="echo">
<property name="sqldriver.jar" value="${user.home}/dev/bin/sqlite/sqlitejdbc-v056.jar"/>
<property name="db.name" value="programmers.db"/>
<property name="url" value="jdbc:sqlite:data"/>
<property name="driver" value="org.sqlite.JDBC"/>
<property name="userid" value="root"/>
<property name="password" value="root"/>
<target name="echo">
@greghelton
greghelton / cookbook.sql
Created January 1, 2012 06:41
MySQL Database for Cookbook, Recipes, Ingredients
-- start the server: $ mysqld --console
-- login: $ mysql -u root --password=wxyz
-- run the script: mysql> source /Users/javapro/dev/src/sql/Cookbook.sql
-- the script:
drop database if exists Cookbook;
create database Cookbook;
connect Cookbook;
@greghelton
greghelton / MovieEngagement.sql
Created January 1, 2012 21:42
MySQL Database for Movie Theater, Screens and Movies
create database MovieEngagement;
connect MovieEngagement;
create table Theater (
id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(50) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
create table Screen (
@greghelton
greghelton / node-mysql-recipes.js
Created February 6, 2012 03:57
MySQL Results in node.js
var http = require('http')
, mysql = require('mysql');
var client = mysql.createClient({
user: 'root',
password: ''
});
client.useDatabase('cookbook');
@greghelton
greghelton / app.jruby
Created February 15, 2012 04:39
JRuby gives me the opportunity to find which is worse, my Swing or my Ruby
require 'java'
swing_classes = %w(JFrame JButton JList JSplitPane
JTabbedPane JTextPane JScrollPane JEditorPane
DefaultListModel ListSelectionModel BoxLayout
JScrollPane JTree tree.TreeModel
text.html.HTMLEditorKit tree.DefaultMutableTreeNode tree.TreeNode)
swing_classes.each do |c|
java_import "javax.swing.#{c}"
end
@greghelton
greghelton / datepicker.html
Created February 23, 2012 05:00
A working example of jQuery UI Datepicker, you supply the image file
<html>
<head>
<link rel="stylesheet" type="text/css" media="screen"
href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.1/themes/ui-lightness/jquery-ui.css" />
</head>
<body>
<p>Date: <input id=fromdt type=text></p>
<div style="display: none" class=demo-description></div>
<p>Date: <input id=todate type=text></p>
<div style="display: none" class=demo-description></div>
@greghelton
greghelton / Test_Calc.rb
Created March 3, 2012 19:29
Let's create a failing test in Test::Unit
require 'test/unit'
class Calc
def add(a,b)
6
end
end
class TestAdd < Test::Unit::TestCase
def test_add
@greghelton
greghelton / TestCalc.rb
Created March 3, 2012 20:15
Let's create a failing test including shoulda
require 'rubygems'
require 'shoulda'
require 'test/unit'
class Calc
def add(a,b)
6
end
end