Skip to content

Instantly share code, notes, and snippets.

@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()
@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 / 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()
// Simulate abstract method
-(CGFloat)abstractFoo {
[self doesNotRecognizeSelector:_cmd];
return 0.0f;
}
@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
@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 / 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 / SimpleCursorLoader.java
Created May 11, 2014 04:23
A custom cursor loader to facilitate using a SQLite database with the Android LoaderManager framework, but without the need for a Content Provider.
import android.content.Context;
import android.database.Cursor;
import android.support.v4.content.AsyncTaskLoader;
/**
* Used to write apps that run on platforms prior to Android 3.0. When running
* on Android 3.0 or above, this implementation is still used; it does not try
* to switch to the framework's implementation. See the framework SDK
* documentation for a class overview.
*
@kzim44
kzim44 / CustomTypefaceSpan.java
Created May 12, 2014 23:19
Android: Support class to enable setting a custom type face in a spannable string.
package my.app;
import android.graphics.Paint;
import android.graphics.Typeface;
import android.text.TextPaint;
import android.text.style.TypefaceSpan;
public class CustomTypefaceSpan extends TypefaceSpan {
private final Typeface newType;
@kzim44
kzim44 / .gitignore
Last active August 29, 2015 14:03
.gitignore file for android studio
# Mac OS X clutter
*.DS_Store
# Windows clutter
Thumbs.db
# built application files
*.apk
*.ap_