Skip to content

Instantly share code, notes, and snippets.

View guizmaii's full-sized avatar
🏄‍♂️

Jules Ivanic guizmaii

🏄‍♂️
View GitHub Profile
@jodosha
jodosha / each_benchmark.rb
Created November 9, 2009 13:49
Ruby benchmark: Array#each vs for x in array
#!/usr/bin/env ruby -w
require "benchmark"
TIMES = 100_000
ARRAY = (1..1_000).to_a
Benchmark.bm(30) do |b|
b.report "each" do
TIMES.times do |i|
ARRAY.each do |element|
@ymasory
ymasory / GetVersion.scala
Created April 17, 2011 00:25
detect Scala version at runtime
/** Use with a default value, for example:
* runningScalaVersion getOrElse "2.8.0"
*/
lazy val runningScalaVersion = {
val matcher = """version (\d+\.\d+\.\d+).*""".r
util.Properties.versionString match {
case matcher(versionString) => Some(versionString)
case _ => None
}
}
@rstacruz
rstacruz / index.md
Last active November 3, 2023 09:56
Rails models cheatsheet

Rails Models

Generating models

$ rails g model User

Associations

belongs_to

has_one

@jboner
jboner / latency.txt
Last active May 3, 2024 15:17
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@amejiarosario
amejiarosario / rails_migration_cheatsheet.md
Created June 18, 2012 21:40
Rails Migration - Cheatsheet
@nthx
nthx / TamperMonkeyScriptWithJqueryAndSugar.js
Created September 3, 2012 01:36
Hello World TamperMonkey script with jquery/sugarjs
// ==UserScript==
// @match https://yourwebsite.com/xyz
// @require http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js
// @require http://cdnjs.cloudflare.com/ajax/libs/sugar/1.3/sugar.min.js
// ==/UserScript==
alert('Hello, I got jQuery included and sugarJs too');
var runEverySecond = function(){
$('p').find('img').attr('width', '0px');
@andyhawthorne
andyhawthorne / unicorn_init.sh
Created September 4, 2012 22:35
start unicorn
#!/bin/sh
set -e
# Feel free to change any of the following variables for your app:
TIMEOUT=${TIMEOUT-60}
APP_ROOT=/home/you/apps/app_name/current
PID=$APP_ROOT/tmp/pids/unicorn.pid
CMD="cd $APP_ROOT; bundle exec unicorn -D -c $APP_ROOT/config/unicorn.rb -E production"
AS_USER=andy
set -u
@olegykz
olegykz / gist:4079178
Created November 15, 2012 15:28
Skipping asset compilation with capistrano
namespace :deploy do
namespace :assets do
task :precompile, :roles => :web, :except => { :no_release => true } do
begin
from = source.next_revision(current_revision) # <-- Fail here at first-time deploy
rescue
err_no = true
end
if err_no || capture("cd #{latest_release} && #{source.local.log(from)} vendor/assets/ app/assets/ | wc -l").to_i > 0
run %Q{cd #{latest_release} && #{rake} RAILS_ENV=#{rails_env} #{asset_env} assets:precompile}
@agile-jordi
agile-jordi / EnumJson
Last active April 22, 2016 05:06
An object with functions the create Reads, Writes or Formats for Enums.
// With an enumeration like...
// object Color extends Enumeration{...}
// Create a format (or reads or writes) like this:
// val fmt = EnumJson.enumFormat(Color);
// The implementation
object EnumJson {
def enumReads[E <: Enumeration](enum: E): Reads[E#Value] = new Reads[E#Value] {
@jsteiner
jsteiner / database_cleaner.rb
Created January 10, 2014 20:31
Database Cleaner
RSpec.configure do |config|
config.before(:suite) do
DatabaseCleaner.clean_with(:truncation)
end
config.before(:each) do
DatabaseCleaner.strategy = :transaction
end
config.before(:each, js: true) do