Skip to content

Instantly share code, notes, and snippets.

View keith-kurak's full-sized avatar

Keith Kurak keith-kurak

View GitHub Profile
#########################
# This gist is meant to be used to install everything needed to get up and running with the Ionic Framework on Windows using Chocolatey (http://chocolatey.org)
# Read "How to use this Gist File" section below for instructions.
#########################
#########################
# NOTE : for those familiar with Chocolatey, there are a couple of custom packages used as part of the install that are not published and are waiting on maintainers to make updates to their packages.
#########################
@keith-kurak
keith-kurak / objcsnippet.m
Created December 1, 2016 15:15
Test Objective C snippet
//start scanning when the Scan button is pushed down (touch down)
- (IBAction)startScanning:(id)sender {
if(![self.session isRunning])
{
[self.barcodeScanAreaView.layer addSublayer:_prevLayer];
[_session startRunning];
[self.barcodeScanAreaView bringSubviewToFront:_highlightView]; //isn't necessary at this point because the line gets removed before anyone sees it. Could be useful if there was a delay before shutting down the view and recording the scan
}
}
//stop scanning when the button is pushed up (inside button) (touch up inside)
@keith-kurak
keith-kurak / SignInSignOutViewController.swift
Last active July 3, 2022 07:30
Stupid Simple iOS Firebase Authentication Setup
// AppDelegate.swift --------------------------------------------------------------------------------------------
//Add this stuff to AppDelegate (in addition to whatever is already in there) to enable Firebase and the auth-specific URL handlers
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
//setup firebase
@keith-kurak
keith-kurak / SomeContainerOfThings.cs
Last active December 2, 2016 13:06
Simple match Big-O comparison
public class SomeContainerOfThings
{
List<IThing> Things {get;set;}
//old - performed at O(N^2)
IEnumerable<IThing> GetThingsAlsoIn(SomeContainerOfThings other)
{
return this.Things.Where(thisThing => other.Things.Any(otherThing => thisThing.Name == otherThing.Name));
}
@keith-kurak
keith-kurak / wraplegacycalendarpicker.jsx
Created January 2, 2017 04:26
Wrapping a legacy control in a React component
class CalendarPicker extends React.Component {
constructor() {
var randomId = CustomFramework.guid(); //get a GUID from the framework that will be the ID for the legacy calendar control
this.state = {controlId: randomId, value: null}; //we'll set value later based on legacy control events (see below)
}
render() {
//On initial render, put an empty div with a unique ID on the DOM.
//The control will be inserted inside this container.
@keith-kurak
keith-kurak / sampledata.json
Last active April 8, 2017 03:39
Sample denormalized Firebase data
{
"users" : {
"user1" : {
"posts" : {
"post1" : {
"title" : "blah",
"body" : "more blah",
"tags" : {"boring" : true, "lame" : true}
},
"post2" : {
@keith-kurak
keith-kurak / tagsthenpostsquery.swift
Created April 8, 2017 03:56
Query posts for tags
// Assumption: you have nice business objects for Posts and Tags that you build from Firebase snapshots
func posts(forTag tagKey: String, completionBlock: (([Post]) -> ()) {
let userId = FIRAuth.auth().currentUser?.uid
let ref = FIRDatabase.database().reference()
var posts = [Post]() //I can put all the posts here as I retrieve them
ref.child("users").child(userId!).child("tags").child(tagKey).observeSingleEvent(of: .value, with: {(tagSnapshot) in
let tag = Tag(fromSnapshot: tagSnapshot)
@keith-kurak
keith-kurak / dispatchgroups.swift
Created April 8, 2017 04:11
Tags then posts with dispatch groups
func posts(forTag tagKey: String, completionBlock: (([Post]) -> ()) {
let userId = FIRAuth.auth().currentUser?.uid
let ref = FIRDatabase.database().reference()
let dispatchGroup = DispatchGroup()
var posts = [Post]() //I can put all the posts here as I retrieve them
ref.child("users").child(userId!).child("tags").child(tagKey).observeSingleEvent(of: .value, with: {(tagSnapshot) in
let tag = Tag(fromSnapshot: tagSnapshot)
@keith-kurak
keith-kurak / asynclistbuilder.swift
Last active April 8, 2017 04:44
Async List Builder Monstrosity
import Foundation
typealias ReturnCompletionBlock<T> = (T?) -> ()
//yes, this is a closure with a closure as a parameter
typealias AsyncListElementFunction<T> = (ReturnCompletionBlock<T>) -> ()
class AsyncListBuilder<T> {
var elementFunctions = [AsyncListElementFunction<T>]()
@keith-kurak
keith-kurak / decoupledfirebaseexample.swift
Last active April 23, 2017 20:48
Decoupled Firebase code
//1) Have a protocol that serves as a placeholder for something that is observing updates- mainly so you can unsubscribe from updates later when you no longer need them
protocol UpdateObserving {
func unsubscribe()
}
//1a) Implement that protocol for Firebase. It needs a ref that can unsubscribe and a handle to the specific subscription