Skip to content

Instantly share code, notes, and snippets.


Erik Berlin sferik

View GitHub Profile
require "http/client"
require "json"
require "oauth"
HOST = ""
# Generate API keys at
API_KEY = "Replace this with your Twitter API Key"
API_SECRET = "Replace this with your Twitter API Key Secret"
ACCESS_TOKEN = "Replace this with your Twitter Access Token"
ACCESS_TOKEN_SECRET = "Replace this with your Twitter Access Token Secret"
sferik / passwords_controller.rb
Created Nov 17, 2012 — forked from kazpsp/passwords_controller.rb
StrongParameters with Devise
View passwords_controller.rb
# app/controllers/users/password_controller.rb
class Users::PasswordsController < Devise::PasswordsController
def resource_params
params.require(:user).permit(:email, :password, :password_confirmation, :reset_password_token)
private :resource_params
class SizeAwareCache
@@cache = {} of String => Hash(Int32, String)
def read(key : String, size : Int32)
if value = @@cache.dig?(key, size)
# Hit! (both key and size)
return value
elsif results = @@cache[key]?
# Key hit, size miss
sorted_results = results.to_a.sort_by(&.first)
sferik /
Last active Dec 25, 2019
Why Software Is Eating The World

Why Software Is Eating The World

August 20, 2011

This week, Hewlett-Packard (where I am on the board) announced that it is exploring jettisoning its struggling PC business in favor of investing more heavily in software, where it sees better potential for growth. Meanwhile, Google plans to buy up the cellphone handset maker Motorola Mobility. Both moves surprised the tech world. But both moves are also in line with a trend I've observed, one that makes me optimistic about the future growth of the American and world economies, despite the recent turmoil in the stock market.

In short, software is eating the world.

sferik /
Created Nov 5, 2012
Instructions to install on Ruby 2.0.0 on Mac OS X with homebrew
#!/usr/bin/env sh
brew update
brew install rbenv
brew install ruby-build
brew install openssl
CONFIGURE_OPTS=--with-openssl-dir=`brew --prefix openssl` rbenv install 2.0.0-preview1
View future.ex
defmodule Future do
def new(fun) do
fn(x) ->
spawn_link fn ->
value = try do
{ :ok, fun.(x) }
e -> { :error, e }
View 1000 Twitter API Requests (JSON)
$ ab -n 1000 -c 10
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd,
Licensed to The Apache Software Foundation,
Benchmarking (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
View app.js
var server = require('http').createServer(serveFile);
var fs = require('fs');
var ntwitter = require("ntwitter");
var io = require('').listen(server);
function serveFile(request, response){
fs.readFile(__dirname + '/index.html', function(error, data){
if(error) {
response.writeHead(404, {'Content-Type': 'text/html'});
response.write("<html><body>No drank for you!</body></html>");
View first_to_finish.rb
module Enumerable
def first_to_finish
threads = collect { |args| { yield(args) } }
loop until done = threads.detect { |t| !t.alive? }
puts [5, 3, 1, 2, 4].first_to_finish { |x| sleep x }
View twitter-friends.rb
require 'csv'
require 'twitter'
def twitter_client
@twitter_client ||= do |config|
config.consumer_key = 'XXXXXX'
config.consumer_secret = 'XXXXXX'
config.access_token = 'XXXXXX'
config.access_token_secret = 'XXXXXX'