Skip to content

Instantly share code, notes, and snippets.

@sungitly
sungitly / android_resize_bitmap.java
Last active August 29, 2015 13:57
Resize bitmap in Android
Bitmap origBitmapOrig = BitmapFactory.decodeFile(imageFilePath);
//Resize the image
double width = origBitmapOrig.getWidth();
double height = origBitmapOrig.getHeight();
int newWidth = 1600
int newHeight = (int)((newWidth/width)*height);
Bitmap newBitmap = Bitmap.createScaledBitmap(origBitmapOrig, newWidth, newHeight, true);
@sungitly
sungitly / git.bash
Created March 20, 2014 02:04
Useful Git Command
git config --global credential.helper store
@sungitly
sungitly / email.php
Created March 20, 2014 02:07
Send Email Through SMTP (SSL) Using Zend
<?php
use Zend\Mail\Transport\Smtp as SmtpTransport;
use Zend\Mail\Transport\SmtpOptions;
use Zend\Mail\Message;
public function sendEmail($to, $subject, $body){
$message = new Message();
$message->addTo($to)
->addFrom('helpdesk@example.com')
@sungitly
sungitly / android_tips.md
Created March 21, 2014 12:41
Android Tips

px = dp * (dpi / 160)

@sungitly
sungitly / sign_android.sh
Created April 1, 2014 09:27
Android Signning
// Generate a private key
keytool -genkey -v -keystore my-release-key.keystore -alias alias_name -keyalg RSA -keysize 2048 -validity 10000
// View generated key store
keytool -list -v -keystore release.keystore
// Sign the application
jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore my-release-key.keystore my_application.apk alias_name
@sungitly
sungitly / jsonencoder.py
Created January 26, 2015 16:00
python json encoder to encode object json with exclusions
class ComplexEncoder(json.JSONEncoder):
def __init__(self, skipkeys=False, ensure_ascii=True,
check_circular=True, allow_nan=True, sort_keys=False,
indent=None, separators=None, encoding='utf-8', default=None, excluded=None):
super(ComplexEncoder, self).__init__(skipkeys, ensure_ascii, check_circular, allow_nan, sort_keys, indent,
separators, encoding, default)
self.excluded = excluded
def default(self, obj):
if hasattr(obj, "__dict__"):
@sungitly
sungitly / datetime_string2unix.py
Created March 5, 2015 05:00
Convert String Datetime To Unix Time
DATE_FORMATTER = '%Y-%m-%d %H:%M:%S'
def unix_time(dt):
epoch = datetime.utcfromtimestamp(0)
delta = dt - epoch
return delta.total_seconds()
def unix_time_millis(dt):
return unix_time(dt) * 1000.0
@sungitly
sungitly / readable_time.php
Created March 9, 2015 14:19
Convert seconds to human readable time duration
static $periods = array(
'天' => 86400,
'小时' => 3600,
'分钟' => 60,
'秒' => 1
);
public function friendlyTime($timestamp)
{
$timeStr = '';
@sungitly
sungitly / datezhcn.py
Created March 20, 2015 13:23
Python 中文日期 格式化
# -*- coding: utf-8 -*-
date.today().strftime(u'%Y年%m月%d日'.encode('utf-8')).decode('utf-8')
#输出:2012年11月27日
@sungitly
sungitly / restartfinder.sh
Created March 26, 2015 14:02
Shell Script To Restart Finder
#!/bin/bash
kill -sighup `ps -e | grep Finder.app | grep -v grep | cut -c1-6`