Skip to content

Instantly share code, notes, and snippets.

View jfarmer's full-sized avatar
🐢

Jesse Farmer jfarmer

🐢
View GitHub Profile
require 'rubygems'
require 'sinatra'
set :environment, :production
disable :run, :reload
get '/' do
"Hey"
end
run Sinatra::Application
Backtrace: /usr/local/lib/ruby/gems/1.8/gems/facebooker-1.0.29/lib/facebooker/parser.rb:535:in `process'
/usr/local/lib/ruby/gems/1.8/gems/facebooker-1.0.29/lib/facebooker/parser.rb:15:in `parse'
/usr/local/lib/ruby/gems/1.8/gems/facebooker-1.0.29/lib/facebooker/service.rb:19:in `post'
/usr/local/lib/ruby/gems/1.8/gems/facebooker-1.0.29/lib/facebooker/session.rb:511:in `post_without_logging'
/usr/local/lib/ruby/gems/1.8/gems/facebooker-1.0.29/lib/facebooker/session.rb:522:in `post'
/usr/local/lib/ruby/gems/1.8/gems/facebooker-1.0.29/lib/facebooker/logging.rb:27:in `log_fb_api'
/usr/local/lib/ruby/1.8/benchmark.rb:308:in `realtime'
/usr/local/lib/ruby/gems/1.8/gems/facebooker-1.0.29/lib/facebooker/logging.rb:27:in `log_fb_api'
/usr/local/lib/ruby/gems/1.8/gems/facebooker-1.0.29/lib/facebooker/session.rb:521:in `post'
/usr/local/lib/ruby/gems/1.8/gems/facebooker-1.0.29/lib/facebooker/session.rb:179:in `secure!'
callback same
url different
api key different
secret different
var inject = function(iterable, initial, func) {
var cur = initial
for(var i = 0;i < iterable.length;i++) {
cur = func(cur, iterable[i])
}
return cur
}
var map = function(arr, func) {
return inject(arr, [], function(memo, val) {
We’ve built a new communication protocol that sends messages with a restricted syntax.
We need to write a function which determines whether a given message is syntactically valid or not.
Here are the rules:
1. There are 15 valid characters in the protocol: the lower-case characters ‘a’ through ‘j’
and the uppercase characters ‘Z’, ‘M’, ‘K’, ‘P’, and ‘Q’.
2. Every lower-case character in isolation is a valid message, e.g., ‘a’ is a valid message.
3. If σ is a valid message then so is Zσ.
4. If σ and τ are valid messages then so are Mστ , Kστ , Pστ , and Qστ .
5. All other messages are invalid.
@jfarmer
jfarmer / gist:1515311
Created December 23, 2011 20:42
cd out of /private on OS X
# Get rid of /private ugh
if [[ $PWD =~ ^/private ]];then
cd ${PWD#*/private}
fi
@jfarmer
jfarmer / gist:1548762
Created January 2, 2012 00:19
Get the battery life percentage of your bluetooth mouse on Mac OS X
ioreg -n "BNBMouseDevice" | grep -i "batterypercent" | sed 's/[^0-9]//g'
@jfarmer
jfarmer / eigenclass.rb
Created May 6, 2012 23:59
Eigenclasses in Ruby
# In Ruby everything is an object, including classes.
# That means class methods are instance methods of some object.
# But what object?
class Object
def eigenclass
class << self
self
end
end
@jfarmer
jfarmer / 01-truthy-and-falsey-ruby.md
Last active April 16, 2024 03:40
True and False vs. "Truthy" and "Falsey" (or "Falsy") in Ruby, Python, and JavaScript

true and false vs. "truthy" and "falsey" (or "falsy") in Ruby, Python, and JavaScript

Many programming languages, including Ruby, have native boolean (true and false) data types. In Ruby they're called true and false. In Python, for example, they're written as True and False. But oftentimes we want to use a non-boolean value (integers, strings, arrays, etc.) in a boolean context (if statement, &&, ||, etc.).

This outlines how this works in Ruby, with some basic examples from Python and JavaScript, too. The idea is much more general than any of these specific languages, though. It's really a question of how the people designing a programming language wants booleans and conditionals to work.

If you want to use or share this material, please see the license file, below.

Update

@jfarmer
jfarmer / todo.txt
Created May 17, 2012 23:30
A rudimentary "database" for a TODO app
(2012-05-01 15:43) [ ] This is a todo item created on May 1st, 2012 at 3:43PM
(2012-05-02 09:10) [X] This is a completed todo item created on May 2nd, 2012 at 9:10AM
(2012-05-03 10:00) [X] Buy groceries
(2012-01-01 00:01) [ ] Make better New Years' resolutions