Skip to content

Instantly share code, notes, and snippets.

@clee704
clee704 / rename-field.py
Created December 31, 2011 17:05
Rename Drupal 7 fields
#! /usr/bin/env python
from datetime import datetime
from StringIO import StringIO
import getpass, os, re, subprocess, sys
import MySQLdb
def main():
if len(sys.argv) != 3:
@clee704
clee704 / korean_error_messages.rb
Created October 31, 2012 17:26
Display proper Korean particles in error messages
# encoding: UTF-8
# Original article: http://dailyupgrade.me/post/6806676778/rubyonrails-full-messages-for-korean
# Modified to support more postpositions and client_side_validations gem.
#
# Add Korean translations like this:
# ko:
# errors:
# format: "%{message}"
# messages:
# blank: "%{attribute}((이)) 입력되지 않았습니다"
// Stolen from http://stackoverflow.com/a/841121/332370
// Modified so that:
// 1. `end' can be omitted (defaults to the same value as `start').
// 2. -1 means the end of the range.
$.fn.selectRange = function(start, end) {
return this.each(function() {
if (typeof end == "undefined") {
end = start;
}
@clee704
clee704 / convert_css_uri.rb
Created May 14, 2013 00:41
Convert CSS URI values
# Parse CSS URI values according to http://www.w3.org/TR/CSS21/syndata.html#uri
URI_PATTERN = /
url\( # 'url('
[ \t\n\r\f]* # optional white space
(
# double quoted URI
(
(?<quote>") # an optional double quote
(?<str>([^"\\]|\\.)*?) # URI
"
@clee704
clee704 / prime.py
Last active August 29, 2015 13:57
Generate and test prime numbers
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright 2014 Choongmin Lee
# Licensed under the MIT License
import argparse
from random import SystemRandom
import sys
parser = argparse.ArgumentParser(description='Generate or test prime numbers.')
@clee704
clee704 / image_downloader.py
Last active August 29, 2015 13:58
Image Downloader
#! /usr/bin/env python
# Copyright 2014 Choongmin Lee
# Licensed under the MIT License
from __future__ import print_function
import argparse
from datetime import datetime
import os
import re
import sys
from tempfile import NamedTemporaryFile
// Makes the element be vertically centered in its parent.
angular.module('mygists', [])
.directive('verticalCenter', function ($window, $timeout) {
var win = angular.element($window);
function reposition(element, firstTime) {
var parent = element.parent();
var parentHeight = parent.innerHeight();
var elementHeight = element.outerHeight();
var top = (parentHeight - elementHeight) / 2;
@clee704
clee704 / ponder.py
Created May 15, 2014 16:45
Ponder This - August 2009
#! /usr/bin/env python3
# Solution to http://domino.research.ibm.com/Comm/wwwr_ponder.nsf/Challenges/August2009.html
import string
import sys
def main():
a = Expression('a', int('00001111', 2))
b = Expression('b', int('00110011', 2))
c = Expression('c', int('01010101', 2))

Keybase proof

I hereby claim:

  • I am clee704 on github.
  • I am choongmin (https://keybase.io/choongmin) on keybase.
  • I have a public key whose fingerprint is BCDF 9A00 2376 BF71 257A 21AE 1884 CDAA F39E 8F3F

To claim this, I am signing this object:

@clee704
clee704 / bitrot.py
Last active August 29, 2015 14:07
Randomly flip bits in the file
#! /usr/bin/env python
# Randomly flip bits in the file.
import argparse
import random
parser = argparse.ArgumentParser()
parser.add_argument('file', help='the file whose bits to be fliped')
parser.add_argument('count', type=int, default=1, nargs='?', help='number of rounds of bit flipping (default: 1)')
args = parser.parse_args()