Skip to content

Instantly share code, notes, and snippets.

@henrik
henrik / my_little_boudoir.rb
Created December 4, 2010 14:08
Simple summary-to-full-feed proxy for a RSS feed, for gf. Ruby CGI.
#!/usr/bin/env ruby
# Simple summary-to-full-feed proxy for a single, hard-coded feed.
# Caches each entry by GUID and timestamp.
FEED = "http://mylittleboudoir.com/feed/"
CACHE_DIR = "/tmp"
require "open-uri"
require "rubygems"
require "nokogiri"
@chrisyour
chrisyour / Folder Preferences
Created December 4, 2010 20:05
Show hidden files and hidden folders (except .git) in your TextMate project drawer
# Want to show hidden files and folders in your TextMate project drawer? Simple, just modify the file and folder patterns in TextMate's preferences.
# Instructions:
# Go to TextMate > Preferences...
# Click Advanced
# Select Folder References
# Replace the following:
# File Pattern
@igrigorik
igrigorik / TweetEvent.java
Created May 27, 2011 06:19
wrapping esper with JRuby embrace
// A simple Tweet POJO:
// $> javac TweetEvent.java
public class TweetEvent {
private String user;
private String text;
private String timezone;
private int retweets;
public TweetEvent(String user, String text, String timezone, int retweets) {
@viktorklang
viktorklang / ScalaEnum.scala
Created June 30, 2011 23:12
DIY Scala Enums (with optional exhaustiveness checking)
trait Enum { //DIY enum type
import java.util.concurrent.atomic.AtomicReference //Concurrency paranoia
type EnumVal <: Value //This is a type that needs to be found in the implementing class
private val _values = new AtomicReference(Vector[EnumVal]()) //Stores our enum values
//Adds an EnumVal to our storage, uses CCAS to make sure it's thread safe, returns the ordinal
private final def addEnumVal(newVal: EnumVal): Int = { import _values.{get, compareAndSet => CAS}
val oldVec = get
@alandipert
alandipert / reinvoke.cljs
Last active June 22, 2019 00:20
It's sweet that IFn is a protocol in ClojureScript
(extend-type js/RegExp
cljs.core/IFn
(-invoke ([this s] (re-matches this s))))
(#"foo.*" "foobar") ;=> "foobar"
(#"zoo.*" "foobar") ;=> nil
(filter #".*foo.*" ["foobar" "goobar" "foobaz"]) ;=> ("foobar" "foobaz")
@kriyative
kriyative / extmap.clj
Created May 9, 2012 07:03
Extending Clojure Map with `deftype` and `defprotocol`
(ns extmap
(:import
[clojure.lang ILookup Associative]))
;; ----------------------------------------------------------------
;; TrackableMap is a persistent map which keeps track of the number of
;; times `get` was called on it.
(defprotocol Trackable
(getStats [self]))
@ckirkendall
ckirkendall / clojure-match.clj
Created June 15, 2012 02:26 — forked from bkyrlach/Expression.fs
Language Compare F#, Ocaml, Scala, Clojure, Ruby and Haskell - Simple AST example
(use '[clojure.core.match :only [match]])
(defn evaluate [env [sym x y]]
(match [sym]
['Number] x
['Add] (+ (evaluate env x) (evaluate env y))
['Multiply] (* (evaluate env x) (evaluate env y))
['Variable] (env x)))
(def environment {"a" 3, "b" 4, "c" 5})
@md-5
md-5 / App.java
Created September 6, 2012 10:03
Why Netty is awesome.
package com.md_5.jcaptive;
import io.netty.bootstrap.Bootstrap;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundMessageHandlerAdapter;
import io.netty.channel.ChannelInitializer;
@disnet
disnet / scheme.sjs
Created October 8, 2012 19:02
start of scheme in sweet.js (modified from http://pastebin.com/0nPBg8LY)
macro sexp {
case () => {
;
}
case ($p) => {
$p
}
case ($x $y) => {
$x($y);
}
@samth
samth / password.rkt
Created October 15, 2012 15:10
Generating XKCD-style passwords in Racket
#lang racket
(define dict "/etc/dictionaries-common/words")
(define (choose l) (list-ref l (random (length l))))
(define words (for/list ([i (file->lines dict)]
#:when (regexp-match? "^[a-z]*$" i)
#:when (3 . < . (string-length i))
#:when (10 . > . (string-length i)))
i))