Skip to content

Instantly share code, notes, and snippets.

View mculp's full-sized avatar
🎨
arting

Matt Culpepper mculp

🎨
arting
View GitHub Profile
@searls
searls / resets_session_but_its_still_thursday_i_need_these.rb
Created August 15, 2024 12:28
Was genuinely surprised Rails `reset_session` doesn't accept a list of exceptions
# If you have any session variables that should survive a logout, add them to
# the except_for array. Usage from a controller:
#
# ResetsSessionButItsStillThursdayINeedThese.new.reset(self,
# except_for: [:has_logged_in_before])
class ResetsSessionButItsStillThursdayINeedThese
def reset(receiver, except_for: [])
backup = except_for.map { |key| [key, receiver.session[key]] }
receiver.reset_session
@troex
troex / my_controller.rb
Last active October 7, 2021 09:41
Sinatra + EventMachine + Puma – Heroku workaround for 30 seconds timeout
module Application
module Controllers
class MyController < Sinatra::Base
helpers Sinatra::Streaming
class << self
def stream(method, path, opts = {}, &block)
send(method, path, opts) do
stream do |out|
timer = EventMachine::PeriodicTimer.new(10) { out << "\0" }
@kevinelliott
kevinelliott / osx-10.11-setup.md
Last active September 5, 2024 01:54
Mac OS X 10.11 El Capitan Setup

Mac OS X 10.11 El Capitan

Custom recipe to get OS X 10.11 El Capitan running from scratch, setup applications and developer environment. This is very similar (and currently mostly the same) as my 10.10 Yosemite setup recipe (as found on this gist https://gist.github.com/kevinelliott/0726211d17020a6abc1f). Note that I expect this to change significantly as I install El Capitan several times.

I use this gist to keep track of the important software and steps required to have a functioning system after a semi-annual fresh install. On average, I reinstall each computer from scratch every 6 months, and I do not perform upgrades between distros.

This keeps the system performing at top speeds, clean of trojans, spyware, and ensures that I maintain good organizational practices for my content and backups. I highly recommend this.

You are encouraged to fork this and modify it to your heart's content to match your own needs.

@JunichiIto
JunichiIto / alias_matchers.md
Last active October 21, 2024 00:54
List of alias matchers in RSpec 3

This list is based on aliases_spec.rb.

You can see also Module: RSpec::Matchers API.

matcher aliased to description
a_truthy_value be_truthy a truthy value
a_falsey_value be_falsey a falsey value
be_falsy be_falsey be falsy
a_falsy_value be_falsey a falsy value
@pcreux
pcreux / 000_postgresql_fancy_datatypes
Last active March 18, 2022 16:51
Postgresql fancy datatypes with Rails / ActiveRecord. Run it with `rake`!
# Postgresql fancy datatypes!
* array
* hstore (=~ hash)
* json
* jsonb
Philippe Creux - [@pcreux](http://twitter.com/pcreux)
@mislav
mislav / OpenSSL fix.md
Last active June 8, 2023 07:48
Fix OpenSSL certificate errors on Ruby 2.0

The reason why you might get certificate errors in Ruby 2.0 when talking HTTPS is because there isn't a default certificate bundle that OpenSSL (which was used when building Ruby) trusts.

Update: this problem is solved in edge versions of rbenv and RVM.

$ ruby -rnet/https -e "Net::HTTP.get URI('https://github.com')"
net/http.rb:917:in `connect': SSL_connect returned=1 errno=0 state=SSLv3
  read server certificate B: certificate verify failed (OpenSSL::SSL::SSLError)

You can work around the issue by installing a certificate bundle that you trust. I trust Mozilla and curl.

function deParam (params, coerce) {
var obj = {};
var coerce_types = { 'true': !0, 'false': !1, 'null': null };
var decode = decodeURIComponent;
// Iterate over all name=value pairs.
$.each(params.replace(/\+/g, ' ').split('&'), function(j, v){
var param = v.split( '=' ),
key = decode(param[0]),
val,