Skip to content

Instantly share code, notes, and snippets.

View keybase.md

Keybase proof

I hereby claim:

  • I am ndurell on github.
  • I am ndurell (https://keybase.io/ndurell) on keybase.
  • I have a public key ASD0kOZ-goL-15d8OGtpW-7l2DFasfT6Zbm_yIgd9T4NrQo

To claim this, I am signing this object:

@ndurell
ndurell / github.swift
Created Nov 27, 2018
point free caching github api example
View github.swift
let cachingGitHub = CachingGitHub()
struct GitHub {
var latestRepos: () -> [Repo] = { return cachingGitHub.latestRepos }
var fetchRepos: (@escaping (Result<[Repo], APIError>) -> Void) -> Void = cachingGitHub.fetchRepos
}
class CachingGitHub {
var latestRepos = [Repo]()
func fetchRepos(completion: @escaping (Result<[Repo], APIError>) -> Void) {
@ndurell
ndurell / example.swift
Created Aug 25, 2017
Weak self example
View example.swift
create(image: image) { [weak self] key, error in
guard let `self` = self else {
return
}
if let error = error {
self.completion?(nil, error)
self.completion = nil
return
}
@ndurell
ndurell / stuff.swift
Created Apr 26, 2017
Instructions for reading a file from the bundle
View stuff.swift
let path : URL = Bundle.main.path(forResource: "scifi-novels", ofType: "json").flatMap {
URL.init(fileURLWithPath: $0)
}!
let data = try! Data(contentsOf: path)
let json = try! JSONSerialization.jsonObject(with: data) as? [String: Any]
@ndurell
ndurell / FLP.md
Last active May 23, 2016
Gist detail how we use Fused Location Provid
View FLP.md

Build google api client:

m_googleApiClient = builder.
        .addConnectionCallbacks(this)
        .addOnConnectionFailedListener(this)
        .addApi(LocationServices.API)
        .build();

The location request looks like this:

@ndurell
ndurell / MyClass.java
Last active Jan 4, 2016
This gist demonstrates how to log an action using the SessionM SDK. Actions trigger achievements which allow to you reward your users for performing actions in your app. Go to http://developer.sessionm.com for more info.
View MyClass.java
package com.sessionm.example;
import com.sessionm.api.SessionM;
public class MyClass {
public void myAwesomeMethod() {
SessionM.getInstance().logAction("demo_action");
}
}
@ndurell
ndurell / MainActivity.java
Last active Jan 4, 2016
This sample activity shows how to extend the SessionM BaseActivity conveinence class.
View MainActivity.java
package test.com.sessionm.app;
import test.com.sessionm.R;
import com.sessionm.api.BaseActivity;
//Just extend the BaseActivity class.
//This will automatically make lifecycle calls for you.
public class MainActivity extends BaseActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
@ndurell
ndurell / proguard.cfg
Last active Jan 4, 2016
This show what to add to your proguard config for SessionM.
View proguard.cfg
-dontwarn com.unity3d.player.**
-keep class com.sessionm.ui.** {*;}
@ndurell
ndurell / AndroidManifest.xml
Last active Jan 4, 2016
The sample manifest shows what to include in your manifest for a SessionM integration.
View AndroidManifest.xml
<?xml version="1.0" encoding="UTF-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sessionm.sample"
android:versionCode="1"
android:versionName="1.0.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<!-- SessionM NOTE: These permissions are required for SessionM -->
<uses-permission android:name="android.permission.INTERNET" />
@ndurell
ndurell / MyViewController.m
Last active Jan 3, 2016
This demonstrates how to instantiate and add a portal button to your a view. This uses the SMPortalButton convenience class.
View MyViewController.m
#import "SMPortalButton.h"
@implementation MyViewController
- (void)viewDidLoad
{
[super viewDidLoad];
SMPortalButton *portalButton=[SMPortalButton buttonWithType:UIButtonTypeSystem];
[portalButton.button setTitle:@"Portal Button" forState:UIControlStateNormal];
portalButton.frame = CGRectMake(40, 40, 100, 30);