Skip to content

Instantly share code, notes, and snippets.

View romaonthego's full-sized avatar

Roman Efimov romaonthego

View GitHub Profile
@romaonthego
romaonthego / genpassword
Created February 11, 2011 23:03
Bash script: genpassword
#!/bin/bash
charspool=('a' 'b' 'c' 'd' 'e' 'f' 'g' 'h' 'i' 'j' 'k' 'l' 'm' 'n' 'o' 'p'
'q' 'r' 's' 't' 'u' 'v' 'w' 'x' 'y' 'z' '0' '1' '2' '3' '4' '5' '6' '7'
'8' '9' '0' 'A' 'B' 'C' 'D' 'E' 'F' 'G' 'H' 'I' 'J' 'K' 'L' 'M' 'N' 'O'
'P' 'Q' 'R' 'S' 'T' 'U' 'V' 'W' 'X' 'Y' 'Z' '-' '_');
len=${#charspool[*]}
if [ $# -lt 1 ]; then
@romaonthego
romaonthego / gist:823233
Created February 11, 2011 23:06
Remove .DS_Store (Mac OS X)
sudo find /WebServers -name ".DS_Store" -depth -exec rm {} \;
@romaonthego
romaonthego / gist:859697
Created March 8, 2011 01:53
Local IP on Debian/Ubuntu
ifconfig|grep 'inet addr'|awk '{print $2}'|sed 's/addr://g'
@romaonthego
romaonthego / NSDateFormatter cheat sheet
Last active July 19, 2024 10:39
Date Formats for NSDateFormatter
a: AM/PM
A: 0~86399999 (Millisecond of Day)
c/cc: 1~7 (Day of Week)
ccc: Sun/Mon/Tue/Wed/Thu/Fri/Sat
cccc: Sunday/Monday/Tuesday/Wednesday/Thursday/Friday/Saturday
d: 1~31 (0 padded Day of Month)
D: 1~366 (0 padded Day of Year)
@romaonthego
romaonthego / htmltest.m
Created September 23, 2013 16:08
UITextView with HTML text (iOS 7)
- (void)viewDidLoad
{
[super viewDidLoad];
UITextView *textView = [[UITextView alloc] init];
textView.translatesAutoresizingMaskIntoConstraints = NO;
[self.view addSubview:textView];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-[textView]-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(textView)]];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-[textView]-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(textView)]];
NSString *htmlString = @"<h1>Header</h1><h2>Subheader</h2><p>Some <em>text</em></p><img src='http://blogs.babble.com/famecrawler/files/2010/11/mickey_mouse-1097.jpg' width=70 height=100 />";
typedef enum _UIBackgroundStyle {
UIBackgroundStyleDefault,
UIBackgroundStyleTransparent,
UIBackgroundStyleLightBlur,
UIBackgroundStyleDarkBlur,
UIBackgroundStyleDarkTranslucent
} UIBackgroundStyle;
@interface UIApplication (UIBackgroundStyle)
-(void)_setBackgroundStyle:(UIBackgroundStyle)style;

MTLModel+MTLNSUbiquitousKeyValueStore

Motivation

To create a method to persist and re-instantiate Mantle MTLModel objects to NSUbiquitousKeyValueStore (iCloud key-value store).

Background

NSUbiquitousKeyValueStore can only store values of class NSNumber, NSString, NSDate, NSData, NSArray, and NSDictionary ("plist types"). The MTLNSUbiquitousKeyValueStore category on MTLModel has been designed to create an NSDictionary representation of a model object in a deeply recursive way, making it suitable for storage in an NSUbiquitousKeyValueStore.

class AccountStore {
// Doesn't work yet
class var sharedStore = ACAccountStore()
// This works although I'm unsure of the optional
class func sharedStore() -> ACAccountStore {
var store: ACAccountStore? = nil
var token: dispatch_once_t = 0
dispatch_once(&token, {
// Playground - noun: a place where people can play
import Foundation
enum Result<ValueType, ErrorType> : LogicValue {
case Value(ValueType)
case Error(ErrorType)
var successful : Bool {
get {
self.errorView = {
let view = UIView()
view.backgroundColor = UIColor.redColor()
view.addSubview({
self.errorLabel = {
let label = UILabel()
label.textAlignment = .Center
label.backgroundColor = UIColor.clearColor()
return label
}()