Skip to content

Instantly share code, notes, and snippets.

View wizjo's full-sized avatar
🏠
Working from home

Jo Pu wizjo

🏠
Working from home
View GitHub Profile

Keybase proof

I hereby claim:

  • I am wizjo on github.
  • I am wizjo (https://keybase.io/wizjo) on keybase.
  • I have a public key ASDBdrtu0w47RZ0gJO4phuruQ9eUpHJf1iV5IDItdc6fxwo

To claim this, I am signing this object:

@wizjo
wizjo / java_version_check
Created August 15, 2012 16:45
checking installed java versions on OSX
/usr/libexec/java_home -V
@wizjo
wizjo / README.md
Created April 26, 2012 18:39 — forked from mbostock/.block
Line Transition

D3’s default path interpolation is the same as its string interpolation: it finds numbers embedded in strings, and interpolates those numbers. So, the default behavior when interpolating two paths is like this:

M x0, y0 L x1, y1 L x2, y2 L x3, y3 
   ↓   ↓    ↓   ↓    ↓   ↓    ↓   ↓
M x0, y1 L x1, y2 L x2, y3 L x3, y4 

For example, the first point ⟨x0,y0⟩ is interpolated to ⟨x0,y1⟩. Since x0 is the same, all you see are the y-values changing (see example)—you don't see the path slide to the left as intended.

What you want to happen here is something like this:

@wizjo
wizjo / parse_tablenames.rb
Created April 7, 2012 06:31
Parse table names
# parse_tablenames.rb
table_freq = {}
IO.foreach("query_frequency.txt") do |line|
next if line =~ /^query_id/
next if line.nil?
regex = /(from|join)\s+([^\s\(]+)/i
matches = line.scan(regex)
cnt = line.match(/\d+$/)[0].to_i
SELECT sub2.period_id, sub2.time_id, sub2.network_id, COUNT(1) as cnt
FROM (
SELECT sub1.period_id,
sub1.time_id,
sub1.network_id,
SUM(sub1.pct_squared) AS dept_concentration_hhi
FROM (SELECT sub.period_id,
sub.time_id,
sub.network_id,
sub.job_type,
@wizjo
wizjo / find_first_duplicate_key.sql
Created March 5, 2012 18:31
Find the first_value(id) of dup key
SELECT FIRST_VALUE(pkey_id) OVER(PARTITION BY cnt ORDER BY cnt DESC, pkey_id)
AS first_id
FROM (
SELECT pkey_id,
COUNT(*) AS cnt
FROM dimension_attribute_histories
GROUP BY 1
)sub
LIMIT 1
@wizjo
wizjo / expensive_queries_check.sql
Created October 3, 2011 19:49
Most expensive queries
select sub.query_id, sub.result, sub.sql,
avg(sub.time_lapse) as avg_time,
max(sub.started_at) as last_run_at,
count(1) as cnt
from
(
select qe.query_id,
qe.result,
qe.started_at,
(qe.finished_at - qe.started_at) time_lapse,
@wizjo
wizjo / group_sort.r
Created July 21, 2011 04:46
SQL-like Grouping and Sorting in R
## here's how you do a "SELECT col1,col2,col3,col4, count(1) AS cnt FROM ds_subs_less_table GROUP BY 1,2,3,4" thing in R ##
# first, find out all the unique combos of col1,col2,col3,col4
subs.geo <- data.frame(unique(cbind(
as.character(ds.subs.less$source_tz), as.character(ds.subs.less$source_country),
as.character(ds.subs.less$target_tz), as.character(ds.subs.less$target_country)
)))
names(subs.geo) <- c("source_tz", "source_country", "target_tz", "target_country")
# next, figure out the frequency of each combo shows up
@wizjo
wizjo / logo.py
Created July 2, 2011 06:12
IAR logo with Nodebox
scl = 3
r = .3 ## roundness of the rectangles
size(100*scl, 100*scl)
w=10*scl
mat1=[
[0,2,2,0,2,2,2,0],
[1,0,0,1,2,0,0,2],
[1,0,0,1,2,0,0,2],
[1,0,0,1,2,0,0,2],
@wizjo
wizjo / tags.py
Created July 2, 2011 06:11
Tags of me with Nodebox
grid = ximport("grid")
words = ["data", "visualization", "mining", "analysis", "design", "UX"]
colormode(RGB, range=255)
colors = [color(255,30,25), color(124,155,220),color(100,100,100), color(197,206,216)]
fontlist = ["Arial Black", "Trebuchet MS", "Georgia"]
def randContent(x, y, w, h, style=None):
for i in range(40):
x1 = random(0,w/2)