Skip to content

Instantly share code, notes, and snippets.

View jphastings's full-sized avatar
🌴

JP Hastings-Edrei jphastings

🌴
View GitHub Profile
@jphastings
jphastings / WhereOnTheWeb.rb
Created April 21, 2009 01:29
A ruby-processing tool that lets you visualize where on the planet your network traffic is coming from.
# Soooooo. Its hacky, and I'm sure there are improvements (shout if you have any) but...
# # # # # # # # # # # # # # # # # # # # # # # #
# - - - Where On The Web - - -
# A ruby-processing tool that lets you visualize where your network traffic is coming from.
#
# My thanks to jashkenas for his excellence - not only in releasing ruby-processing
# but also for his rapid help in the forums when Java and Ruby fell out.
#
# Code as art,
# JP - jphastings.tumblr.com
# gem install jphastings-dlc
require 'dlc'
s = DLC::Settings.new
s.name = "Your Name"
s.url = "http://yourdomain.com"
s.email = "[email protected]"
# Now you can make a dlc:
package = DLC::Package.new
package.name = "My package" # Suggested, but not required
// Lets javascript add twitter links to @reply style text items in any selected html elements
// Requires MooTools' selectors
function tumblrTweets(selector) {
$$(selector).each(function(t) {
t.set('html',t.get('html').replace(/@([a-zA-Z0-9_]+)/,"<a href=\"http://twitter.com/$1\">$1</a>"));
});
}
@jphastings
jphastings / rougly.rb
Created May 22, 2009 18:48
A small Time class extension that gives a fuzzy time string output
class Time
# Gives a 'fuzzy' output of the distance to the time stored.
#
# eg. 'in 28 minutes' or '23 hours ago'
def roughly
diff = self.to_i - Time.now.to_i
ago = diff < 0
diff = diff.abs
case diff
when 0
@jphastings
jphastings / eta.rb
Created May 22, 2009 18:51
An ETA class to allow intuitive access to an estimated time of arrival
# Thanks Ellie and Robert! http://www.ruby-forum.com/topic/187604
# Allows relative times, most frequently used in times of arrival etc.
class ETA < Time
# Takes a number of seconds until the event
def self.new(seconds)
raise "ETA requires a number of seconds" if not seconds.is_a?(Numeric)
at Time.now + seconds
end
# Requires http://gist.github.com/116290
@jphastings
jphastings / percentage.rb
Created May 22, 2009 20:18
Allows a percentage to be used as a float, but shown as a percentage (to variable decimal places)
# Cheers Andrew http://www.ruby-forum.com/topic/187508
require 'delegate'
# Allows percentages to be inspected and stringified in human
# form "33.3%", but kept in a float format for mathmatics
class Percentage < DelegateClass(Float)
def to_s(decimalplaces = 0)
(((self * 10**(decimalplaces+2)).round)/10**decimalplaces).to_s+"%"
end
#!/usr/bin/env ruby
require 'plw'
### Program
if ARGV[0].nil? or not File.exists? ARGV[0]
$stderr.puts "Usage: #{$0} filename.plw\n You must specify a PLW file to parse"
Process.exit
end
$stdout.sync = true
# This options file will have your get_iplayer (linuxcentre.net) running smoothly on mac os x, outputting iTunes friendly m4v files (provided you install the binaries as explained below)
# Usually found in ~/.get_iplayer/options
# Download and install the binaries as described on his site, but be sure to install them to /usr/local/bin (and make sure they're executable)
# $ chmod +x ffmpeg
# $ sudo mv ffmpeg /usr/local/bin/ffmpeg
# and similar for flvstreamer. lame will install there by default and mplayer is explained below (for itv downloads)
rtmpdump /usr/local/bin/flvstreamer
lame /usr/local/bin/lame
fileprefix <name> - <episode> - <pid>
<!-- This is a quick rundown of how I got geotagging working in Tumblr via javascript and some hacking. Its in use at http://jpinjapan.tumblr.com - I hope tumblr builds it into their site soon! -->
<!-- This has to go somewhere at the top of your page, inside your <head>, as javascript -->
<!-- It prepares the regular expression that finds the geo: tags inside your various tags -->
var geore = new RegExp(/^geo:(-?\d+\.\d+);(-?\d+\.\d+)$/)
<!-- You must alter every <div> containing a post to look like this: -->
<div class="post text" id="post-{PostID}">
<!-- This is so that the javascript can find the posts it needs to. Its a hack around my unfamiliarity with jQuery really. -->
@jphastings
jphastings / Resolvable Podcasting.xml
Created November 16, 2009 16:29
An idea I had for describing composited audio such that copyrighted tracks can be resolved and an identical copyright conforming rendition can be created.
<?xml version="1.0" encoding="UTF-8"?>
<!-- Please read the blog entry for a description as to what this is: http://jphastings.tumblr.com/post/246130623 -->
<playlist simulatneous="true"> <!-- Or way informing that this playlist needs to be interpreted according to this article -->
<chapters> <!-- A new element entirely. The Hospital Podcast is a good example of chapter use in Podcasts. -->
<chapter> <!-- NB. There are other ways to define chapters -->
<cueTime relativeTo="id_of_element">±3142</cueTime> <!-- Milliseconds in from beginning (+) or back from the end (-) of the track referenced -->
<name>Name of Chapter</name>
<image>http://path.to/image</image> <!-- Individual chapters might have the album art of the song etc -->
</chapter>
</chapters>