Skip to content

Instantly share code, notes, and snippets.

View jweir's full-sized avatar
🌴
On vacation - foreva

John Weir jweir

🌴
On vacation - foreva
View GitHub Profile
@jweir
jweir / gist:633535
Created October 19, 2010 03:02 — forked from wayneeseguin/gist:588881
fixed a typo & deprecated method
#!/usr/bin/env bash
# Author: Wayne E. Seguin (wayneeseguin@gmail.com)
#
# I like the sound of 'work_on', however you can name this
# function anything that makes it easier for you to think.
#
work_on ()
{
# We are expecting project name to be the first parameter
@jweir
jweir / protovis_to_link.js
Created November 19, 2010 19:23
How to save SVG data to a file from a web browser
@jweir
jweir / migrate_taggings.rb
Created January 21, 2012 18:49
Migrate from ActsAsTaggableOnSteroids to ActsAsTaggableOn
class MigrateTaggings < ActiveRecord::Migration
def up
change_table :taggings do |t|
t.references :tagger, :polymorphic => true
t.string :context, :limit => 128
t.index [:taggable_id, :taggable_type, :context]
end
ActsAsTaggableOn::Tagging.all.each {|t| t.update_attribute :context, 'tags'}
end
@jweir
jweir / gist:1903527
Created February 24, 2012 20:27
dynamic keys in object
# Oh, if only this were possible. I know it is not in JS, but still would be cool
z = 'a key'
x =
"#{z}" : 1
@jweir
jweir / convert.rb
Created April 19, 2012 18:36
Daniel's pollution and position converter
#!/usr/bin/env ruby
# Script to load GPS and CO2 data and normalize the data
# the position data in a file "run.xml"
# pollution in a file "pollution.txt"
require 'nokogiri'
require 'fastercsv'
require 'active_support'
@jweir
jweir / summary
Created May 5, 2012 16:54
MySQL table size summmary
# thank you http://www.mysqlperformanceblog.com/2008/02/04/finding-out-largest-tables-on-mysql-server/
SELECT CONCAT(table_schema, '.', table_name),
CONCAT(ROUND(table_rows / 1000000, 2), 'M') rows,
CONCAT(ROUND(data_length / ( 1024 * 1024 * 1024 ), 2), 'G') DATA,
CONCAT(ROUND(index_length / ( 1024 * 1024 * 1024 ), 2), 'G') idx,
CONCAT(ROUND(( data_length + index_length ) / ( 1024 * 1024 * 1024 ), 2), 'G') total_size,
ROUND(index_length / data_length, 2) idxfrac
FROM information_schema.TABLES
ORDER BY data_length + index_length DESC
LIMIT 10;
@jweir
jweir / flex-image.js
Created May 17, 2012 13:56
flex-image: javascript for image replacement based on screen size
(function(){
/*
flex-image: javascript for image replacement based on screen size
by John Weir http://famedriver.com
Usage, where `*` will be replaced by the image size.
<img data-src='/path-to-image/image-*.jpg' data-sizes='320:480,481:960' class='flex-image'/>
Thanks to Aurélien Delogu & Molt for the inspiration -> https://github.com/pyrsmk/molt
@jweir
jweir / redis-eventsource.go
Last active April 19, 2021 03:08
Example of using Redis PubSub and EventSource with golang
package main
import (
eventsource "github.com/antage/eventsource/http"
redis "github.com/vmihailenco/redis"
"log"
"net/http"
)
func haltOnErr(err error){
@jweir
jweir / gist:bfac545a1648620c1247
Created August 29, 2014 14:35
Weeding functions
// just a sketch to put away for now
// these are weeding functions
// the goal is to remove lables on a graph that are too close together (ie weed out overlapping labels)
function weed(array, x, y){
var f = array[0]
, l = array[array.length -1]
, ex = d3.extent(array, function(d){ return d.y })
, hiLo = array.filter(function(d){ return d.y == ex[0] || d.y == ex[1]});
return _.uniq([f,l].concat(hiLo));
@jweir
jweir / fixslides.js
Last active August 29, 2015 14:27
I dislike the slide deck that the Go team uses for the presentations. It is a bit of a pain to read and follow on a desktop. This bit-o-JS will turn the slide deck into a normal scrolling page.
$('article').attr('class','current').css({position: 'relative', margin: 10, padding: '20px',top: 0, left: 0, height: 'auto', width: 'auto'}), $('#help').remove(), document.removeEventListener('keydown', handleBodyKeyDown), $('h2').css({position:'static'})