Skip to content

Instantly share code, notes, and snippets.

View gstark's full-sized avatar

Gavin Stark gstark

View GitHub Profile
# 004
sorted_rates = rates.select { |rate| rate.from != 'USD' }.
sort { |a, b| a.from <=> from_cur }.
map { |rate| [rate] }
# Split the select into two? less efficient but "single responsibility" ?
all_paths(sorted_rates).select { |rates_arr| rates_arr.first.from == from_cur && rates_arr.last.to == 'USD' }.
sort { |a, b| a.length <=> b.length }.
first
module ActiveRecord
class Base
# Define a method that can be called on an ActiveRecord::Base class
# or on a Scope object. This will call the db-adapters select_and_yield
# to perform the query and yield back each row found. Each row is then
# instantiated into an object and yielded to the caller.
def self.yield_all(*args)
raise "Must supply block" unless block_given?
options = args.extract_options!
@gstark
gstark / expand.txt
Created April 9, 2014 13:08
How to expand an LVM volume
How to expand a volume
1) Add new disk to the VM
2) Ensure it shows up as a device
3) fdisk /dev/____
4) add a partition (primary?)
5) sudo pvcreate /dev/____
6) sudo pvs # get name of volume group
7) sudo vgextend NAME_OF_VOLUME_GROUP /dev/____
8) sudo lvextend -l+100%FREE /dev/NAME_OF_VOLUME_GROUP/root
@gstark
gstark / pluck.rb
Created July 20, 2014 00:31
pluck backported to Rails 3.x
module ActiveRecord
class Base
class << self
delegate :pluck, :ids, :to => :scoped
end
end
class CollectionProxy
delegate :pluck, :ids, :to => :scoped
end
@gstark
gstark / dpkg.txt
Created August 13, 2014 18:45
xrandr issues with xorg-intel
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version Architecture Description
+++-===============================-====================-====================-===================================================================
ii accountsservice 0.6.35-0ubuntu7.1 i386 query and manipulate user account information
ii acl 2.2.52-1 i386 Access control list utilities
ii adduser 3.113+nmu3ubuntu3 all add and remove users and groups
ii apparmor 2.8.95~2430-0ubuntu5 i386 User-space parser utility for AppArmor
ii apt 1.0.1ubuntu2.1 i386 commandline package manager
@gstark
gstark / xrandr.txt
Created August 13, 2014 18:50
xrandr failure
# Failure with xrandr when TearFree is enabled
xrandr -d :0 --output LVDS1 --off
xrandr -d :0 --output TV1 --off
xrandr -d :0 --output VIRTUAL1 --off
xrandr -d :0 --output VGA1 --off
xrandr -d :0 --output DVI1 --off
xrandr -d :0 --output VGA1 --mode 1920x1080 --refresh 60 --rotation normal
xrandr -d :0 --output DVI1 --mode 1920x1080 --refresh 60 --rotation normal
xrandr -d :0 --output DVI1 --right-of VGA1 # FAILS HERE with: “Configure crtc 1 failed”
@gstark
gstark / gist:fd68480cc0c2c197a6f5
Last active August 29, 2015 14:05
xrandr (2.99.910) with --enable-debug=full
+ xrandr -d :0 --output DVI1 --right-of VGA1
X: ../../../src/sna/kgem.c:4173: kgem_create_2d: Assertion `size && size <= kgem->max_object_size' failed.
XIO: fatal IO error 11 (Resource temporarily unavailable) on X server ":0"
after 38 requests (38 known processed) with 0 events remaining.
[ 42.911]
X.Org X Server 1.15.1
Release Date: 2014-04-13
[ 42.911] X Protocol Version 11, Revision 0
@gstark
gstark / Xorg.0.log.gz
Last active August 29, 2015 14:05
xrandr (2.99.914+git20140811.6554cf0a)
BIG_BEFORE="big before"
BIG_AFTER="big after"
GARBAGE="garbage"
REGEXP=/big /
$big_after_id = 0
$big_before_id = 0
$callable_id = 0
@gstark
gstark / terminal_kittens.rb
Created May 19, 2015 19:48
Kittens in your terminal, how awesome!
require "base64"
require "open-uri"
def url_to_terminal_image(url)
raw_image = open(url).read
encoded_image = Base64.encode64(raw_image).gsub(/[\n\r]/,'')
"\033]1337;File=size=#{raw_image.length};inline=1:#{encoded_image}\a\n"
end