Skip to content

Instantly share code, notes, and snippets.

View jtoy's full-sized avatar

jtoy

View GitHub Profile
@torsten
torsten / proxy.rb
Last active April 30, 2024 17:53
A quick HTTP proxy server in Ruby.
#!/usr/bin/env ruby
# A quick and dirty implementation of an HTTP proxy server in Ruby
# because I did not want to install anything.
#
# Copyright (C) 2009-2014 Torsten Becker <torsten.becker@gmail.com>
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
@tmm1
tmm1 / em-irb-console.rb
Created July 12, 2009 01:17
networked irb server/client in EM
require 'rubygems'
require 'eventmachine'
module Console
PROMPT = "\n>> ".freeze
def post_init
send_data PROMPT
send_data "\0"
end
@timcharper
timcharper / console
Created July 9, 2010 06:08
script/console that loads your .irbrc before activating bundler
#!/usr/bin/env ruby
require "irb"
load "#{ENV['HOME']}/.irbrc"
def IRB.run_config; end
ARGV.unshift "console"
load File.dirname(__FILE__) + "/rails"
class FanCount
@queue = "FanCount"
include Mongoid::Document
field :page_id
field :fans
field :date, :type => DateTime
index :page_id, :unique => true, :background => true
index(
coll = db.foo
coll.drop()
coll.insert( { arr : [ { a : 1 } , { b : 2 } , { c : 3 } ] } )
coll.insert( { arr : [ { a : 2 } , { b : 3 } , { c : 1 } ] } )
coll.insert( { arr : [ { a : 3 } , { b : 1 } , { c : 2 } ] } )
coll.ensureIndex( { arr : -1 } )
@nz
nz / Delete all documents in a Solr index using curl.md
Last active February 12, 2024 10:55
Delete all documents in a Solr index using curl
# http://wiki.apache.org/solr/FAQ#How_can_I_delete_all_documents_from_my_index.3F
# http://wiki.apache.org/solr/UpdateXmlMessages#Updating_a_Data_Record_via_curl

curl "http://index.websolr.com/solr/a0b1c2d3/update?commit=true" -H "Content-Type: text/xml" --data-binary '<delete><query>*:*</query></delete>'

I'm amused at the traction this little gist is getting on Google! I would be remiss not to point out that six+ years later I'm still helping thousands of companies on a daily basis with their search index management, by providing managed Solr as a service over at Websolr, and hosted Elasticsearch at Bonsai. Check us out if you'd like an expert helping hand at Solr and Elasticsearch hosting, ops and support!

require 'matrix'
def regression x, y, degree
x_data = x.map {|xi| (0..degree).map{|pow| (xi**pow) }}
mx = Matrix[*x_data]
my = Matrix.column_vector y
((mx.t * mx).inv * mx.t * my).transpose.to_a[0].reverse
end
@naryad
naryad / CreateTwitterTable.java
Created July 23, 2011 11:09
Minimal implementation of twitter data layer using HBase
package hbase.sandbox;
import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.client.HBaseAdmin;
@tjogin
tjogin / README.md
Created September 5, 2011 06:56 — forked from rodrigorm/README.md
Configuration file to use PHP with Ruby rack

Installation

First you need php-cgi, i used brew with Formula below:

$ curl -O https://raw.github.com/gist/1194269/7ae1709453a8a19ce9c030bf41d544dd08d96d85/php.rb
$ mv php.rb `brew --prefix`/Library/Formula
$ brew install php --with-mysql

Second, install this ruby gems:

@misshie
misshie / viterbi.rb
Created September 18, 2011 12:05
A Ruby implementation of the Viterbi algorithm based on the hidden Markov model (HMM)
# A Ruby implementation of
# the Viterbi algorithm based on the hidden Markov model (HMM)
#
# An original Python code: a Wikipedia page "Viterbi algorithm" at
# http://en.wikipedia.org/wiki/Viterbi_algorithm
#
# Author: MISHIMA, Hiroyuki
#
require 'pp'