Skip to content

Instantly share code, notes, and snippets.

View rafbm's full-sized avatar

Rafael Masson rafbm

View GitHub Profile
@rafbm
rafbm / pusher-v1_3_2-v1_3_3.patch
Created October 11, 2019 19:26
Diff between versions 1.3.2 and 1.3.3 of `pusher` gem
diff --git a/README.md b/README.md
index 97c0bfb..365acbd 100644
--- a/README.md
+++ b/README.md
@@ -18,7 +18,7 @@ or install via gem
gem install pusher
```
-After registering at <https://dashboard.pusher.com/>, configure your Pusher Channels app with the security credentials.
+After registering at <https://dashboard.pusher.com/>, configure your Channels app with the security credentials.
def call
scope = base_relation.joins(:care_periods)
if params.care_provider_id.present?
scope = scope
.where(care_periods: { care_provider_id: params.care_provider_id })
end
if params.hospital_id.present?
scope = scope
codeMirror.setOption('onDragEvent', function(cm, e) {
// Move the cursor as they drag.
var pos = codeMirror.coordsChar({left: e.x, top: e.y });
codeMirror.setCursor(pos);
codeMirror.focus();
var isImageDrop = e.type == 'drop' && e.dataTransfer.files && e.dataTransfer.files.length > 0 && e.dataTransfer.files[0].type && e.dataTransfer.files[0].type.indexOf('image/') > -1;
if (!isImageDrop) return;
event.preventDefault();
@rafbm
rafbm / gist:9068f377f54b6b7a0915
Created January 19, 2015 15:52
Ruby String#tr VS String#gsub benchmark
require 'benchmark'
STRING = 'Haha hah hahaa ahah!!'
FIND = 'a'
REPLACE = 'o'
STRING.tr(FIND, REPLACE) == STRING.gsub(FIND, REPLACE) or abort
Benchmark.bmbm do |bm|
bm.report '.tr' do
raise FucktardError, 'You nuts?!?'
<!DOCTYPE html>
<head>
<style>
body { text-align: center }
h1 { font-size: 56px }
</style>
<link href="http://fonts.googleapis.com/css?family=Ruge+Boogie" rel="stylesheet">
<script>
WebFontConfig = { google: { families: [ 'Butterfly+Kids::latin' ] } }
;(function() {
@rafbm
rafbm / net_http_debug.rb
Created May 22, 2014 15:52
Net::HTTP provides instance-level debugging. Here’s how to toggle it globally with `Net::HTTP.debug=`.
# config/initializers/net_http_debug.rb
if Rails.env.development?
require 'net/http'
Net::HTTP.class_eval do
class << self
attr_accessor :debug
end
if Array < Object
puts 'Cool, “<” can be used to test class inheritance.'
end
if Object > Array
puts 'Cool, works the other way too.'
end
@rafbm
rafbm / json_benchmark.rb
Created May 22, 2013 20:12
Benchmarking Ruby’s JSON.load and JSON.parse.
require 'benchmark'
require 'json'
str = '{"foo": "bar"}'
Benchmark.benchmark Benchmark::CAPTION, 11 do |bm|
bm.report 'JSON.load' do
500_000.times { JSON.load(str) }
end
@rafbm
rafbm / human_name.rb
Last active December 17, 2015 04:29
Fix common downcase/whitespace issues in people names
# encoding: utf-8
require 'minitest/autorun'
# `gem install unicode_utils`
require 'unicode_utils/downcase'
require 'unicode_utils/upcase'
module HumanName
def self.all_lower_case?(name)