View short_lived_threads_connection_pool.rb
module ActiveRecord
module ConnectionAdapters # :nodoc:
class ConnectionPool
def checkout_with_cleared_stale_cached_connections
synchronize do
# reclaim unused connections immediately to optimize for short-lived threads
clear_stale_cached_connections!
checkout_without_cleared_stale_cached_connections
View convert_images.go
package main
import (
"github.com/tobi/mogrify-go"
"net/http"
"github.com/gorilla/mux"
"strconv"
"strings"
"log"
"regexp"
View marshaled_class_attribute.rb
# Ripped out of ActiveSupport 2.3.8 and modified.
# MIT LICENSE
# Copyright (c) 2005-2012 David Heinemeier Hansson
# Copyright (c) 2012 Zencoder
#
# Allow inheritable class attributes, but marshal/unmarshal the value when it is
# inherited to prevent object modifications from being passed onto children.
# With ActiveSupport's class_attribute, objects that are modified via accessing
# them will be passed on to all child classes. Only assignment to a class
# attribute will cause the child to have a different value than the parent.
View get_process_tree_cpu_usage.py
import psutil
import re
for process in psutil.process_iter():
try:
# match against a proctitle. will raise an exception if you can't query
# the process' cmdline which is caught below
if len(process.cmdline) and re.match("MY PROCTITLE", process.cmdline[0]):
# add up cpu usage
cpu_usage = 0.0
View rubby.rb
def extract_components(filename)
segments = filename.split(" ")
last_segment, *extensions = segments.pop.split(".")
basename = (segments << last_segment).join(" ")
[basename, extensions]
end
extract_components("a.b c.a")
# => ["a.b c", ["a"]]
View gist:3758090
read_pipe, write_pipe = IO.pipe
input_file = File.open("input_video.mp4", "r")
output_file = File.open("output_video.mp4", "w")
Thread.new do
loop do
begin
write_pipe.write(input_file.read_nonblock(1024))
rescue EOFError => e
write_pipe.close
View hack.sh
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2260182/87abace383ef4321d6e9174c29105f66300331d7/hack.sh | sh
#
View gist:3608072
api_concern :public_browser_base do |t|
t.add :id
t.add :title
end
api_accessible :v1_public_browser do |t|
t.concern :public_browser_base
t.add :current_state
t.add :start_date_unixtime
end
View install_package_manager.sh
echo;echo;echo
echo "YOUR MACHINE WAS JUST OWNED. OR IT WOULD BE, IF I WANTED IT TO BE. IMPLICIT TRUST IS A BAD THING."
echo;echo;echo
View timestamping_cassandra.rb
# If you insert a column using a timestamp that is before the current value's
# timestamp, your insert will be rejected. The timestamps come from the client
# not the server unless you're using CQL (apparently).
require 'rubygems'
require 'cassandra-cql'
require 'cassandra/1.0'
# Freezes time so we can mock it out for the duration of a block
require 'timecop'