Skip to content

Instantly share code, notes, and snippets.

  • Dynamic Dispatch
  • Dynamic Method
  • Ghost Methods
  • Dynamic Proxies
  • Blank Slate
  • Kernel Method
  • Flattening the Scope (aka Nested Lexical Scopes)
  • Context Probe
  • Class Eval (not really a 'spell' more just a demonstration of its usage)
  • Class Macros
require 'json'
require 'active_support/core_ext/numeric/bytes'
require 'delegate'
require 'forwardable'
require 'time'
require 'celluloid/io'
require 'websocket/driver'
require 'webmachine'
require 'webmachine/adapters/rack'
require 'celluloid/autostart'
package rx.internal.util.unsafe;
import java.lang.reflect.Field;
public class Unsafe {
public int getIntVolatile(Object obj, long offset) {
return 0;
}
# This module allows you to prepend a version prefix to your Sinatra URLs
# Example:
#
# require 'rubygems'
# require 'sinatra/base'
#
# class App < Sinatra::Base
# register Versioned
#
# set :version, 'v1'
@bogdanRada
bogdanRada / custome_time_parser.rb
Last active August 29, 2015 14:07
custom time parser of timestamp
module CustomTimeParser
extend self
def get_time_interval(str_format = '%h:%m:%s', i_seconds=0, options = {})
a_period = {'hour' => 0, 'min' => 0, 'sec' => 0 }
#-- Get the correct period
ThinkingSphinx::Index.define(
:incident,
with: :active_record,
delta?: false,
delta_processor: ThinkingSphinx::Deltas.processor_for(ThinkingSphinx::Deltas::ResqueDelta)
) do
where "incidents.deleted = 0 AND accounts.status = 'enabled'"
set_property group_concat_max_len: 8192
indexes name, sortable: true
@jturkel
jturkel / multi_provider_saml_handler.rb
Last active March 24, 2021 04:51
How to configurate omniauth-saml to work with multiple identity providers based on a dynamic URL path segment. A gem based on this idea has been extracted to https://github.com/salsify/omniauth-multi-provider-saml.
require 'omniauth'
require 'omniauth-saml'
class MultiProviderSamlHandler
UUID_REGEX = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/
attr_reader :path_prefix, :provider_name
def initialize(path_prefix: OmniAuth.config.path_prefix, provider_name: 'saml')
@path_prefix = path_prefix
@markets
markets / migrate_s3.rake
Created November 12, 2015 15:09
Migrate Paperclip assets from filesystem to AWS S3
namespace :attachments do
task migrate_to_s3: :environment do
require 'aws-sdk'
# Define Paperclip models
models = [
[Attachment, :data],
[Image, :data],
[MediaAppearance, :media_logo],
[Testimonial, :avatar_logo]
@jtilly
jtilly / install.sh
Last active May 23, 2024 10:36
Install qcachegrind on Ubuntu
#!/bin/bash
sudo apt-get install qt5-default
wget http://kcachegrind.sourceforge.net/kcachegrind-0.7.4.tar.gz
tar xvf kcachegrind-0.7.4.tar.gz
cd kcachegrind-0.7.4
qmake && make
sudo install -m 755 qcachegrind/qcachegrind /usr/local/bin
sudo install -m 644 qcachegrind/qcachegrind.desktop \
/usr/local/share/applications/
@cristobal
cristobal / machine-diskutil.sh
Last active November 2, 2024 08:05
Machine Diskutil to mount/unmont external volumes inside docker machines running on Virtualbox
#!/usr/bin/env sh
# @see http://stackoverflow.com/questions/30040708/how-to-mount-local-volumes-in-docker-machine
# @see https://github.com/boot2docker/boot2docker/blob/master/doc/FAQ.md
################################################################################
# Dependency Section #
# #
################################################################################
check_deps() {
## Make sure commands are available