Skip to content

Instantly share code, notes, and snippets.

View jeremyroman's full-sized avatar

Jeremy Roman jeremyroman

View GitHub Profile
@jeremyroman
jeremyroman / gist:815849
Created February 8, 2011 04:24
One possible way of describing languages
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}",
},
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.
// 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 July 6, 2011 14:31
Example of CommonJS modules
var nextNumber = 0;
module.exports.getNumber = function() {
nextNumber += 1;
return nextNumber;
};
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 July 28, 2011 15:54
An HTTP importer for Sass
# 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
@jeremyroman
jeremyroman / gist:1239662
Created September 24, 2011 18:18
Java hello world
import java.lang.*;
class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello world!");
}
}
@jeremyroman
jeremyroman / gist:1240690
Created September 25, 2011 15:02
Repetition
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,
$ 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>
#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);