Skip to content

Instantly share code, notes, and snippets.

View jamesshipton's full-sized avatar

James Shipton jamesshipton

View GitHub Profile
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jamesshipton
jamesshipton / synchronously.rb
Last active August 29, 2015 14:14
synchronously.rb
# Synchronously
class Fetcher
def self.fetch_api_data(uuids)
uuids.map { |uuid| new(uuid).fetch }
end
def fetch
"api response for #{uuid}"
end
@jamesshipton
jamesshipton / ruby-object-model.rb
Last active August 29, 2015 14:06
Ruby Object Model
MyModule = Module.new
MyModule.module_eval do
@module_ivar = 4
class << self
def my_singleton_method
@module_ivar
end
end
@jamesshipton
jamesshipton / linode_rebuild.rb
Last active December 19, 2015 02:48
Code to rebuild a Linode with ruby - using createfromdistribution. This code has been designed for use with one linode - if you have more than one it will need to be amended you will need to install the linode gem https://github.com/rick/linode
## Run rake rebuild
#
#task :rebuild do
# DiscogsServer.shutdown
#
# DiscogsServer.delete_disks
#
# DiscogsServer.delete_configs
#
# DiscogsServer.create_disks
@jamesshipton
jamesshipton / my_class_keywords.rb
Last active October 13, 2015 18:07
Please rewrite the MyString definition, without using ruby keywords # http://www.ruby-doc.org/docs/keywords/1.9/
# Please rewrite the MyString definition, without using ruby keywords
# http://www.ruby-doc.org/docs/keywords/1.9/
class MyString < String
class << self
def alphabet
'abc'
end
end
Object.send(:define_method, :eigen, lambda{ class << self; self; end }) #crack open the eigenclass
@jamesshipton
jamesshipton / ffmpeg_video_chunker
Created August 6, 2012 13:13
ffmpeg - split video file into smaller chunks
ffmpeg -ss 00:40:00 -t 1200 -i E3-1080.mp4 -acodec copy -vcodec copy E3-3-1080.mp4
@jamesshipton
jamesshipton / ffmpeg_audio_to_video
Created May 20, 2012 19:35
ffmpeg - add image to audio & convert to video
slow - ffmpeg -loop_input -shortest -y -i trevor_dale.jpg -i TrevorDale_Summer88.mp3 -acodec copy -vcodec mjpeg TrevorDale_Summer88.avi
fast - ffmpeg -f image2 -loop_input -i MichaelWatford_SoIntoYou\(DubMix\).jpg -i MichaelWatford_SoIntoYou\(DubMix\).mp3 -vcodec mpeg4 -qscale 2 -acodec copy -shortest MichaelWatford_SoIntoYou\(DubMix\)2.avi
@jamesshipton
jamesshipton / rename_files_in_folder.rb
Created January 4, 2012 06:46
Rename files in the current dir, if they match the regex
Dir.entries(".").each { |filename| if (filename =~ /\A[0-9]{3}-[a-zA-Z0-9]+-(.+)-small(.mp4)\Z/) then File.rename(filename, $1+$2) end }
@jamesshipton
jamesshipton / sed_amend_multiple_lines
Created June 1, 2011 16:40
sed - to amend multiple lines
cat changeset.xml | sed '/<cs:removal>/ {
N
s|<cs:removal>\n|<cs:removal>|
N
s|</rdf:Statement>\n|</rdf:Statement>|
}' | sed 's|<cs:removal>.*</cs:removal>||' > changeset_addition.xml