Skip to content

Instantly share code, notes, and snippets.

Matthew Gilliard mjg123

Block or report user

Report or block mjg123

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@mjg123
mjg123 / gist:956051
Created May 4, 2011
my 13 LOC chat server for node.js
View gist:956051
var http = require('http');
var url = require('url');
var messages = ["welcome to nodeChat"];
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
var query = url.parse(req.url, true).query;
if ( query.message ){
messages.push( query.message );
res.end("thanks");
} else {
@mjg123
mjg123 / SortedRespectDue.java
Created Jul 10, 2011
Testing the behaviour of mergesort in Java's core implementation
View SortedRespectDue.java
import java.util.Arrays;
import java.util.Random;
/**
* Created by Matthew Gilliard
* Date: 10/07/11
* Time: 18:22
*/
public class SortedRespectDue {
@mjg123
mjg123 / SortedRespectDue.java
Created Jul 10, 2011
Testing the behaviour of mergesort in Java's core implementation
View SortedRespectDue.java
import java.util.Arrays;
import java.util.Random;
/**
* Created by Matthew Gilliard
* Date: 10/07/11
* Time: 18:22
*/
public class SortedRespectDue {
@mjg123
mjg123 / MergeSort.java
Created Jul 10, 2011
Source of mergesort from Java 6
View MergeSort.java
/**
* Src is the source array that starts at index 0
* Dest is the (possibly larger) array destination with a possible offset
* low is the index in dest to start sorting
* high is the end index in dest to end sorting
* off is the offset to generate corresponding low, high in src
*/
private static void mergeSort(Object[] src,
Object[] dest,
@mjg123
mjg123 / hello.cljs
Created Jul 21, 2011
Hello World in ClojureScript
View hello.cljs
(ns hello)
(defn ^:export greet [n]
(str "Hello " n))
@mjg123
mjg123 / hello.js
Created Jul 21, 2011
hello.cljs compiled
View hello.js
function b(c){throw c;}var f=null;function aa(){return function(c){return c}}function i(c){return function(){return this[c]}}function j(c){return function(){return c}}var k;
function n(c){var a=typeof c;if(a=="object")if(c){if(c instanceof Array)return"array";else if(c instanceof Object)return a;var d=Object.prototype.toString.call(c);if(d=="[object Window]")return"object";if(d=="[object Array]"||typeof c.length=="number"&&typeof c.splice!="undefined"&&typeof c.propertyIsEnumerable!="undefined"&&!c.propertyIsEnumerable("splice"))return"array";if(d=="[object Function]"||typeof c.call!="undefined"&&typeof c.propertyIsEnumerable!="undefined"&&!c.propertyIsEnumerable("call"))return"function"}else return"null";
else if(a=="function"&&typeof c.call=="undefined")return"object";return a}function ba(c){return typeof c=="string"}Math.floor(Math.random()*2147483648).toString(36);var ca={"\000":"\\0","\u0008":"\\b","\u000c":"\\f","\n":"\\n","\r":"\\r","\t":"\\t","\u000b":"\\x0B",'"':'\\"',"\\":"\\\\"},da={"'":"\\'"};
fun
@mjg123
mjg123 / map2map.clj
Created Jul 21, 2011
function to turn a clojure map into a js map in ClojureScript
View map2map.clj
(defn make-js-map
"makes a javascript map from a clojure one"
[cljmap]
(reduce #(aset %1 (name (first %2)) (second %2)) (js-obj) cljmap))
; (make-js-map {:a "Hello"}) returns "Hello", not the js-map :(
@mjg123
mjg123 / ajax.cljs
Created Jul 21, 2011
How to make a json(p) request from ClojureScript using jQuery
View ajax.cljs
(def jquery (js* "$"))
(defn show [msg]
(let [data-as-json ((js* "JSON.stringify") msg nil 4)]
((js* "alert") data-as-json)))
(defn make-js-map
"makes a javascript map from a clojure one"
[cljmap]
(let [out (js-obj)]
@mjg123
mjg123 / helloclosure.cljs
Created Jul 21, 2011
Same jsonp call as before but with gclosure instead of jQuery
View helloclosure.cljs
(ns helloclosure
(:require [goog.net.Jsonp :as jsonp]))
(defn show [msg]
(let [data-as-json ((js* "JSON.stringify") msg nil 4)]
((js* "alert") data-as-json)))
(defn doajax []
(.send (goog.net.Jsonp. (goog.Uri. "http://api.stackoverflow.com/1.1/users/268619") "jsonp")
nil
@mjg123
mjg123 / calculate.clj
Created Jul 25, 2011
Why can't I recur here?
View calculate.clj
(defn calculate
"A list of coin-values from coins, which sum to target"
[coins target]
(let [coin (max-coin coins target)]
(cond
(not coin) (js-alert "No solution")
(= coin target) (list coin)
(< coin target) (cons coin (recur coins (- target coin))))))
You can’t perform that action at this time.