Skip to content

Instantly share code, notes, and snippets.

havin a normal one

Dan Nguyen dannguyen

havin a normal one
View GitHub Profile
dannguyen / google-analytics-for-wordpress-sql-join.sql
Last active Aug 29, 2015
connecting wordpress to google analytics in MySQL
View google-analytics-for-wordpress-sql-join.sql
`wp_terms`.`slug` AS wordpress_category,
COUNT(1) AS post_count,
SUM(`google_stats`.`Visits`) AS total_visits,
SUM(`google_stats`.`New Visits`) AS total_new_visits,
ROUND((SUM(`google_stats`.`Visits`) / COUNT(1)), 1) AS visits_per_post
FROM `wp_posts`
INNER JOIN `wp_term_relationships`
dannguyen /
Last active Aug 29, 2015
This is just a quickie write-up of how to de-secure PDF files using ghostscript from the command line. There's some setup code to simulate a bunch of locked PDFs.
# First
mkdir copies
newnames=("a" "b" "c" "d" "e")
for x in "${newnames[@]}"; do
cp $orgfile "copies/$x.pdf"
View HMXPC13_DI_v2_5-14-14-sample.csv
We can make this file beautiful and searchable if this error is corrected: It looks like row 10 should actually have columns, instead of 1. in line 9.
HarvardX/CB22x/2013_Spring,MHxPC130442623,1,0,0,0,United States,NA,NA,NA,0,2012-12-19,2013-11-17,,9,,,0,,1
HarvardX/CS50x/2012,MHxPC130442623,1,1,0,0,United States,NA,NA,NA,0,2012-10-15,,,9,,1.0,0,,1
HarvardX/CB22x/2013_Spring,MHxPC130275857,1,0,0,0,United States,NA,NA,NA,0,2013-02-08,2013-11-17,,16,,,0,,1
HarvardX/CS50x/2012,MHxPC130275857,1,0,0,0,United States,NA,NA,NA,0,2012-09-17,,,16,,,0,,1
HarvardX/ER22x/2013_Spring,MHxPC130275857,1,0,0,0,United States,NA,NA,NA,0,2012-12-19,,,16,,,0,,1
HarvardX/PH207x/2012_Fall,MHxPC130275857,1,1,1,0,United States,NA,NA,NA,0,2012-09-17,2013-05-23,502,16,50,12.0,0,,
HarvardX/PH278x/2013_Spring,MHxPC130275857,1,0,0,0,United States,NA,NA,NA,0,2013-02-08,,,16,,,0,,1

Middleman - Makes developing websites simple

Middleman is a static site generator using all the shortcuts and tools in modern web development. Check out for detailed tutorials, including a getting started guide. You can also follow @middlemanapp for updates.

Why Middleman?

The last few years have seen an explosion in the amount and variety of tools developers can use to build web applications. Ruby on Rails selects a handful of these tools:

View ad-hoc-jquery-web-scraper-dhs.js
var element1 = document.createElement("script");element1.src = "";element1.type="text/javascript";document.getElementsByTagName("head")[0].appendChild(element1);
var str = "<table><tbody>";
$(".field-items h3").each(function(){
var h3 = $(this);
var p =;
var rows = p.html().split("<br>").reverse();
View unix-tricks.txt
# A mirror of:
I have marked with a * those which I think are absolutely essential
Items for each section are sorted by oldest to newest. Come back soon for more!
* In bash, 'ctrl-r' searches your command history as you type
- Input from the commandline as if it were a file by replacing
dannguyen / add-seconds-to-timestamp-xmp.rb
Created Jul 6, 2014
For Adobe Lightroom XMP files, a quickie Ruby script to timeshift the capture time by an arbitrary number of seconds
View add-seconds-to-timestamp-xmp.rb
# A quickie script to timeshift all XMP files of a certain camera model
# by an arbitrary number of seconds
require 'nokogiri'
require 'chronic'
require 'fileutils'
files = Dir.glob('./xmps/*.xmp')
orgdir = "./new-xmps"
seconds_to_shift = 98
model_name_to_change = 'NEX-7'
dannguyen / nyt-list-scrape.rb
Last active Aug 29, 2015
A script to scrape what recommends to me and also, what is popular among other users
View nyt-list-scrape.rb
#!/usr/bin/env ruby
# nyt-list-scrape.rb
# Dan Nguyen @dancow
# Created: 2014-07-26
# Updated: 2014-07-29
# Scrape the titles/urls of articles recommended to the user by the NYT,
# and also, the most popular ones at the moment
# Requirements: Ruby 1.9.x and the Mechanize gem and a NYT digital subscriber account
dannguyen /
Last active Aug 29, 2015
Sharknado Protection - protect your twitter timeline from the #sharknado

Sharknado Protection

This series of commands will unfollow anyone you currently follow who has recently mentioned "sharknado".


gem install t

dannguyen / ca_public_salaries.rb
Created Sep 1, 2014
A quickie script to batch download all the raw salary data from and combine into one file
View ca_public_salaries.rb
# ca_public_salaries.rb
# A quickie script to batch download all the raw salary data
# from
# by Dan Nguyen
# How to use:
# install these gems: nokogiri, rubyzip
# then pop open irb and run: