Skip to content

Instantly share code, notes, and snippets.

@igstan
igstan / state-monad.coffee
Created April 22, 2011 11:57
State Monad in CoffeeScript
push = (element) -> (stack) ->
newStack = [element].concat stack
{value: element, stack: newStack}
pop = (stack) ->
element = stack[0]
newStack = stack.slice 1
{value: element, stack: newStack}
bind = (stackOperation, continuation) -> (stack) ->
\* Build Lisp CxRS *\
\* CC Part *\
(defcc <expr> X <expr> := [X | <expr>]; <e> := [];)
(defcc <a-d-to-head-tail>
"a" <a-d-to-head-tail> := [head <a-d-to-head-tail>];
"d" <a-d-to-head-tail> := [tail <a-d-to-head-tail>];
"r" <expr> := <expr>;)
(defcc <cxr?>
"c" "a" <a-d-to-head-tail> := [head <a-d-to-head-tail>];
@matteoagosti
matteoagosti / client.js
Created June 3, 2012 21:49
Meteor JS server side sessions
Meteor.subscribe(
'server_sessions',
amplify.store('session'), // Read from local storage / cookies
function() {
// The server returns only one record, so findOne will return that record
var serverSession = new Meteor.Collection('server_sessions').findOne();
// Stores into client session all data contained in server session;
// supports reactivity when server changes the serverSession
Session.set('serverSession', serverSession);
// Stores the server session id into local storage / cookies
if (Meteor.is_client) {
var userName = "PatelNachiket";
Template.hello.greeting = function () {
return "Fetch recent tweets from Twitter stream of user : " ;
};
Template.hello.events = {
'click #fetchButton' : function () {
console.log("Recent tweets from stream!");
$('#fetchButton').attr('disabled','true').val('loading...');
@mtmtcode
mtmtcode / auto-rsync.el
Last active September 2, 2022 00:30
auto-rsync.el - Emacs minor mode to execute rsync automaticlly
;;; auto-rsync-mode -- minor mode for auto rsync
;;
;; Author: @l3msh0
;;
;;; Example
;;
;; (require 'auto-rsync)
;; (auto-rsync-mode t)
;; (setq auto-rsync-dir-alist
@bhyde
bhyde / example-named-readtable.lisp
Last active December 26, 2016 23:03
Named-Readtables, and example.
;;;; Load some utilities
;;; ... typically this would go in our ASDF system file.
;;; in which case you wouldn't need the eval when
(eval-when (:compile-toplevel :load-toplevel :execute)
(ql:quickload "cl-interpol")
(ql:quickload "named-readtables"))
;;;; Define a package and a read table.
@cgmartin
cgmartin / gist:5880732
Last active September 15, 2018 01:22
WebSocket subprotocol and origin validation with HTTP Kit
(ns my.server
(:use org.httpkit.server
[clojure.string :only [split trim lower-case]])
(:import [org.httpkit.server AsyncChannel]))
(defn origin-match? [origin-re req]
(if-let [req-origin (get-in req [:headers "origin"])]
(re-matches origin-re req-origin)))
@jamesdwilson
jamesdwilson / meteor-create.sh
Last active December 20, 2015 13:09
Create Meteor project using meteor create, set up directory structure following the Unofficial Meteor FAQ (by oortcloud). Also initializes git and uses coffescript instead of JS. Note: I am using main.html instead of index.html as I think that is better as it loads last. To make this your default skeleton, empty your ~/.meteor/tools/latest/tools…
#!/bin/sh
# Follows https://github.com/oortcloud/unofficial-meteor-faq#where-should-i-put-my-files
# I release this into the Public domain -osirisx11 on freenode
: <<'END'
osiris@krypton:~/playpen$ ~/meteor-create.sh example
example: created.
To run your new app:
cd example
meteor
@grantslatton
grantslatton / hngen.py
Last active September 27, 2021 11:07
A program that uses Markov chains to generate probabilistic Hacker News titles.
import urllib2
import re
import sys
from collections import defaultdict
from random import random
"""
PLEASE DO NOT RUN THIS QUOTED CODE FOR THE SAKE OF daemonology's SERVER, IT IS
NOT MY SERVER AND I FEEL BAD FOR ABUSING IT. JUST GET THE RESULTS OF THE
CRAWL HERE: http://pastebin.com/raw.php?i=nqpsnTtW AND SAVE THEM TO "archive.txt"
@egamble
egamble / private.clj
Last active May 16, 2023 12:41
Two ways to call private methods in Clojure.
;; This fn allows calling any method, as long as it's the first with that name in getDeclaredMethods().
;; Works even when the arguments are primitive types.
(defn call-method
[obj method-name & args]
(let [m (first (filter (fn [x] (.. x getName (equals method-name)))
(.. obj getClass getDeclaredMethods)))]
(. m (setAccessible true))
(. m (invoke obj (into-array Object args)))))