Skip to content

Instantly share code, notes, and snippets.

- (NSString *)randomString {
NSString *alphabet = @"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXZY0123456789";
u_int32_t len = arc4random_uniform(20) + 5;
NSMutableString *s = [NSMutableString stringWithCapacity:len];
for (NSUInteger i = 0U; i < len; i++) {
u_int32_t r = arc4random() % [alphabet length];
unichar c = [alphabet characterAtIndex:r];
[s appendFormat:@"%C", c];
}
return s;
// related to SO question:
// http://stackoverflow.com/questions/26252432/how-do-i-set-a-auto-increment-key-in-realm/26257616#26257616
// keywords: realm auto increment id primary key autoincrement
//
// two assumptions:
// 1) time always goes forward
// 2) realm and app has shared lifetime:
// no external realms are imported, if app deleted realm is deleted
@interface TSUUID : NSObject
@property (nonatomic) double baseOffset;
class Date
def quarter
case self.month
when 1,2,3
return 1
when 4,5,6
return 2
when 7,8,9
return 3
when 10,11,12
if [ "${CONFIGURATION}" = "Ad Hoc" ] || [ "${CONFIGURATION}" = "App Store" ]; then
buildNumber=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "${INFOPLIST_FILE}")
buildNumber=$((buildNumber + 1))
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "${INFOPLIST_FILE}"
./Pods/Fabric/Fabric.framework/run key key
fi
@rbaulin
rbaulin / AppDelegate.m
Last active August 29, 2015 14:20
AppDelegate without Storyboards snippet
<#ViewController#> *vc = [[<#ViewController#> alloc] init];
UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:vc];
UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
window.rootViewController = nc;
[window makeKeyAndVisible];
self.window = window;
@rbaulin
rbaulin / dynamic_realm.m
Last active August 29, 2015 14:21
Realm dynamic API usage example
#import <Realm.h>
// extracted from RLMRealm_Dynamic.h
@interface RLMProperty (AGDynamic)
- (instancetype)initWithName:(NSString *)name
type:(RLMPropertyType)type
objectClassName:(NSString *)objectClassName
indexed:(BOOL)indexed;
@end
var path = require('path');
var express = require('express');
var app = express();
var openConnections = [];
global.emitEvent = function () {
console.log("emit to clients " + openConnections.length);
openConnections.forEach(function(res) {
res.write('data: event' + "\n\n");
// unity pc and mobile input
// http://docs.unity3d.com/ScriptReference/Input.GetMouseButtonDown.html
// http://docs.unity3d.com/Manual/MobileInput.html
void Update() {
if (SystemInfo.deviceType == DeviceType.Desktop) {
if (Input.GetMouseButtonDown(0)) {// 0 - left click, 1 - right click, 2 - middle click
// click
}
# open terminal here service
# works in OSX El Capitan
# to install create new Automator Service with Run Shell script below
# original script http://protips.maxmasnick.com/cdff-cd-to-the-path-of-the-front-most-finder-window
function ff { osascript -e 'tell application "Finder"'\
-e "if (${1-1} <= (count Finder windows)) then"\
-e "get POSIX path of (target of window ${1-1} as alias)"\
-e 'else' -e 'get POSIX path of (desktop as alias)'\
-e 'end if' -e 'end tell'; };\
@rbaulin
rbaulin / rand-nsstring.m
Last active June 6, 2016 17:54
random NSString in objective-c
NSString *rand_str() {
NSString *alphabet = @"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXZY0123456789";
u_int32_t len = arc4random_uniform(20) + 5;
NSMutableString *s = [NSMutableString stringWithCapacity:len];
for (NSUInteger i = 0U; i < len; i++) {
u_int32_t r = arc4random() % [alphabet length];
unichar c = [alphabet characterAtIndex:r];
[s appendFormat:@"%C", c];
}
return s;