Skip to content

Instantly share code, notes, and snippets.

View Gurpartap's full-sized avatar
:octocat:
Working from home

Gurpartap Singh Gurpartap

:octocat:
Working from home
View GitHub Profile
@Gurpartap
Gurpartap / gist:1130056
Created August 7, 2011 04:49
Compare iOS app version with latest version from server
<?php
$request_body = @file_get_contents('php://input');
$request_data = json_decode($request_body, true);
$bundle_version = $_GET['bundleVersion'];
$latest_version = "1.0.1";
if (version_compare($bundle_version, $latest_version, '<')) {
$result = array(
'needsUpdate' => TRUE,
'latestVersion' => $latest_version
@Gurpartap
Gurpartap / gist:1130060
Created August 7, 2011 04:56
Process the result of server side app version check
- (void)request:(ASIHTTPRequest *)request didReceiveData:(NSData *)data {
NSString *dataString = [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease];
if ([dataString length] > 0) {
self.manifest = [NSDictionary dictionaryWithDictionary:[dataString JSONValue]];
if ([[_manifest objectForKey:@"needsUpdate"] boolValue] == YES && [self remindNow] == YES) {
NSString *alertTitle = NSLocalizedString(@"Update available", nil);
if ([[_manifest allKeys] containsObject:@"alertTitle"]) {
alertTitle = [_manifest objectForKey:@"alertTitle"];
@Gurpartap
Gurpartap / gist:1141421
Created August 12, 2011 03:58
Generate unique alphanumeric incrementing string keys
var symbols = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".split('');
var max_length = symbols.length;
for (var length = 1; length <= max_length; length++) {
var scombos = combinations(symbols, length);
for (var j = 0; j < scombos.length; j++) {
var word = scombos[j];
console.log(word.join(''));
}
}
@Gurpartap
Gurpartap / gist:1423205
Created December 2, 2011 13:14 — forked from odrobnik/gist:1423199
Uploading documentation to GitHub
mkdir gh-pages
cd gh-pages
git init
git remote add origin git@github.com:Cocoanetics/DTWebArchive.git
# add and commit files
git push origin master:gh-pages
@Gurpartap
Gurpartap / gist:1495827
Created December 19, 2011 07:10
Load custom fonts in iOS
#import <dlfcn.h>
NSUInteger loadFonts() {
NSUInteger newFontCount = 0;
NSBundle *frameworkBundle = [NSBundle bundleWithIdentifier:@"com.apple.GraphicsServices"];
const char *frameworkPath = [[frameworkBundle executablePath] UTF8String];
if (frameworkPath) {
void *graphicsServices = dlopen(frameworkPath, RTLD_NOLOAD | RTLD_LAZY);
if (graphicsServices) {
BOOL (*GSFontAddFromFile)(const char *) = dlsym(graphicsServices, "GSFontAddFromFile");
@Gurpartap
Gurpartap / gist:1527659
Created December 28, 2011 11:39
Nginx (at /usr/local/nginx) init.d script from debian squeeze apt package
#!/bin/sh
### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $network $remote_fs $local_fs
# Required-Stop: $network $remote_fs $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Stop/start nginx
### END INIT INFO
@Gurpartap
Gurpartap / gist:1529497
Created December 28, 2011 20:11
Redis (at /usr/local/redis) init.d script from debian squeeze apt package
#! /bin/sh
### BEGIN INIT INFO
# Provides: redis-server
# Required-Start: $syslog $remote_fs
# Required-Stop: $syslog $remote_fs
# Should-Start: $local_fs
# Should-Stop: $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: redis-server - Persistent key-value db
@Gurpartap
Gurpartap / gist:1530397
Created December 28, 2011 23:25
Nginx God config
God.watch do |w|
w.name = "nginx"
w.interval = 30.seconds
w.start = "/etc/init.d/nginx start"
w.stop = "/etc/init.d/nginx stop"
w.restart = "/etc/init.d/nginx restart"
w.start_grace = 10.seconds
w.restart_grace = 10.seconds
w.pid_file = "/var/run/nginx.pid"
@Gurpartap
Gurpartap / gist:1530414
Created December 28, 2011 23:28
/etc/init.d/god
#!/bin/bash
#
# god Startup script for god (http://god.rubyforge.org)
#
# chkconfig: - 85 15
# description: God is an easy to configure, easy to extend monitoring \
# framework written in Ruby.
#
CONF_DIR=/usr/local/god
@Gurpartap
Gurpartap / nginx.conf
Created December 29, 2011 01:39
/usr/local/nginx/conf/nginx.conf
worker_processes 4;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {