This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Node { | |
| def next | |
| def data | |
| } | |
| def n3 = new Node(data:"three", next:null) | |
| def n2 = new Node(data:"two", next:n3) | |
| def n1 = new Node(data:"one", next:n2) | |
| class MyList { def firstNode } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //load jars | |
| String jar_class_path = ? | |
| def jardir = new File(jar_class_path) | |
| def jars = jardir.listFiles().findAll { it.name.endsWith('.jar') } | |
| jars.each { this.class.classLoader.rootLoader.addUrl( it.toURI().toURL() ) } | |
| def props = new Properties() | |
| props.putAll( ['mail.smtp.host':'localhost', 'mail.smtp.timeout':20000', 'mail.smtp.connectiontimeout':'20000']) | |
| //wire up Spring |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //simple validation method in Groovy | |
| def validateIt(Map params, List requiredList, Map requiredSizeMap) { | |
| def message = '' | |
| for (e in params) { | |
| if (e.key in requiredList) { | |
| if (!e.value) { message += "${e.key} is required\n" } | |
| } | |
| if (e.key in requiredSizeMap.keySet()) { | |
| def validSize = requiredSizeMap[e.key] | |
| if (e.value.size() > validSize) { message += "${e.key} cannot be more than ${validSize} characters\n" } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| db.things.insert({name:'joe', state:'va'}) | |
| db.things.insert({name:'jane', state:'va'}) | |
| db.things.insert({name:'sally', state:'md'}) | |
| var m = function() { emit( this.state, {count:1}); } | |
| var r = function() (key, values) { | |
| var result = { count: 0 } | |
| values.forEach(function(value) { result.count++ } ); | |
| return result; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function randomOne(from, to) { | |
| return Math.floor(Math.random() * (to - from + 1) + from); | |
| } | |
| var name = ['tom', 'jeff', 'carol', 'mike', 'robert', 'suzan', 'wendy'] | |
| var st = ['va', 'md', 'ny', 'ca', 'fl', 'oh', 'mi']; | |
| var food = ['pizza', 'hamburger', 'spaghetti', 'burrito', 'seafood', 'indian', 'thai'] | |
| var quote = ['abc abc abc abc....', 'cba cba cba cba....', 'xyz xyz xyz...', | |
| 'jio jio jio....', 'oww oww oww...', 'fow fow fow...', 'soi soi soi...'] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'rubygems' | |
| require 'mongo' | |
| @conn = Mongo::Connection.new | |
| @db = @conn['geo-db'] | |
| @coll = @db['places'] | |
| File.open("US.txt", "r").each do | line | | |
| sp = line.split("\t") | |
| #country zip state region lat long |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| The key is to map unique roman numerals to binary values, then start from traversing through the list from high values to low values. | |
| When binary is greater, start building the roman string, subtracting from the binary as you go. | |
| Takeaway: If writing a conversion problem, make list mapping one to another. Also, look for "shortcuts" or patterns to avoid full lists mapping each value. | |
| */ | |
| def binaryToRoman(int binary) { | |
| def RCODE = ["M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var App = { | |
| something: function(args1, callback) { | |
| console.log("in something 2"); | |
| callback.apply(App, arguments); | |
| return false; | |
| }, | |
| dothis: function() { | |
| var l = ['one','two']; | |
| var s = "hi"; | |
| App.something(s, function(args1) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta charset="utf-8" /> | |
| <title>QUnit Tests</title> | |
| <link rel="stylesheet" href="qunit.css"> | |
| </head> | |
| <body> | |
| <h1 id="qunit-header">QUnit Hello World</h1> | |
| <h2 id="qunit-banner"></h2> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <html> | |
| <head> | |
| <script type="text/javascript" src="jquery-1.7.1.min.js"></script> | |
| <script type="text/javascript" src="underscore-min.js"></script> | |
| <script> | |
| $(document).ready(function() { | |
| var people_records = {people:[{first_name:'joe', last_name:'shmo'}, {first_name:'jane', last_name:'smith'}]}; | |
| var row_template = "<% _.each(people, function(obj) { %> <tr> <td> <%= obj.first_name %> </td> <td> <%= obj.last_name %> </td> </tr> <% }); %>"; | |
| $("#table_rows").html( _.template( row_template, people_records ) ); |