Skip to content

Instantly share code, notes, and snippets.

@ghoseb
ghoseb / ns-cheatsheet.clj
Last active April 11, 2024 05:28 — forked from alandipert/ns-cheatsheet.clj
Clojure ns syntax cheat-sheet
;;
;; NS CHEATSHEET
;;
;; * :require makes functions available with a namespace prefix
;; and optionally can refer functions to the current ns.
;;
;; * :import refers Java classes to the current namespace.
;;
;; * :refer-clojure affects availability of built-in (clojure.core)
;; functions.
@banksean
banksean / mersenne-twister.js
Created February 10, 2010 16:24
a Mersenne Twister implementation in javascript. Makes up for Math.random() not letting you specify a seed value.
/*
I've wrapped Makoto Matsumoto and Takuji Nishimura's code in a namespace
so it's better encapsulated. Now you can have multiple random number generators
and they won't stomp all over eachother's state.
If you want to use this as a substitute for Math.random(), use the random()
method like so:
var m = new MersenneTwister();
@mrjjwright
mrjjwright / nosqlite_blueprint.txt
Created April 29, 2010 20:35
The blueprint for a radically new version of my project NoSQLite
Topic
- NoSQLite
- Consider 3 useful things:
- SQLite - SQLite is itself a great datastore because it is a
fast and powerful SQL database in one file and is widely
deployed and supported.
- JSON - JSON is a simple and cruft free way to describe and
transport objects. That is why programmers love it. There is
good support for it in virtually every language.
- HTTP - HTTP allows things to connect and talk to each other.
@davidminor
davidminor / partition-between.clj
Created January 7, 2011 17:14
Clojure - Split a collection into partitions on boundaries specified by supplied function.
(defn partition-between
"Splits coll into a lazy sequence of lists, with partition
boundaries between items where (f item1 item2) is true.
(partition-between = '(1 2 2 3 4 4 4 5)) =>
((1 2) (2 3 4) (4) (4 5))"
[f coll]
(lazy-seq
(when-let [s (seq coll)]
(let [fst (first s)]
(if-let [rest-seq (next s)]
@fwielstra
fwielstra / api.js
Created June 14, 2011 14:46
An example NodeJS / Mongoose / Express application based on their respective tutorials
/* The API controller
Exports 3 methods:
* post - Creates a new thread
* list - Returns a list of threads
* show - Displays a thread and its posts
*/
var Thread = require('../models/thread.js');
var Post = require('../models/post.js');
@clintel
clintel / gist:1155906
Created August 19, 2011 02:40
Fenced code in bullet lists with GitHub-flavoured MarkDown??

Fenced code blocks inside ordered and unordered lists

  1. This is a numbered list.

  2. I'm going to include a fenced code block as part of this bullet:

    Code
    More Code
    
@Melipone
Melipone / remove-duplicates
Created October 14, 2011 14:53
remove-duplicates in clojure based on the distinct function
(defn remove-duplicates
"Returns a lazy sequence of the elements of coll with duplicates removed using a predicate"
[coll pred]
(let [step (fn step [xs seen]
(lazy-seq
((fn [[f :as xs] seen]
(when-let [s (seq xs)]
(if (some #(pred f %) seen)
(recur (rest s) seen)
(cons f (step (rest s) (conj seen f))))))
@podefr
podefr / LICENSE.txt
Created October 25, 2011 12:54 — forked from 140bytes/LICENSE.txt
Finite State Machine
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Olivier Scherrer
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@NicolasZanotti
NicolasZanotti / main.js
Created January 10, 2012 16:41
Render HTML content to a PDF file with wkhtmltopdf and Node.js
var http = require('http');
var sys = require('sys');
var exec = require('child_process').exec;
var util = require('util');
var fs = require('fs');
http.createServer(function(request, response) {
var dummyContent = '<!doctype html><html><head><title>Test</title><meta charset="utf-8"></head><body><p>Hello world!</p></body></html>';
var htmlFileName = "page.html", pdfFileName = "page.pdf";
@ssp
ssp / git-extract-file.markdown
Created January 23, 2012 13:21
Extract a single file from a git repository

How to extract a single file with its history from a git repository

These steps show two less common interactions with git to extract a single file which is inside a subfolder from a git repository. These steps essentially reduce the repository to just the desired files and should performed on a copy of the original repository (1.).

First the repository is reduced to just the subfolder containing the files in question using git filter-branch --subdirectory-filter (2.) which is a useful step by itself if just a subfolder needs to be extracted. This step moves the desired files to the top level of the repository.

Finally all remaining files are listed using git ls, the files to keep are removed from that using grep -v and the resulting list is passed to git rm which is invoked by git filter-branch --index-filter (3.). A bit convoluted but it does the trick.

1. copy the repository to extract the file from and go to the desired branch