Skip to content

Instantly share code, notes, and snippets.

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

@maccman
maccman / juggernaut_channels.rb
Created June 26, 2012 04:56
Sinatra Server Side Event streaming with private channels.
# Usage: redis-cli publish message.achannel hello
require 'sinatra'
require 'redis'
conns = Hash.new {|h, k| h[k] = [] }
Thread.abort_on_exception = true
get '/' do
@maccman
maccman / juggernaut.rb
Created June 26, 2012 02:49
Sinatra Server Side Event streaming.
# Usage: redis-cli publish message hello
require 'sinatra'
require 'redis'
conns = []
get '/' do
erb :index
end
@chuckbjones
chuckbjones / deploy.rb
Created August 22, 2012 07:51
Generate static html files at deploy time in Rails 3.x
# define a method to run rake tasks
def run_rake(task, options={}, &block)
rake = fetch(:rake, 'rake')
rails_env = fetch(:rails_env, 'production')
command = "cd #{current_path} && #{rake} #{task} RAILS_ENV=#{rails_env}"
run(command, options, &block)
end
@mslepko
mslepko / updown_widget.js
Last active May 16, 2021 12:53
iOS Scriptable uptown.io Widget
const api_domain = "https://updown.io/api/"
const api_key = "INSERT_YOUR_API_KEY_HERE"
let w = new ListWidget() // Create the widget
w.backgroundColor = Color.clear() // add transparent background
//w.url= "https://url.com" // an url to open on click
async function getChecks() {
const response = new Request(api_domain + '/checks?api-key=' + api_key);
@rkh
rkh / chat.rb
Created December 14, 2011 12:55
Simple Chat Application using the Sinatra Streaming API
# coding: utf-8
require 'sinatra'
set server: 'thin', connections: []
get '/' do
halt erb(:login) unless params[:user]
erb :chat, locals: { user: params[:user].gsub(/\W/, '') }
end
get '/stream', provides: 'text/event-stream' do
@jbaranski
jbaranski / Img2MBTilesWithGDAL.md
Created August 1, 2020 14:52
Convert an image (like JPG or TIF) to MBTiles using GDAL

Here are the steps needed to convert an image (like JPG or TIF) to MBTiles using GDAL:

  1. Download and install GDAL (https://gdal.org/, https://anaconda.org/conda-forge/gdal):

       conda install -c conda-forge gdal
    

    Installing GDAL is kind of a pain in the ass, especially on Windows. I'm assuming you'll be able to work out whatever issues you run into here.

  2. Download example jpg and tif map images we can work with:

@mudge
mudge / production.rb
Last active November 21, 2023 14:06
How to configure Rails and Rack::Attack to use the real client IP when running behind Cloudflare
Rails.application.configure do
# Add Cloudflare's IPs to the trusted proxy list so they are ignored when
# determining the true client IP.
#
# See https://www.cloudflare.com/ips-v4/ and https://www.cloudflare.com/ips-v6/
config.action_dispatch.trusted_proxies = ActionDispatch::RemoteIp::TRUSTED_PROXIES + %w[
173.245.48.0/20
103.21.244.0/22
103.22.200.0/22
103.31.4.0/22
@O-I
O-I / weighted_random_sampling.md
Last active February 21, 2024 19:02
[TIx 8] Weighted Random Sampling in Ruby

One of the many reasons I love working with Ruby is it has a rich vocabulary that allows you to accomplish your goals with a minimal amount of code. If there isn't a method that does exactly what you want, it's usually possible to build an elegant solution yourself.

Let's take the example of simulating the rolling of a die.

We can represent a die as an array of its faces.

die = [*?⚀..?⚅]
# => ["⚀", "⚁", "⚂", "⚃", "⚄", "⚅"]
@justjanne
justjanne / Price Breakdown.md
Last active April 11, 2024 22:21 — forked from kylemanna/price.txt
Server Price Breakdown: DigitalOcean, Amazon AWS LightSail, Vultr, Linode, OVH, Hetzner, Scaleway/Online.net:

Server Price Breakdown: DigitalOcean, Amazon AWS LightSail, Vultr, Linode, OVH, Hetzner, Scaleway/Online.net:

Permalink: git.io/vps

$5/mo

Provider Type RAM Cores Storage Transfer Network Price