Skip to content

Instantly share code, notes, and snippets.

View pedrocarrico's full-sized avatar

Pedro Carriço pedrocarrico

View GitHub Profile
module HashExtensions
def symbolize_keys
inject({}) do |acc, (k,v)|
key = String === k ? k.to_sym : k
value = Hash === v ? v.symbolize_keys : v
acc[key] = value
acc
end
end
end
@bensomers
bensomers / rails_routing_invalid_chars_fix.rb
Created May 29, 2012 19:08
3.0.x monkeypatch for fixing Invalid Char 500s
# Fix for a Rails - Ruby 1.9 bug
# Rails Router, now that it's UTF-8 default, blows up when routing requests
# with invalid chars in the URL; it should properly return a 400 error
# Have to monkey-patch the fix in, since it's not scheduled for release until
# Rails 4.0.
# Adapted Andrew White (pixeltrix)'s fix at
# https://github.com/rails/rails/commit/3fc561a1f71edf1c2bae695cafa03909d24a5ca3,
# but edited to work in 3.0.x.
# 3.1.x, 3.2.x compatibility unknown
require 'action_dispatch/routing/route_set'
@marionzualo
marionzualo / benchmark_with_default_arguments.rb
Last active November 7, 2015 18:15
Benchmark keyword arguments, normal arguments and an options hash in Ruby 2.1.5 and 2.2.3. Background: Koichi's talk on the evolution of keyword parameters at Ruby Conf PT - https://www.youtube.com/watch?v=qNaXZ1VWuvA. Inspired by https://gist.github.com/postmodern/5274138
require 'benchmark/ips'
def keyword(a:1,b:2,c:3)
a + b + c
end
def normal(a=1,b=2,c=3)
a + b + c
end

ruby-1.9.3-p392 cumulative performance patch for rbenv

(I guarantee nothing. No warranty I am not responsible blah blah blah. Seems to work great for me so far. Thanks to Tyler Bird who I forked this from.)

This installs a patched ruby 1.9.3-p392 with the railsexpress patchsets: https://github.com/skaes/rvm-patchsets

Requirements

@sturadnidge
sturadnidge / minipi.sh
Last active June 13, 2016 13:21
Minimal Raspbian image builder.
#!/bin/bash
# required build environment packages: binfmt-support qemu qemu-user-static debootstrap kpartx lvm2 dosfstools
# made possible by:
# Klaus M Pfeiffer (http://blog.kmp.or.at/2012/05/build-your-own-raspberry-pi-image/)
# Alex Bradbury (http://asbradbury.org/projects/spindle/)
deb_mirror="http://archive.raspbian.org/raspbian/"
deb_local_mirror=$deb_mirror
deb_release="wheezy"
@jaytaylor
jaytaylor / mysql-fast-loader.sh
Created October 20, 2011 19:38
Copies MySQL database to ramdisk then runs supplied shell script or command. The ramdisk version of the database is then copied back to the filesystem. Speeds up IO-intensive operations (e.g. loading heavily indexed tables.)
#!/usr/bin/env bash
##
# @author Jay Taylor <outtatime@gmail.com>
#
# @date 2011-10-20
#
# @description Copies MySQL database to ramdisk then runs supplied shell script
# or command. The ramdisk version of the database is then copied back to the
# filesystem. Speeds up IO-intensive operations (e.g. loading heavily indexed
@adammw
adammw / README.md
Created August 3, 2012 06:30
Node.js for Raspberry Pi

Node.js for Raspberry Pi

Pre-built binaries

Recent releases have been pre-built using cross-compilers and this script and are downloadable below.

If you have found these packages useful, give me a shout out on twitter: @adammw

ARG FUNCTION_RUNTIME
FROM mikesir87/aws-cli as code
ARG FUNCTION_NAME
ARG AWS_DEFAULT_REGION
ARG AWS_ACCESS_KEY_ID
ARG AWS_SECRET_ACCESS_KEY
RUN wget -O function.zip `aws lambda get-function --function-name $FUNCTION_NAME --query 'Code.Location' --output text`
@andyjbas
andyjbas / gist:9962218
Last active June 23, 2020 13:33
Disable CSS Animations in Poltergeist & Phantomjs. Phantomjs does not like to wait for animations, and you can run in to nasty test flickers because of it. This pattern will disable animations in test env, and not touch any app code.
# env.rb or spec_helper.rb

Capybara.register_driver :poltergeist do |app|
  opts = {
    extensions: ["#{Rails.root}/features/support/phantomjs/disable_animations.js"] # or wherever
  }

  Capybara::Poltergeist::Driver.new(app, opts)
end
@stonehippo
stonehippo / RPi-Dashing-howto.md
Last active October 6, 2021 13:52
Setting up a Raspberry Pi as a dashboard server with Dashing

Setting up a Raspberry Pi as a dashboard server with Dashing

Why the heck did I do this?

I wanted to set up one of my Raspberry Pi's as a data dashboard, pushing sensor data to a web interface that's easy to digest. I decided to use Shopify's Dashing framework. Dashing is based on Sinatra, and is pretty lightweight.

Dashing does require Ruby 1.9.3 to run. In addition, it makes use of the execjs gem, which needs to have a working Javascript interpreter available. Originally, I tried to get therubyracer working, but decided to switch over to Node.js when I ran into roadblocks compiling V8.

One warning: The RPi is a very slow system compared with modern multi-core x86-style systems. It's pretty robust, but compiling all this complex software taxes the system quite a bit. Expect that it's going to take at least half a day to get everything going.