Skip to content

Instantly share code, notes, and snippets.

@deltheil
deltheil / bubble.rb
Created October 27, 2010 12:43
Speech bubble PNG icon generator - mimicks the Facebook for iPhone comments toolbar button
require 'rubygems'
require 'Rmagick'
include Magick
# In pixels
SQUARE_SIZE = 20
CORNER = 2
SPIKE_OFFSET, SPIKE_WIDTH, SPIKE_HEIGHT = 7, 4, 6
@deltheil
deltheil / MSImageView.m
Created June 16, 2011 20:19
Three20 TTImageView always checks the in-memory cache *without* using any expiration age - this version solves this problem
#import "MSImageView.h"
#import <Three20Network/TTURLCache.h>
#import <Three20Network/TTURLImageResponse.h>
#import <Three20Network/TTURLRequest.h>
#import "MSGlobals.h"
@implementation MSImageView
@deltheil
deltheil / gist:1555692
Last active September 29, 2015 05:48
Print out the width x height of a given image via ImageMagick identify
# ImageMagick `identify` format features is handy
# e.g. to obtain the width x height of a given image (360x480)
#
# See http://www.imagemagick.org/script/escape.php
# for a complete list of supported format characters
identify -format "%wx%h" myimage.jpg
@deltheil
deltheil / gist:1601327
Created January 12, 2012 16:05
GCC - list all the macros defined during the execution of the preprocessor
# -E is for preprocessor only
# -dM tells GCC to generate a list of #define directives
# e.g.
# #define __APPLE__ 1
# #define __SSE2__ 1
# #define __GNUC__ 4
# ...
gcc -E -dM - < /dev/null
@deltheil
deltheil / platform.h
Created January 12, 2012 17:53
Preprocessor: detect mobile platform (iOS vs Android)
/**
* NOTES:
* - iOS: the useful macros are defined within TargetConditionals.h
* - Android:
* - with Android.mk file(s) and the 'ndk-build' script (aka vanilla way),
* ANDROID is predefined (see -DANDROID extra C flag),
* - with the Android Standalone Toolchain __ANDROID__ is predefined instead
*/
#if defined(__APPLE__)
#include <TargetConditionals.h>
@deltheil
deltheil / pname.c
Created April 3, 2012 10:59
Android Native API (JNI): get the device name
#include <stdio.h>
#include <string.h>
#include <sys/system_properties.h>
/* Get device name
--
1/ Compile with the Android NDK Toolchain:
arm-linux-androideabi-gcc -static pname.c -o pname
2/ Transfer on device:
@deltheil
deltheil / systemversion.c
Created April 6, 2012 17:09
iOS: get device OS version from C code via the Objective-C Runtime
#include <objc/runtime.h>
#include <objc/message.h>
#include <CoreFoundation/CoreFoundation.h>
/* ... */
/**
* Return a character string that holds the current version
* of the operating system which is equivalent to:
@deltheil
deltheil / gist:2644728
Created May 9, 2012 14:08
Use nslookup to check an MX record
$ nslookup
> set q=MX
> github.com
Server: 212.27.40.240
Address: 212.27.40.240#53
Non-authoritative answer:
github.com mail exchanger = 10 ALT1.ASPMX.L.GOOGLE.com.
...
@deltheil
deltheil / nginx.conf
Created June 4, 2012 07:57
Hide sensitive GET parameters within nginx access logs thanks to the Lua module
http {
log_format filt '$remote_addr - $remote_user [$time_local] "$_request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
server {
location /login {
# `set` is provided by the Rewrite module
set $filter "password|secret";
@deltheil
deltheil / gist:2868896
Created June 4, 2012 15:04
Create a file of given size with random data
# `head -c bytes`
# e.g. for a 1kb file:
cat /dev/random | head -c 1024 > data.bin