Skip to content

Instantly share code, notes, and snippets.

@cybertk
cybertk / generate_samples.py
Created Jul 22, 2014
Generate normal distrubution samples with given mu and sigma
View generate_samples.py
#!/usr/bin/env python
import sys
import optparse
import numpy as np
from progress.counter import Counter
def GenerateSamples(mu, sigma, size, delta):
bar = Counter('Calculating: ')
@cybertk
cybertk / watermark.py
Created Jul 22, 2014
Add a text watermark to give image
View watermark.py
#!/usr/bin/env python
import os
import sys
TEXT_ID = 'itunesartwork'
# Provided by sw-dev.herokuapp.com
os.environ.setdefault('CLOUDINARY_URL',
'cloudinary://api_key:secret')
@cybertk
cybertk / generate_patch.rb
Created Jul 22, 2014
Generate patches from gerrit
View generate_patch.rb
#!/usr/bin/env ruby
# Generate patch from gerrit
require 'optparse'
def generatePatch(base_branch, topic_pattern, output_dir)
`git review -l | sed "s,\x1B\[[0-9;]*[a-zA-Z],,g"`.lines do |line|
_, patch, topic = line.match(/(\d+).*(#{topic_pattern}).*/).to_a
next if not patch or not topic
@cybertk
cybertk / remove_unused_images.py
Created Jul 22, 2014
Remove unused images from Xcode project
View remove_unused_images.py
#!/usr/bin/env python
# Copyright (c) 2014 Quanlong. All rights reserved.
#
# \author: Quanlong <quanlong.he@gmail.com>
import logging
import subprocess
import re
import optparse
import sys
@cybertk
cybertk / send_sms.py
Created Jul 22, 2014
Send sms via Twillio
View send_sms.py
#!/usr/bin/env python
from twilio.rest import TwilioRestClient
# Your Account Sid and Auth Token from twilio.com/user/account
account_sid =
auth_token =
client = TwilioRestClient(account_sid, auth_token)
message = client.sms.messages.create(body="Jenny please?! I love you <3",
@cybertk
cybertk / heroku.py
Created Jul 22, 2014
Auto append --app to heroku bin according to ENV['HEROKU_APP']
View heroku.py
#!/usr/bin/env python
#
# A simple wrapper support select app by reading from environment vars and
# auto append the --app to origin heroku bin.
#
# Last-updated: Fri Dec 6 17:19:07 CST 2013 by quanlong.
import sys
import os
import subprocess
@cybertk
cybertk / heroku_remove_apps.rb
Created Jul 25, 2014
Remove multiple apps against regex pattern
View heroku_remove_apps.rb
#!/usr/bin/ruby
require 'optparse'
def RemoveHerokuAppsWithPattern(pattern, confirm)
apps = []
# Find apps to remove
`heroku apps`.lines do |line|
_, app = line.match(/(#{pattern}.*)/).to_a
@cybertk
cybertk / md_github_issue_link.py
Last active Aug 29, 2015
Render github issue with link
View md_github_issue_link.py
@cybertk
cybertk / unzip.rb
Last active Aug 29, 2015
Unzip and handle filename encoding correctly
View unzip.rb
#!/usr/bin/ruby
# Download from https://gist.github.com/cybertk/ff72d68e592966b11c23#file-unzip-rb
require 'optparse'
require 'zip'
require 'rchardet'
def GuessEncoding(zipfile_name)
enc = {}
@cybertk
cybertk / rake-apns.rb
Last active Aug 29, 2015
Rake tasks for APNs
View rake-apns.rb
namespace :apns do
task :verify do
openssl s_client -connect gateway.sandbox.push.apple.com:2195 -cert server_certificates_bundle_sandbox.pem -key server_certificates_bundle_sandbox.pem
end
task :p12topem do
openssl pkcs12 -in apns.p12 -out apns.pem -nodes -clcerts
end
end