Skip to content

Instantly share code, notes, and snippets.

View Harinder's full-sized avatar

Harinder Harinder

  • iHSApps
  • United States
View GitHub Profile
@Harinder
Harinder / EventEmitter.swift
Created January 7, 2019 05:55 — forked from brennanMKE/EventEmitter.swift
React Native Event Emitter for RCTEventEmitter in Objective-C and Swift
class EventEmitter
/// Shared Instance.
public static var sharedInstance = EventEmitter()
// ReactNativeEventEmitter is instantiated by React Native with the bridge.
private static var eventEmitter: ReactNativeEventEmitter!
private init() {}
@Harinder
Harinder / iterm2.md
Created December 28, 2018 20:06 — forked from squarism/iterm2.md
iterm2 cheatsheet

Tabs and Windows

Function Shortcut
New Tab + T
Close Tab or Window + W (same as many mac apps)
Go to Tab + Number Key (ie: ⌘2 is 2nd tab)
Go to Split Pane by Direction + Option + Arrow Key
Cycle iTerm Windows + backtick (true of all mac apps and works with desktops/mission control)
@Harinder
Harinder / States-v3.md
Created August 2, 2016 03:55 — forked from andymatuschak/States-v3.md
A composable pattern for pure state machines with effects (draft v3)

A composable pattern for pure state machines with effects

State machines are everywhere in interactive systems, but they're rarely defined clearly and explicitly. Given some big blob of code including implicit state machines, which transitions are possible and under what conditions? What effects take place on what transitions?

There are existing design patterns for state machines, but all the patterns I've seen complect side effects with the structure of the state machine itself. Instances of these patterns are difficult to test without mocking, and they end up with more dependencies. Worse, the classic patterns compose poorly: hierarchical state machines are typically not straightforward extensions. The functional programming world has solutions, but they don't transpose neatly enough to be broadly usable in mainstream languages.

Here I present a composable pattern for pure state machiness with effects,

@Harinder
Harinder / variadicFuncArgs.swift
Created September 28, 2014 09:19
Variadic function arguments
func sumOf(numbers: Int...) -> Int {
var sum = 0
for number in numbers {
sum += number
}
return sum
}
sumOf()
sumOf(42, 597, 12)”
@Harinder
Harinder / NSManagedObjectContext_saveToPersistentStore.swift
Created September 28, 2014 07:10
Save context and propagate changes to any parent contexts
import CoreData
extension NSManagedObjectContext {
/// Commit unsaved changes and propagate them to ancestor contexts, if any.
///
/// :param: error A pointer to an NSError object returned on failure
/// :returns: true if the operation succeeds, false otherwise
@objc(kdj_saveToPersistentStore:)
public func saveToPersistentStore(error: NSErrorPointer) -> Bool {
if !self.save(error) {
@Harinder
Harinder / dateUtility
Created September 28, 2014 07:09
Calculate dates one year in the past or one year in the future
import Foundation
/// Return date that is exactly one year earlier than specified date
///
/// :param: date NSDate
/// :returns: NSDate that is one year before date
func oneYearBeforeDate(date: NSDate) -> NSDate {
let offsetComponents = NSDateComponents()
offsetComponents.year = -1
@Harinder
Harinder / setDefaultListSelector.java
Created September 28, 2014 07:07
Android: Programmatically set the listSelector for a ListView to the default for the current theme
private static void setDefaultListSelector(ListView listView, Context context) {
TypedArray typedArray = context.obtainStyledAttributes(null, new int[]{android.R.attr.listSelector}, android.R.attr.listViewStyle, 0);
Drawable drawable = typedArray.getDrawable(0);
listView.setSelector(drawable);
}
@Harinder
Harinder / NSData+AESCrypt.h
Created September 26, 2011 20:07 — forked from gonecoding/Readme.markdown
Adding methods to NSData and NSString using categories to provide AES256 encryption on iOS
//
// NSData+AESCrypt.h
//
// AES Encrypt/Decrypt
// Created by Jim Dovey and 'Jean'
// See http://iphonedevelopment.blogspot.com/2009/02/strong-encryption-for-cocoa-cocoa-touch.html
//
// BASE64 Encoding/Decoding
// Copyright (c) 2001 Kyle Hammond. All rights reserved.
// Original development by Dave Winer.