Skip to content

Instantly share code, notes, and snippets.

Avatar

Jeremy Roman jeremyroman

View GitHub Profile
@jeremyroman
jeremyroman / gist:815849
Created Feb 8, 2011
One possible way of describing languages
View gist:815849
languages = {
"C": {
'main_file': "{bot}.c",
'nuke_globs': ["*.o", "{bot}"],
'compile': [
System("gcc -O3 -c {file}", glob="*.c"),
System("gcc -O2 -lm -o {bot}", glob="*.o"),
],
'run': "./{bot}",
},
View gist:1057181
var f = function() {};
f.prototype.food = { apples: 0, bananas: 0 };
var f1 = new f();
f1.food.apples++;
var f2 = new f();
console.log(f2.food.apples); // 1
This is because the food object is modified in-place, and both instances refer to the same object.
View gist:1066483
// a.js
exports.message = 'hello world!';
exports.b = require('./b');
// b.js
var a = require('./a');
module.exports = function() { return a.message; }
@jeremyroman
jeremyroman / mymodule.js
Created Jul 6, 2011
Example of CommonJS modules
View mymodule.js
var nextNumber = 0;
module.exports.getNumber = function() {
nextNumber += 1;
return nextNumber;
};
View gist:1067452
var http = require('http'),
qs = require('querystring');
var body = qs.stringify({ method: 'system.connect' });
var options = {
host: 'www.goworkit.com',
port: 80,
path: '/services/json/',
method: 'POST',
headers: {
@jeremyroman
jeremyroman / sass_http.rb
Created Jul 28, 2011
An HTTP importer for Sass
View sass_http.rb
# Additional caching and such might be helpful for performance.
# Sass's regeneration only on changed files should work as long as the server provides the Last-Modified header
require 'net/http'
require 'time'
require 'sass'
module Sass
module Importers
# Importer which issues HTTP requests
View gist:1239662
import java.lang.*;
class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello world!");
}
}
View gist:1240690
public class BananaMerchant {
private final BananaFactory bananaFactory;
private final ShippingAgent shippingAgent;
private final PricingBroker pricingBroker;
private final List<Banana> bananas;
private final Map<Integer, Customer> customerMap;
public BananaMerchant(
final BananaFactory bananaFactory,
final ShippingAgent shippingAgent,
View gist:1479694
$ g++ -c monads.cc
monads.cc: In member function ‘lvector<B> Monad<lvector>::bind(lvector<A>, Function)’:
monads.cc:24: error: expected `;' before ‘it_a’
monads.cc:26: error: ‘it_a’ was not declared in this scope
monads.cc:28: error: expected `;' before ‘it_b’
monads.cc:28: error: ‘it_b’ was not declared in this scope
#include <string>
#include <vector>
View gist:1479822
#include <iostream>
#include <string>
#include <vector>
template <template <typename> class M>
class Monad {
public:
template <typename A, typename B, typename Function>
static M<B> monad_bind(M<A> in, Function function);