Skip to content

Instantly share code, notes, and snippets.

@ghawkgu
ghawkgu / smtp.py
Created April 26, 2011 13:58
Python smtp sample
#!/usr/bin/env python
import smtplib
mail_server = 'smtp.example.com'
mail_server_port = 465
from_addr = 'foo@example.com'
to_addr = 'bar@exmaple.com'
@ghawkgu
ghawkgu / ssh_client.py
Created April 27, 2011 10:18
Python ssh client sample
#!/usr/bin/env python
import paramiko
hostname = 'localhost'
port = 22
username = 'foo'
password = 'xxxYYYxxx'
if __name__ == "__main__":
@ghawkgu
ghawkgu / boto_s3_sample.py
Created May 31, 2011 10:13
Writing into s3 with boto.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from boto.s3.connection import S3Connection
from boto.s3.key import Key
conn = S3Connection('access key', 'access secret')
bucket = conn.get_bucket('some-bucket')
# Write into 'mysql/test.txt'
@ghawkgu
ghawkgu / buildquerystring.m
Created July 22, 2011 04:01 — forked from chrishulbert/buildquerystring.m
Build a url query string in obj-c from a dictionary of params like jquery does
+(NSString*)urlEscape:(NSString *)unencodedString {
NSString *s = (NSString *)CFURLCreateStringByAddingPercentEscapes(NULL,
(CFStringRef)unencodedString,
NULL,
(CFStringRef)@"!*'\"();:@&=+$,/?%#[]% ",
kCFStringEncodingUTF8);
return [s autorelease]; // Due to the 'create rule' we own the above and must autorelease it
}
// Put a query string onto the end of a url
@ghawkgu
ghawkgu / private.xml
Created March 30, 2012 03:54
Customized mapping rules for keyRemap4MacBook to switch input source by one touch
<?xml version="1.0"?>
<root>
<item>
<name>Switch Input Source</name>
<appendix>Use the right Option key to select the next input source</appendix>
<identifier>private.switch_input_source_with_right_option</identifier>
<autogen>--KeyToKey-- KeyCode::OPTION_R, KeyCode::SPACE, ModifierFlag::OPTION_L | ModifierFlag::COMMAND_L</autogen>
</item>
<item>
@ghawkgu
ghawkgu / auto_increase_build_number.sh
Created March 31, 2012 07:20
Increase build number of an Xcode project for each build.
#! /bin/bash
# Increase build number for each build.
# Use "Run Script" to append this script into a project's scheme.
buildNumber=$(/usr/libexec/PlistBuddy -c "print CFBundleVersion" ${PROJECT_DIR}/${PROJECT_NAME}/${PROJECT_NAME}-Info.plist)
buildNumber=$(($buildNumber + 1))
/usr/libexec/PlistBuddy -c "set :CFBundleVersion $buildNumber" ${PROJECT_DIR}/${PROJECT_NAME}/${PROJECT_NAME}-Info.plist
@ghawkgu
ghawkgu / .tmux.conf
Last active July 29, 2019 03:24
tmux settings
#utf setting
# set-window-option -g utf8 on "Deprecated since 2.2"
set-window-option -g mode-keys vi
# set-window-option -g automatic-rename off
setw -g automatic-rename off
set -s escape-time 0
setw -g window-status-current-style underscore
# Since tmux 1.8, we can use copy-pipe to utilize the system-wide clipboard.
git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --"
def wpautop(pee, br = true)
return '' if pee.strip == ''
pee = "#{pee}\n" # just to make things a little easier, pad the end
pee = pee.gsub(/<br \/>\s*<br \/>/, "\n\n")
# pace things out a little
allblocks = '(?:table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|option|form|map|area|blockquote|address|math|style|input|p|h[1-6]|hr|fieldset|legend|section|article|aside|hgroup|header|footer|nav|figure|figcaption|details|menu|summary)';
pee = pee.gsub(Regexp.new('(<'+allblocks+'[^>]*>)'), "\n"+'\1')
pee = pee.gsub(Regexp.new('(<\/'+allblocks+'[^>]*>)'), '\1' + "\n\n")
pee = pee.gsub(/\r\n|\r/, "\n") # cross-platform newlines
if pee.include?('<object')
@ghawkgu
ghawkgu / gist:4621586
Last active April 5, 2018 20:25
Intercept the request of uiwebview, add customized header in the request. For detailed info, read http://www.nomadplanet.fr/2010/09/custom-http-headers-for-every-request-made-in-uiwebviews/ .
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)aRequest navigationType:(UIWebViewNavigationType)navigationType {
NSDictionary *headers = [aRequest allHTTPHeaderFields];
BOOL hasWhateverAddedHeader = NO;
for(NSString *key in [headers allKeys]) {
if([[key lowercaseString] isEqualToString:@"my-added-header"]) {
hasWhateverAddedHeader = YES;
break;
}
}