Skip to content

Instantly share code, notes, and snippets.

@xhinking
xhinking / pc2.py
Created March 21, 2013 17:30
Python Challenge Level 2 Code
# find in my other gist
words = open("words.txt").read()
# 97-121 65-90
def Sp(c):
x = ord(c)
if (x >= 65 and x <= 90) or (x >= 97 and x <= 121):
return chr(x)
else:
return ''
@xhinking
xhinking / pc3.py
Created March 21, 2013 17:31
Python Challenge Level 3 Code
import re
text = open("words3.txt").read()
print ''.join(re.findall('[^A-Z][A-Z]{3}([a-z])[A-Z]{3}[^A-Z]', text))
@xhinking
xhinking / issameday.m
Created April 23, 2013 07:24
is same day method in obejctive c
- (BOOL)isSameDay:(NSDate*)date1 otherDay:(NSDate*)date2 {
NSCalendar* calendar = [NSCalendar currentCalendar];
unsigned unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit;
NSDateComponents* comp1 = [calendar components:unitFlags fromDate:date1];
NSDateComponents* comp2 = [calendar components:unitFlags fromDate:date2];
return [comp1 day] == [comp2 day] &&
[comp1 month] == [comp2 month] &&
[comp1 year] == [comp2 year];
@xhinking
xhinking / earthquake.py
Created August 8, 2013 04:38
Earthquake Data crawler
# -*- coding: utf-8 -*-
# Data Source: http://earthquake.usgs.gov/earthquakes/eqarchives/epic/
import urllib2
import csv
import pymongo
import time
import calendar
from datetime import date
@xhinking
xhinking / tpl_mongo.py
Created August 8, 2013 08:18
python mongodb template.
import pymongo
# Connect MongoDB
conn = pymongo.Connection('localhost', 27017)
mongodb = conn.dbname
@xhinking
xhinking / blur.css
Created August 25, 2013 16:42
blur effect css
#myDiv:hover #effect {
display:block;
-webkit-filter: blur(20px);
-moz-filter: blur(15px);
-o-filter: blur(15px);
-ms-filter: blur(15px);
filter: blur(15px);
opacity: 0.95;
}
@xhinking
xhinking / d3-table.coffee
Created September 12, 2013 07:36
using d3.js generate a table
d3.csv 'data/data.csv', (data) ->
rows = table.selectAll('tr').data(data)
.enter().append('tr').style('color', (d)-> d.color)
.html((d)-> '<td>'+d.aa+'</td><td>'+d.bb+'</td><td>'+d.cc+'</td>')
jsgradient = {
inputA : '',
inputB : '',
inputC : '',
gradientElement : '',
// Convert a hex color to an RGB array e.g. [r,g,b]
// Accepts the following formats: FFF, FFFFFF, #FFF, #FFFFFF
hexToRgb : function(hex){
var r, g, b, parts;
@xhinking
xhinking / crop.js
Created December 26, 2013 08:13 — forked from arian/crop.js
var spawn = require('child_process').spawn;
var Stream = require('stream');
/**
* crops and resizes images to our desired size
* @param {Stream} streamIn in stream containing the raw image
* @return {Stream}
*/
exports.cropImage = function(streamIn){