Skip to content

Instantly share code, notes, and snippets.

View fogus's full-sized avatar
💭
attempting to learn how to better learn

Fogus fogus

💭
attempting to learn how to better learn
View GitHub Profile
@fogus
fogus / twicl
Created November 9, 2008 23:24 — forked from leahneukirchen/twicl
#!/usr/bin/env ruby
# -*- ruby -*-
# twitter command line client
# That's What I Call Lame
# 09nov2008 +chris+
require 'json'
require 'open-uri'
(ns org.apache.http.examples
"Basic HTTP Server.
A quick port of http://svn.apache.org/repos/asf/httpcomponents/httpcore/trunk/httpcore/src/examples/org/apache/http/examples/ElementalHttpServer.java to Clojure"
(:import (java.io File OutputStreamWriter InterruptedIOException IOException)
(java.net ServerSocket URLDecoder)
(java.util Locale)
(org.apache.http.protocol BasicHttpProcessor HttpContext BasicHttpContext HttpRequestHandler HttpRequestHandlerRegistry HttpService ResponseConnControl ResponseContent ResponseDate ResponseServer)
(org.apache.http ConnectionClosedException HttpEntity HttpEntityEnclosingRequest HttpException HttpRequest HttpResponse HttpServerConnection HttpStatus MethodNotSupportedException)
(org.apache.http.entity ContentProducer EntityTemplate FileEntity)
(org.apache.http.impl DefaultConnectionReuseStrategy DefaultHttpResponseFactory DefaultHttpServerConnection)
(ns tiger
(:import ( org.apache.commons.net.ftp FTP FTPClient))
(:require [com.github.kyleburton.sandbox.ftp :as ftp])
(:use [ clojure.contrib.str-utils :as str]))
(def *tiger-ftp-url* "ftp://anonymous:user%40host.com@ftp2.census.gov/geo/tiger/TIGER2008/")
(ftp/list-all *tiger-ftp-url*)
(ftp/list-files *tiger-ftp-url*)
(ftp/list-directories *tiger-ftp-url*)
#!/usr/bin/ruby
# Trivial little twitter script
# Pass it a list of names as command line arguments
# and it will return a list of all people who follow everyone in the
# list.
# A person is implicitly assumed to follow themselves, so if foo follows
# bar and bar follows foo then common_followers foo bar would include
# both foo and bar in the output, but if bar did not follow foo it
# would include neither.
package retweetrec
import scala.xml.XML
import java.net.URL
import java.io.InputStream
object ReTweetRec {
def getFollowers(id: String) = {
val data = new URL("http://twitter.com/followers/ids/" + id + ".xml").getContent
"""
Simple forking echo server built with Python's SocketServer library. A more
Pythonic version of http://gist.github.com/203520, which itself was inspired
by http://tomayko.com/writings/unicorn-is-unix.
"""
import os
import SocketServer
class EchoHandler(SocketServer.StreamRequestHandler):
@fogus
fogus / rlsp.rb
Created November 9, 2009 02:02 — forked from h0rs3r4dish/rlsp.rb
#!/usr/bin/ruby
RLSP_VERSION = "1.4.1"
class Lambda
attr_accessor :args, :body
def initialize(args=[],body="")
@args = (args.class == Array) ? args : [args]
@body = body
end
(defprotocol Matchable (match [me matcher]))
(defmacro data [name & constructors]
`(do
(defprotocol ~name)
(defprotocol ~(symbol (str "match-"name))
~@(for [[const & args] constructors]
`(~(symbol (str "match-"const)) [_# ~@args])))
~@(for [[const & args] constructors]
@fogus
fogus / gist:265107
Created December 29, 2009 02:32 — forked from agentcoops/gist:265069
(defn listify [orig-list]
"Turns (1 2 3 ...) into (1 (2 (3 (...)))) using continuation passing style."
(loop [lst orig-list cont identity]
(if (= () lst)
(cont ())
(recur (rest lst)
(fn [insert]
(cont (cons (first lst)
(list insert))))))))
@fogus
fogus / xset.clj
Created January 8, 2010 18:39 — forked from Chouser/xset.clj
(defn xseq [t]
(when t
(concat (xseq (:l t)) [(:root t)] (xseq (:r t)))))
(defn xconj [t v]
(cond
(nil? t) {:root v :l nil :r nil}
(< v (:root t)) {:root (:root t) :l (xconj (:l t) v) :r (:r t)}
:else {:root (:root t) :l (:l t) :r (xconj (:r t) v)}))