Skip to content

Instantly share code, notes, and snippets.

View psandeepunni's full-sized avatar

Sandeep Unni psandeepunni

View GitHub Profile
package main
import (
"fmt"
"log"
"net/http"
"html/template"
"github.com/gorilla/sessions"
@psandeepunni
psandeepunni / String+Unicode.swift
Created September 19, 2016 18:39
Hack/Parse Unicode Chars in Swift String with syntax \uXXXX
import Foundation
extension String {
func replaceUnicodeChars () -> String {
if self.rangeOfString("\\u") != nil {
let pattern = "u([A-F0-9]{4})"
do {
let regex = try NSRegularExpression(pattern: pattern, options: .DotMatchesLineSeparators)
let tmp = self as NSString
var results = [String]()
@psandeepunni
psandeepunni / DeviceUID.m
Created January 14, 2016 18:44 — forked from miguelcma/DeviceUID.m
iOS Unique Device ID that persists between app reinstalls
/* DeviceUID.h
#import <Foundation/Foundation.h>
@interface DeviceUID : NSObject
+ (NSString *)uid;
@end
*/
// Device.m
@psandeepunni
psandeepunni / gist:d49b397e7e5cfcaa4fa2
Created October 15, 2015 14:16 — forked from krzysztofzablocki/gist:4396302
Set symbol breakpoint on objc_msgSend then setup this debug command to log all methods called in iOS Simulator. If you want to do device debugging change esp+4 register to r0, esp+8 to r1 Found long ago somewhere on stackoverflow.
expr -- (void)printf("[%s, %s]\n",(char *) object_getClassName(*(long*)($esp+4)), (char *) *(long *)($esp+8) )
@psandeepunni
psandeepunni / mongoose-inmemory-cache.js
Last active March 18, 2018 07:50
Mongoose Query Cache (in-memory)
'use strict';
/**
* This mongoose query caching is a shameless copy of mongoose-memcached (https://github.com/benjibc/mongoose-memcached) module
* But instead of relying upon using memcached db, this uses an in memory cache provided by memory-cache (https://github.com/ptarjan/node-cache)
* Thank you Paul Tarjan (ptarjan) and Yufei (Benny) Chen (benjibc). You've made our lives easier
*/
/*
*Module dependencies.
*/
@psandeepunni
psandeepunni / flatten.js
Last active November 18, 2021 22:08
Javascript function to flatten a nested Associative Array (tree) to a List
var bfs = function(tree, key, collection) {
if (!tree[key] || tree[key].length === 0) return;
for (var i=0; i < tree[key].length; i++) {
var child = tree[key][i]
collection[child.id] = child;
bfs(child, key, collection);
}
return;
}