Skip to content

Instantly share code, notes, and snippets.

View zdzolton's full-sized avatar

Zach Zolton zdzolton

View GitHub Profile
@zdzolton
zdzolton / gist:6143926
Created August 2, 2013 22:17
Hacking Roman Numeral support onto Ruby numbers...
class Fixnum
NUMERALS = {
1000 => %w(M),
100 => %w(C D),
10 => %w(X L),
1 => %w(I V),
}
def to_roman
raise "Out of range" unless (1...3000).include?(self)
@zdzolton
zdzolton / gist:3019289
Created June 29, 2012 17:08
Super useful Site Stream API error from Twitter
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Error 401 Unauthorized</title>
</head>
<body>
<h2>HTTP ERROR: 401</h2>
<p>Problem accessing '/2b/site.json'. Reason:
<pre> Unauthorized</pre>
@zdzolton
zdzolton / map.coffee
Created January 6, 2012 03:43 — forked from plesiecki/map.js
Hadoop Streaming with Node.js (CoffeeScript edition)
#!/usr/bin/env coffee
stdin = process.openStdin()
stdout = process.stdout
input = ''
stdin.setEncoding 'utf8'
stdin.on 'data', (data) ->
return unless data?
@zdzolton
zdzolton / gist:1068652
Created July 7, 2011 00:16
Error from CQS SendMessage
Error: Couch response 500 to http://devadmin:foo@localhost:5984/cqs-development/CQS%2FZachary-Zoltons-MacBook-Air-local-development%2F2f7a20debd8f40d9629898d584a30a94: {"error":"case_clause","reason":"{[{<<\"message\">>,<<\"/^CQS\\\\//.test is not a function\">>},\n {<<\"fileName\">>,<<>>},\n {<<\"lineNumber\">>,18},\n {<<\"stack\">>,\n <<\"([object Object],null,[object Object],[object Object])@:18\\n(function (newDoc, oldDoc, userCtx, secObj) {var NAME = \\\"Zachary-Zoltons-MacBook-Air-local-development\\\";var my_msg_id = function (doc) {var for_me = /^CQS\\\\/Zachary-Zoltons-MacBook-Air-local-development\\\\/(.*)$/;var match = for_me.exec(doc._id);if (!match) {return null;}var msg_id = match[1];match = /^([0-9a-f]{32})($|\\\\/(.*)$)/.exec(msg_id);if (!match) {throw {forbidden: \\\"Invalid message id: \\\" + msg_id};}return {id: match[1], extra: match[3]};};if (!/^CQS\\\\//.test(newDoc._id)) {throw {forbidden: \\\"This database is for CQS only\\\"};}var msg_id = mpg-api
$ curl http://npmjs.org/install.sh | sudo sh
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
115 230 115 230 0 0 5385 0 --:--:-- --:--:-- --:--:-- 11500
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 553k 100 553k 0 0 150k 0 0:00:03 0:00:03 --:--:-- 165k
node cli.js cache clean
npm it worked if it ends with ok
npm cli [ 'cache', 'clean' ]
@zdzolton
zdzolton / npm-install-request.sh
Created August 13, 2010 02:30
Installing a Node.js package via NPM
$ npm install request
npm it worked if it ends with ok
npm cli [ 'install', 'request' ]
npm version 0.1.23
npm config file /Users/zach/.npmrc
npm config file /usr/local/Cellar/node/0.1.103/etc/npmrc
npm install pkg request
npm fetch data request
npm GET request
npm install pkg request
@zdzolton
zdzolton / commit_all.html
Created August 9, 2010 14:11
CouchDB - commit all databases
<!DOCTYPE html>
<html>
<head><title>Commit All Databases</title></head>
<body>
<h1>Commit All Databases</h1>
<p>This script will trigger <tt>_ensure_full_commit</tt> on all databases.</p>
<ul id="databases"></ul>
</body>
<script src="/_utils/script/jquery.js"></script>
<script src="/_utils/script/jquery.couch.js"></script>
@zdzolton
zdzolton / rename_rhtml_to_erb_html.rb
Created June 21, 2009 19:29
Renames your RHTML templates to the new file extension convention
Dir.glob('**/*.rhtml') do |rhtml_path|
new_path = rhtml_path.gsub /^(.*)\.rhtml$/, '\1.erb.html'
`git mv #{rhtml_path} #{new_path}`
end
@zdzolton
zdzolton / tweet-spritzer-to-couchdb.rb
Created June 9, 2009 13:59
How to Fill up a CouchDB with Twitter Statuses
require 'rubygems'
require 'json'
gem 'jchris-couchrest'
require 'couchrest'
require 'open3'
COUCHDB_HOST = "http://127.0.0.1:5984"
DB_NAME = 'tweet-spritzer'
SPRITZER_DB = CouchRest.database! "#{COUCHDB_HOST}/#{DB_NAME}"
@zdzolton
zdzolton / database.rb
Created May 7, 2009 18:16
CouchDB-Lucene Searching with CouchRest
CouchRest::Database.class_eval do
def search query, options={}
CouchRest.get "#{@uri}/_fti?#{options.merge(:q => query).to_query}"
end
end