Skip to content

Instantly share code, notes, and snippets.

havin a normal one

Dan Nguyen dannguyen

havin a normal one
View GitHub Profile
dannguyen /
Created Aug 26, 2015
strip-instagram-data-ids: remove some identifier information from a list of Instagram images
# convenience script to obfuscate, but not completely redact, *some*
# identifier information from a list of Instagram images, such as
# all likes and commenters. Image unique ID is left in so original data
# can be recovered
import json
from random import choice
from string import ascii_letters, digits
FNAME = './examples/images.json'
jdata = json.load(open(FNAME))
dannguyen / index.html
Last active Aug 27, 2015
Modified version of
View index.html
<!DOCTYPE html>
<meta charset="utf-8">
copied from Mike Bostock:
<script src=""></script>
<script src=""></script>
dannguyen / erb-to-slim-kindof.rb
Last active Aug 29, 2015
Prepare ERB for SLIM
View erb-to-slim-kindof.rb
# Not great, but better than doing everything by hand...
def prepare_erb_for_slim(body)
# remove all %>
body.gsub!(/%> */, '')
# convert <%-/= to -
body.gsub!(/<%(-|=) */, '\1 ')
dannguyen / loofah-and-nokogiri-whitespace.rb
Created Feb 14, 2014
How to use the Loofah library with a Nokogiri node to preserve line breaks between block elements
View loofah-and-nokogiri-whitespace.rb
npage = Nokogiri::HTML(html)
h[:text] = Loofah.fragment('.displaytext').to_html).to_text
dannguyen / ruby-wrap-graphicsmagick-blue.rb
Created Feb 18, 2014
Ruby invoking graphicsmagick to make images blue because I'm too lazy to learn shell loops
View ruby-wrap-graphicsmagick-blue.rb
Sector.all.each do |sector|
files = Dir.glob("./**/skift/#{sector.slug}.png").reject{|f| f =~ /-blue\.\w{3,4}$/}
files.each do |fname|
cmd = "convert #{fname} -fill '#2b74a5' +opaque darkblue #{fname}"
puts cmd
dannguyen / sublime.text.user-settings.json
Last active Aug 29, 2015
Setting the defaults for my Sublime Text 3
View sublime.text.user-settings.json
"always_show_minimap_viewport": true,
"auto_complete_commit_on_tab": true,
"auto_find_in_selection": true,
dannguyen / sublime-text-3.keys.move-character.json
Created Mar 16, 2014
Sublime Text 3 keyboard shortcut: Mapping Shift-Tab to move outside a right closing bracket/braces/quote-mark
View sublime-text-3.keys.move-character.json
"keys": ["shift+tab"], "command": "move", "args": {"by": "characters", "forward": true}
dannguyen / value-lengths-dist-for-field.sql
Last active Aug 29, 2015
find distribution of value lengths for a given field
View value-lengths-dist-for-field.sql
SET @field_name = "place_of_service";
SET @tablename = "payments";
SET @query = CONCAT('SELECT ', @field_name, ', count(1), length(', @field_name, ') AS lt FROM ', @tablename,' GROUP BY ', @field_name, ' ORDER BY lt desc');
PREPARE stmt FROM @query;
dannguyen / minimal-rspec-setup.rb
Created Apr 3, 2014
Minimal number of files to run `rspec` from command-line in your folder
View minimal-rspec-setup.rb
# Needed files:
# - Rakefile
# - Gemfile
# - spec/spec_helper
## Gemfile
source ''
gem 'rspec'
View ruby-enumerables-sugar.rb
stores.each do |store|
if country == store[:name]
store_id = store[:id]
### With #select