Skip to content

Instantly share code, notes, and snippets.

View sferik's full-sized avatar

Erik Berlin sferik

View GitHub Profile
@sferik
sferik / install-ruby-2.0.0.sh
Created November 5, 2012 02:28
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
@sferik
sferik / mutant.out
Created October 24, 2023 02:27
Erroring mutant output for x-ruby MediaUploader class
This file has been truncated, but you can view the full file.
warning: parser/current is loading parser/ruby33, which recognizes 3.3.0-dev-compliant syntax, but you are running 3.3.0.
Please see https://github.com/whitequark/parser#compatibility-with-ruby-mri.
Mutant environment:
Matcher: #<Mutant::Matcher::Config subjects: [X::MediaUploader]>
Integration: minitest
Jobs: 10
Includes: ["lib"]
Requires: ["x", "x/media_uploader"]
Operators: full
MutationTimeout: 10
@sferik
sferik / digits_cli.cr
Last active July 28, 2023 19:05
NYTimes Digits Game (aka Countdown) Solver written in Crystal by Erik Berlin
require "option_parser"
class CountdownGame
OPERATORS = [:+, :-, :*, :/]
def initialize(@numbers : Array(Int32), @target : Int32)
end
def solve
result = solve_recursively(@numbers.map { |n| {n, n.to_s} }).find { |result, _| result == @target }
@sferik
sferik / twimg.cr
Last active September 4, 2021 14:43
require "http/client"
require "json"
require "oauth"
HOST = "api.twitter.com"
# Generate API keys at https://developer.twitter.com/en/portal/projects-and-apps
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
sferik / passwords_controller.rb
Created November 17, 2012 00:18 — forked from kazpsp/passwords_controller.rb
StrongParameters with Devise
# 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)
end
private :resource_params
end
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
sferik / why_software_is_eating_the_world.md
Last active December 25, 2019 15:43
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
sferik / future.ex
Last active October 23, 2018 18:46 — forked from josephwilk/future.ex
defmodule Future do
def new(fun) do
fn(x) ->
spawn_link fn ->
value = try do
{ :ok, fun.(x) }
rescue
e -> { :error, e }
end
@sferik
sferik / 1000 Twitter API Requests (JSON)
Created December 10, 2009 03:28
Twitter API Benchmarks
$ ab -n 1000 -c 10 http://twitter.com/help/test.json
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking twitter.com (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
var server = require('http').createServer(serveFile);
var fs = require('fs');
var ntwitter = require("ntwitter");
var io = require('socket.io').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>");