Skip to content

Instantly share code, notes, and snippets.

@kzim44
kzim44 / Iso8601.java
Created May 6, 2014 17:29
Class to parse ISO8601 dates for Android apps.
/**
* Helper class for handling ISO 8601 strings of the following format:
* "2008-03-01T13:00:00+01:00". It also supports parsing the "Z" timezone.
*/
public final class Iso8601 {
/** Transform Calendar to ISO 8601 string. */
public static String fromCalendar(final Calendar calendar) {
Date date = calendar.getTime();
String formatted = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ")
.format(date);
@kzim44
kzim44 / android-world-readable-file.java
Created April 11, 2014 05:00
Android - create world readable file in app private file directory. Useful for capturing images with the stock camera app.
//Remove if exists, the file MUST be created using the lines below
File f = new File(getFilesDir(), "Captured.jpg");
f.delete();
//Create new file
FileOutputStream fos = openFileOutput("Captured.jpg", Context.MODE_WORLD_WRITEABLE);
fos.close();
//Get reference to the file
File f = new File(getFilesDir(), "Captured.jpg");
@kzim44
kzim44 / git-list-conflict-files
Created August 27, 2013 06:04
Git - commandline to list file names with conflicts
git diff --name-only --diff-filter=U
// Simulate abstract method
-(CGFloat)abstractFoo {
[self doesNotRecognizeSelector:_cmd];
return 0.0f;
}
@kzim44
kzim44 / http_image_upload.py
Created August 12, 2013 20:49
Post image to rest service with python and urllib2
import urllib2, os
image_path = "png\\01.png"
url = 'http://xx.oo.com/webserviceapi/postfile/'
length = os.path.getsize(image_path)
png_data = open(image_path, "rb")
request = urllib2.Request(url, data=png_data)
request.add_header('Cache-Control', 'no-cache')
request.add_header('Content-Length', '%d' % length)
request.add_header('Content-Type', 'image/png')
res = urllib2.urlopen(request).read().strip()
@kzim44
kzim44 / LoadResForiOSVersion.m
Created July 30, 2013 17:27
Loading app resources for specific versions of iOS
if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) {
// Load resources for iOS 6.1 or earlier
} else {
// Load resources for iOS 7 or later
}
@kzim44
kzim44 / editExistingPdf.py
Created February 24, 2013 07:29
Edit an existing PDF using Python
from pyPdf import PdfFileWriter, PdfFileReader
import StringIO
from reportlab.pdfgen import canvas
from reportlab.lib.pagesizes import letter
packet = StringIO.StringIO()
# create a new PDF with Reportlab
can = canvas.Canvas(packet, pagesize=letter)
can.drawString(100,100, "Hello world")
can.save()