Skip to content

Instantly share code, notes, and snippets.

View reu's full-sized avatar

Rodrigo Navarro reu

View GitHub Profile
@drogus
drogus / Rakefile.rb
Created July 26, 2013 10:49
This is the example contents of the Rakefile, which you would use to run active record tasks without using Rails. It assumes using the same directories as rails uses: `db/migrate`, `config/database.yml`.
require 'bundler/setup'
require 'active_record'
include ActiveRecord::Tasks
db_dir = File.expand_path('../db', __FILE__)
config_dir = File.expand_path('../config', __FILE__)
DatabaseTasks.env = ENV['ENV'] || 'development'
@dmatveev
dmatveev / gist:5993223
Created July 14, 2013 04:36
Yet another Haskell ST-powered QuickSort implementation
{-# LANGUAGE ScopedTypeVariables #-}
module MergeSort where
import Control.Monad.ST
import Control.Monad (forM_, when)
import Data.Array.ST
import Data.STRef
-- Required for tests only
@guimello
guimello / decorators.py
Created July 11, 2013 01:48
Decorators examples in python.
from time import time
# Decoratoring with a class
class Benchmark(object):
def __init__(self, function):
self.function = function
def __call__(self, *args, **kwargs):
t1 = time()
result = self.function(*args, **kwargs)
@fnando
fnando / giffy
Last active July 1, 2020 02:30
Export video files as GIF
#!/usr/bin/env bash
if [[ ! -f "$1" ]]; then
echo "=> Movie file not found"
exit 1
fi
tempfile=/tmp/output.gif
rm -f $tempfile
@afeld
afeld / gist:5704079
Last active April 21, 2025 15:11
Using Rails+Bower on Heroku
@arschles
arschles / twitterFutureToScala.scala
Created May 2, 2013 18:45
Converting a Twitter future to a Scala Future
import com.twitter.util.{Future => TwFuture}
import scala.concurrent.{Future => ScFuture, promise => scPromise}
implicit def twFutureToScala[T](twFuture: TwFuture[T]): ScFuture[T] = {
val prom = scPromise[T]
twFuture.onComplete { res: T =>
prom.success(res)
}
twFuture.onFailure { t: Throwable =>
prom.failure(t)
}
@oliland
oliland / gist:5416438
Created April 18, 2013 21:37
An example of using CIFilters to mess with UIViews on iOS.
- (void)viewDidLoad
{
[super viewDidLoad];
// Great tutorial: http://www.raywenderlich.com/22167/beginning-core-image-in-ios-6
// Official docs: https://developer.apple.com/library/ios/#documentation/GraphicsImaging/Conceptual/CoreImaging/ci_intro/ci_intro.html#//apple_ref/doc/uid/TP30001185-CH1-TPXREF101
// Alt-click on function names for more!
// Make any old label, with our frame set to the view so we know it's there.
UILabel *label = [[UILabel alloc] initWithFrame:self.view.frame];
@jnape
jnape / FutureEither.scala
Created April 3, 2013 09:03
Making dealing with Future[Either[L, R]] palatable in Scala
package com.thoughtworks.futureeither
import concurrent.{Await, Future}
import scala.concurrent.ExecutionContext.Implicits.global
import concurrent.duration.FiniteDuration
import java.util.concurrent.TimeUnit
class FutureEither[L, R](private val future: Future[Either[L, R]]) {
def flatMap[R2](block: R => FutureEither[L, R2]): FutureEither[L, R2] = {

This is a proof-of-concept of a couple of concurrent data structures written in Ruby.

The implementations are heavily commented for those interested. There are benchmarks (with results) included below. The results are interesting, but, as always, take with a grain of salt.

Data structures

AtomicLinkedQueue is a lock-free queue, built on atomic CAS operations.

Commandline output

$ ruby treetoar.rb 
SELECT "topics".* FROM "topics"  WHERE "topics"."id" = 1
Topic.where(id: 1)
SELECT "topics".* FROM "topics"  WHERE "topics"."id" IN (1, 2, 3)
Topic.where(id: [1, 2, 3])