Skip to content

Instantly share code, notes, and snippets.

View jamesshipton's full-sized avatar

James Shipton jamesshipton

View GitHub Profile
@jamesshipton
jamesshipton / ruby_triple_store_jena.rb
Created May 11, 2011 15:17
Ruby::TripleStore::Jena input an rdf/xml file, with reified addition/removals for a changeset and output either the additions or removals as triples
require 'java'
dir = Dir.new("***CLASSPATH_DIR***")
dir.each {|file| $CLASSPATH << dir.path + file if file.end_with?('jar')}
java_import com.hp.hpl.jena.rdf.model.ModelFactory;
java_import com.hp.hpl.jena.rdf.model.impl.StatementImpl;
java_import java.lang.System;
@jamesshipton
jamesshipton / n3_to_json.rb
Created May 11, 2011 15:51
Ruby::TripleStore::Tripod - convert n3 to rdf/json
require 'java'
dirs = [Dir.new('***classpath_dir***')]
dirs.each {|dir| dir.each{|file| $CLASSPATH << dir.path + file if file.end_with?('jar')}}
java_import '***.ContentNegotiator'
java_import '***.JsonRdfSerializer'
java_import '***.JenaOntologyHelper'
@jamesshipton
jamesshipton / sesame_connection.rb
Created May 11, 2011 15:53
Ruby::TripleStore::Sesame connect to triplestore using sesame and find statements
require 'java'
dir = Dir.new('***classpath_dir***')
dir.each {|file| $CLASSPATH << dir.path + file if file.end_with?('jar')}
java_import org.openrdf.repository.Repository;
java_import org.openrdf.repository.RepositoryConnection;
java_import org.openrdf.repository.http.HTTPRepository;
java_import org.openrdf.model.URI;
java_import org.openrdf.repository.RepositoryException;
@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
@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 / 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 / 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
Object.send(:define_method, :eigen, lambda{ class << self; self; end }) #crack open the eigenclass
@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
@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