Skip to content

Instantly share code, notes, and snippets.

-- Stochatistic Gradient Descent in Haskell
--
-- Based on Mark Reid's implementation in Clojure:
--
-- http://github.com/mreid/injuce
--
--
-- Profiling
-- ---------
--
require "rubygems"
require "nokogiri"
require "uri"
module Rack
class KarmaChameleon
def initialize(app, options = {})
@ext = options[:extension] || "aspx"
@ext_regexp = /\.#@ext$/
@app = app
@gus
gus / index.txt
Created November 30, 2009 21:55 — forked from toothrot/index.txt
Ruby/Clojure analogs
For each Ruby module/class, we have Ruby methods on the left and the equivalent
Clojure functions and/or relevant notes are on the right.
For clojure functions, symbols indicate existing method definitions, in the
clojure namespace if none is explicitly given. clojure.contrib.*/* functions can
be obtained from http://github.com/kevinoneill/clojure-contrib/tree/master,
ruby-to-clojure.*/* functions can be obtained from the source files in this
gist.
If no method symbol is given, we use the following notation:
@mikhailov
mikhailov / redis_usage.rb
Created January 18, 2010 06:52
Rails on Redis - is all about high performance
# app/controllers/posts_controller.rb
class PostsController < ApplicationController
def index
@posts.all_cached # Retrive only at once by every 5 minutes
expires_in 5.minutes, :private => false, :public => true
end
end
# app/models/post.rb
Class Post
@gravis
gravis / resque_schedule_retry_job.rb
Created February 9, 2010 20:24
A resque job with retry on failure, dead simple. Needs resque-schedule plugin. the only caveat is that the first attempt is in the "events" queue, whereas retries are only visible in Delayed tab.
class GetEventResult
@queue = :events
def self.perform(event_id, attempt=0)
event = Event.find(event_id)
Rails.logger.info "Fetching results for event ##{event.id} (#{event.name})..."
begin
results = EventImporter.new(event.datetime.to_date).get_results(event)
rescue OpenURI::HTTPError
@maraigue
maraigue / xauth-twitter.rb
Created February 14, 2010 16:41
Requesting OAuth access token without browser, only with Twitter user name and password (so-called xAuth), by Ruby
#!/usr/bin/env ruby
# *** Important notification ***
# As xAuth is officially supported, we have to register
# your application needing xAuth, via e-mail.
# If not registered, 401 error will be returned.
# http://apiwiki.twitter.com/Twitter-REST-API-Method:-oauth-access_token-for-xAuth
#
# (*** 重要な告知 ***
# xAuthが公式にサポートされたのに伴い、xAuthの必要なアプリケーションは
@rafacv
rafacv / redis_pubsub_demo.rb
Created March 30, 2010 16:43 — forked from pietern/redis_pubsub_demo.rb
Simple demo to showcase Redis PubSub with EventMachine
# Author: Pieter Noordhuis
# Description: Simple demo to showcase Redis PubSub with EventMachine
#
# Requirements:
# - rubygems: eventmachine, thin, cramp, sinatra, yajl-ruby
# - a browser with WebSocket support
#
# Usage:
# ruby redis_pubsub_demo.rb
#
import re
# http://atomboy.isa-geek.com/plone/Members/acoil/programing/double-metaphone
from metaphone import dm as double_metaphone
# get the Redis connection
from jellybean.core import redis
import models
# Words which should not be indexed
var child_process = require('child_process'),
sys = require('sys'),
net = require('net'),
netBinding = process.binding('net');
var fd = netBinding.socket('tcp4');
netBinding.bind(fd, 8080);
netBinding.listen(fd, 128);
for (var i = 0; i < 4; i++) {
@jeromeetienne
jeromeetienne / twitter to irc from maushu
Created June 10, 2010 14:48
twitter to irc from maushu
#!/usr/local/bin/node
var sys = require('sys'),
http = require('http'),
querystring = require('querystring'),
base64 = require('./lib/base64'),
Buffer = require('buffer').Buffer,
Irc = require('./vendor/IRC/lib/irc');
var twitter_auth = { user: "<YOUR_TWITTER_USERNAME>", pass: "<YOUR_TWITTER_PASSWORD>"};