Skip to content

Instantly share code, notes, and snippets.

View lopopolo's full-sized avatar

Ryan Lopopolo lopopolo

View GitHub Profile
@lopopolo
lopopolo / thread_peg.rb
Created July 9, 2019 09:42
Testing GIL throughput on CRuby
#!/usr/bin/env ruby
# frozen_string_literal: true
# Ruby GIL test
# Ideally this should saturate two cores.
a = []
b = []
t1 = Thread.new do
@lopopolo
lopopolo / temp_django_backup.py
Created July 10, 2016 06:54
Quick-fix to the original django-backup.py to get media archive smaller
#!/usr/bin/env python
import contextlib
import datetime
import os
import shutil
import smtplib
import subprocess
import tarfile
import tempfile
@lopopolo
lopopolo / console
Last active August 29, 2015 14:07
Scala return keyword short-circuits code execution in other functions
scala> foo1
finally
res0: String = foo
scala> foo2
finally
after
res1: String = foo
@lopopolo
lopopolo / gist:9427762
Created March 8, 2014 09:19
Relink all homebrew formulae after Mavericks upgrade
▶ brew list -1 | while read line; do brew unlink $line; brew link $line; done
Unlinking /usr/local/Cellar/appledoc/2.2... 0 links removed
Linking /usr/local/Cellar/appledoc/2.2... 1 symlinks created
Unlinking /usr/local/Cellar/autoconf/2.69... 0 links removed
Linking /usr/local/Cellar/autoconf/2.69... 18 symlinks created
Unlinking /usr/local/Cellar/bash-completion/1.3... 184 links removed
Linking /usr/local/Cellar/bash-completion/1.3... 182 symlinks created
Unlinking /usr/local/Cellar/bgrep/0.2... 0 links removed
Linking /usr/local/Cellar/bgrep/0.2... 1 symlinks created
Unlinking /usr/local/Cellar/binutils/2.24... 49 links removed
@lopopolo
lopopolo / ruby-warrior.rb
Created August 15, 2013 06:45
hacking at the ruby warrior game.
class Player
def max_health; 20; end;
def healing_threshold; 10; end
def initialize
@healing = false
@retreating = false
@last_action = nil
@lopopolo
lopopolo / array_lookup.php
Last active December 19, 2015 17:19
microbenchmark for lookup performance in arrays and objects in PHP
<?php
# vim: sw=2 ts=2
echo 'PHP version: ' . phpversion() . PHP_EOL;
function lookup_ake(array $a, $key, $default = null)
{
if (array_key_exists($key, $a))
{
return $a[$key];
@lopopolo
lopopolo / last.coffee
Created February 13, 2013 02:02
Hubot script to replay the last bot command
# Description:
# Last asks Hubot to repeat the last command he received
#
# Commands:
# hubot !! - execute the last received command
# hubot last - execute the last received command
# hubot repeat - execute the last received command
Robot = require('hubot')
#!/usr/bin/env ruby
POPSIZE = 2048
MAXITER = 16384
ELITRATE = 0.10
MUTATIONRATE = 0.25
TARGET = "Hello world!"
class Ga
attr_accessor :str, :fitness
@lopopolo
lopopolo / test.rb
Created February 28, 2012 06:40
The power of try-catch-finally
def fun
begin
return "begin"
ensure
return "ensure"
end
end
puts "fun returned: '#{fun}'"