Skip to content

Instantly share code, notes, and snippets.

View luxinyan's full-sized avatar

Lu Xinyan luxinyan

View GitHub Profile
@luxinyan
luxinyan / get_pic.py
Created April 22, 2014 15:21
This is a simple web crawler to get image from jandan.net
import re
import urllib2
import urllib
import sys
import time
#get html of page
def getHtml(url):
page = urllib2.urlopen(url)
html = page.read()
@luxinyan
luxinyan / generate_pdf_by_reportlab.py
Created April 23, 2014 03:54
python generate pdf with reportlab.
'''
This is a simple code for generate pdf with reportlab.
More information:http://www.reportlab.com/software/opensource/rl-toolkit/faq/
'''
from reportlab.pdfgen import canvas
from reportlab.lib.units import cm
my_pdf = canvas.Canvas("hello.pdf")
my_pdf.drawString(9*cm, 22*cm, "Hello World!")
my_pdf.showPage()
my_pdf.save()
@luxinyan
luxinyan / reportlab_barcode.py
Created April 23, 2014 07:14
Generate barcode with reportlab.
from reportlab.pdfgen import canvas
from reportlab.lib.pagesizes import A4
from reportlab.lib.units import mm
#I"ll be generating code39 barcodes, others are available
from reportlab.graphics.barcode import code39
# generate a canvas (A4 in this case, size doesn"t really matter)
c=canvas.Canvas("barcode_example.pdf",pagesize=A4)
# create a barcode object
# (is not displayed yet)
#!/usr/bin/env python
# -*- coding:utf-8 -*-
#author:rikugun
import sys
import urllib
import os
from shutil import copyfile
@luxinyan
luxinyan / Increase_Build_Number.sh
Last active August 29, 2015 14:04
Xcode Increase Build Number
buildNumber=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "${PROJECT_DIR}/${INFOPLIST_FILE}")
buildNumber=$(($buildNumber + 1))
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "${PROJECT_DIR}/${INFOPLIST_FILE}"
NSString *myString = @"1233 12313";
[myString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]
@luxinyan
luxinyan / UIBezierPathDemo.m
Last active August 29, 2015 14:05
How to use UIBezierPath draw
//Begin the path
UIBezierPath *path = [[UIBezierPath alloc] init];
//Move around, add lines or arcs to the path
[path moveToPoint:CGPointMake(75, 10)];
[path addLineToPoint:CGPointMake(160, 150)];
[path addLineToPoint:CGPointMake(10, 150]);
//Close the path
[path closePath];
@luxinyan
luxinyan / Gesture.m
Last active August 29, 2015 14:05
use implement and use a gesture
- (void)setPannableView:(UIView *)pannableView // maybe this is a setter in a Controller
{
_pannableView = pannableView;
UIPanGestureRecognizer *pangr =
[[UIPanGestureRecognizer alloc] initWithTarget:pannableView action:@selector(pan:)];
[pannableView addGestureRecognizer:pangr];
}
//implement a gesture
@luxinyan
luxinyan / RNSwizzle.m
Created August 14, 2014 02:32
Method Swizzle
//
// RNSwizzle.m
// MethodSwizzle
#import "RNSwizzle.h"
#import <objc/runtime.h>
@implementation NSObject (RNSwizzle)
@luxinyan
luxinyan / build_number_equal_date
Created August 21, 2014 01:56
Let Xcode build number = date
buildNumber=$(date "+%y%m%d")
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "${PROJECT_DIR}/${INFOPLIST_FILE}"