Skip to content

Instantly share code, notes, and snippets.

@moink
moink / transclose.m
Created October 25, 2011 21:20
Transitive closure solution in Matlab
function A=transclose(A)
%returns the transitive closure matrix of the input matrix
%input: A(i,j) is 1 if the binary relation if (element i) R (element j) using the %notation in the introduction
%of http://en.wikipedia.org/wiki/Transitive_closure
%
%Usage example: Implements the first example problem on https://www.4clojure.com/problem/84
%
%divideskey=[2 3 4 8 9 27];
%%I don't actually use that variable, but it keeps track of what my matrix means
%
@mislav
mislav / config.ru
Created October 16, 2011 18:32
Shortest simplest sweetest web "hello {NAME}" in Ruby
run ->(e){ p=Hash[*e['QUERY_STRING'].split(/[&=]/)]; [200, {'Content-type'=>'text/html'}, ["Hello #{p['name']}!"]] }
# https://gist.github.com/1185131
class Array
def next; self[1..-1] end
# returns a function that is the combination of a sequence of function calls
# on some external arguments. the functions combined are the elements of self.
def compose
lambda do |*args|
inject(*args) do |mem, fn|
@jehiah
jehiah / simulate_memcached.py
Created August 20, 2011 01:43
test script to simulate a partially reachable memcached instance
#!/bin/env python
"""
This is a test script to simulate a memcached instance on a server
that has gone south and is accepting connections, but generally not
responding.
The goal of this script is to help test/develop correct client
side settings for timeouts/failure scenarios
@fronx
fronx / first-n-fib.clj
Created August 3, 2011 21:08
different fibonacci implementations
(def first-n-fib
#(loop [l [] a 0 b 1 c 0]
(if (= c %)
l
(recur
(conj l a)
b
(+ a b)
(+ 1 c)))))
@michiakig
michiakig / ants.clj
Created July 19, 2011 22:37
Clojure ant sim from Rich Hickey
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Ant sim ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Copyright (c) Rich Hickey. All rights reserved.
; The use and distribution terms for this software are covered by the
; Common Public License 1.0 (http://opensource.org/licenses/cpl.php)
; which can be found in the file CPL.TXT at the root of this distribution.
; By using this software in any fashion, you are agreeing to be bound by
; the terms of this license.
; You must not remove this notice, or any other, from this software.
;dimensions of square world
require 'eventmachine'
module Client
def connection_completed
send_data "*1\r\n$4\r\nPING\r\n"
end
def receive_data(data)
p data
end
@hyone
hyone / gist:1032985
Created June 18, 2011 10:47
4clojure #53 - Longest continuous increasing subsequence
;; hyone's solution to Longest Increasing Sub-Seq
;; https://4clojure.com/problem/53
(fn longest-inc-seq [coll]
(reduce #(let [len-a (count %1)
len-b (count %2)]
(if (and (> len-b 1) (> len-b len-a)) %2 %1))
[]
(reductions
(fn [xs y]
;; jneira's solution to Transitive Closure
;; https://4clojure.com/problem/84
(fn [s]
(let [f #(for [[a b] % [c d] %
:when (= c b)] [a d])]
(->> s (iterate #(let [n (into % (f %))]
(when (not= % n) n)))
(take-while identity)
(last))))
@jed
jed / LICENSE.txt
Created May 10, 2011 16:04 — forked from 140bytes/LICENSE.txt
write contextual templates
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Jed Schmidt <http://jed.is>
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