Skip to content

Instantly share code, notes, and snippets.

View lincank's full-sized avatar
🎯
Focusing

lincank

🎯
Focusing
View GitHub Profile
@lincank
lincank / batch_rename.py
Created July 9, 2012 09:38
Give unique names for each picture
import os, sys, pprint, re, shutil, random
log_file = "/tmp/batch-rename.log"
f = open(log_file, 'w')
regx = re.compile("\\.jpg|\\.png|\\.gif", re.IGNORECASE)
def subdirs(path):
"""
@lincank
lincank / truncate.py
Created July 9, 2012 09:43
make all files such as "dsf_kkk.jpg" into "kkk.jpg" in a specific folder
import os, re, sys
def sub_string(string, sub_str):
"""
Arguments:
- `string`: string you want to be truncated
- `sub_str`: starting sub-string (exclusive)
"""
index = string.rfind(sub_str)
@lincank
lincank / mountain-lion-brew-setup.markdown
Created July 27, 2012 05:59 — forked from myobie/mountain-lion-brew-setup.markdown
Get Mountain Lion and Homebrew to Be Happy

Get Mountain Lion and Homebrew to Be Happy

1) Install XCode 4.4 into /Applications

Get it from http://developer.apple.com. You will not be able to submit apps to any stores using this XCode version, so turn away if that is something you might want to do.

2) Install Command Line Tools

In XCode's Preferences > Downloads you can install command line tools.

@lincank
lincank / pdfform.py
Created September 11, 2012 06:38
collect fillable form data from all pdf files in the input directory, and generate a "output.csv" file in the input directory
"""
collect fillable form data from all pdf files in the input directory,
and generate a "output.csv" file in the input directory
Dependency: pdfminer
Install: pip install pdfminer
Usage:
@lincank
lincank / get_ip.sh
Created October 6, 2012 06:26
Get Your Router IP and your public IP with shell
# get internal ip of the router
netstat -rn | grep UG
# get your public ip
wget -q -O - checkip.dyndns.org | grep -Eo "([0-9\.]+)"
#get filesize using the command
curl -sI $url | grep Content-Length | cut -d ' ' -f 2
@lincank
lincank / mergeXlsx.R
Created October 7, 2012 06:11
R with xlsx
# inputPath: an absolute path to the directory that contains xlsx files, like "C:/download"
# outputPath: absolute path for the output file
mergeXlsx <- function(inputPath, outputPath)
{
# load xlsx package to read/write xlsx files
library(xlsx)
# get all files end with ".xlsx" in the given path and save them in fileList
fileList <- list.files(inputPath, pattern=".xlsx")
if (length(fileList) < 2 ){
@lincank
lincank / self_signed_cert.rb
Created October 9, 2012 07:30 — forked from nickyp/self_signed_cert.rb
create a self-signed certificate using ruby-openssl
require 'rubygems'
require 'openssl'
key = OpenSSL::PKey::RSA.new(1024)
public_key = key.public_key
# uncomment the following line if you when to save key to somewhere
# open '/tmp/key.pem', 'w' do |io| io.write key.to_pem end
# puts 'save to /tmp/key.pem'
@lincank
lincank / format.sh
Created October 15, 2012 07:11
Format a volume via terminal on Mac
# find out which partition to format
diskutil list
# format disk1s1 to FAT32 file system with label "ADATA"
diskutil eraseVolume "FAT32" ADATA disk1s1
@lincank
lincank / date_avr.py
Created October 23, 2012 15:51
calculate average date difference in xls file with python
import datetime
import xlrd
# change the input path and output path
input_path = "/tmp/date.xls"
terminated_path = "/tmp/terminated.xlsx"
output_path = "/tmp/output.csv"
terminated_str = "terminate after IC"
#Steps to install RVM + Ruby 1.9.3 + Rails + nginx + Passenger on CentOS (tested on v5.5)
# Todo get up to date repo's
# Install git and curl, if not already installed
sudo yum install git
sudo yum install curl-devel
# Create the rvm group and add any users who will be using rvm to the group
sudo su -