Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
havin a normal one

Dan Nguyen dannguyen

💭
havin a normal one
View GitHub Profile
@dannguyen
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
SELECT
`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
dannguyen / make-andpdftk.sh
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.
View make-andpdftk.sh
# First
# http://unix.stackexchange.com/questions/46948/how-to-make-duplicates-with-different-names-from-a-single-file
mkdir copies
newnames=("a" "b" "c" "d" "e")
orgfile=my_original_doc.pdf
for x in "${newnames[@]}"; do
cp $orgfile "copies/$x.pdf"
done
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.
course_id,userid_DI,registered,viewed,explored,certified,final_cc_cname_DI,LoE_DI,YoB,gender,grade,start_time_DI,last_event_DI,nevents,ndays_act,nplay_video,nchapters,nforum_posts,roles,incomplete_flag
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
HarvardX/CB22x/2013_Spring,MHxPC130539455,1,1,0,0,France,NA,NA,NA,0,2013-01-01,2013-05-14,42,6,,3.0,0,,
Harvard
View middleman-readme.markdown.md

Middleman - Makes developing websites simple

Middleman is a static site generator using all the shortcuts and tools in modern web development. Check out middlemanapp.com 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 = "http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js";element1.type="text/javascript";document.getElementsByTagName("head")[0].appendChild(element1);
var str = "<table><tbody>";
$(".field-items h3").each(function(){
var h3 = $(this);
var p = h3.next();
var rows = p.html().split("<br>").reverse();
View unix-tricks.txt
# A mirror of: http://cfenollosa.com/misc/tricks.txt
-----------------
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!
BASH
* In bash, 'ctrl-r' searches your command history as you type
- Input from the commandline as if it were a file by replacing
@dannguyen
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
dannguyen / nyt-list-scrape.rb
Last active Aug 29, 2015
A script to scrape what nytimes.com 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
dannguyen / sharknado-blocker.md
Last active Aug 29, 2015
Sharknado Protection - protect your twitter timeline from the #sharknado
View sharknado-blocker.md

Sharknado Protection

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

Pre-installation

gem install t

@dannguyen
dannguyen / ca_public_salaries.rb
Created Sep 1, 2014
A quickie script to batch download all the raw salary data from publicpay.ca.gov 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 publicpay.ca.gov
#
# by Dan Nguyen
#
# How to use:
# install these gems: nokogiri, rubyzip
#
# then pop open irb and run: