Skip to content

Instantly share code, notes, and snippets.

View martin-cotta's full-sized avatar

Martin Cotta martin-cotta

  • San Francisco Bay Area
View GitHub Profile
@martin-cotta
martin-cotta / singleton.swift
Last active October 19, 2015 17:59
Singleton in Swift
import UIKit
final class Singleton {
static let sharedInstance = Singleton()
private init() { }
var value = ""
}
class ViewController: UIViewController {
class AppContext {
let device : UIDevice
// Delay object creation
lazy var dataService: DataService = DataService()
// Property is depended on other parts of a class, that aren’t available yet
lazy var isTablet: Bool = { [unowned self] in
self.device.userInterfaceIdiom == .Pad
@martin-cotta
martin-cotta / Activity.java
Last active March 1, 2016 05:37
Data Bound RecyclerView Adapter
public class Activity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
RecyclerView recyclerView = getRecyclerView();
List<Item> items = getItems();
recyclerView.setAdapter(new DataAdapter(items));
}
static class Adapter extends DataBoundAdapter<Item, ItemBinding> {
@martin-cotta
martin-cotta / ViewController.m
Created April 11, 2016 23:38
Hack to fix navigation bar position/height on iOS 8 after closing fullscreen video
// on a portrait only app, when a video player is launched from a WebView
// and the user turn the phone into landscape and then closes the player,
// the navigation bar slips under the status bar
@property (nonatomic, strong) id observer;
- (instancetype)init {
@weakify(self);
@martin-cotta
martin-cotta / ViewController.m
Created April 11, 2016 23:44
self reference inside a block, weakSelf and strongSelf
__weak __typeof__(self) weakSelf = self;
dispatch_group_async(_operationsGroup, _operationsQueue, ^{
__typeof__(self) strongSelf = weakSelf;
[strongSelf doSomething];
[strongSelf doSomethingElse];
});
@martin-cotta
martin-cotta / RemoveAndroid.sh
Last active July 1, 2016 18:13
How to Completely Remove Android Studio
rm -rf /Applications/Android\ Studio.app
rm -rf ~/AndroidStudioProjects
rm -rf ~/Library/Preferences/AndroidStudio*
rm -rf ~/Library/Application\ Support/AndroidStudio*
rm -rf ~/Library/Logs/AndroidStudio*
rm -rf ~/Library/Caches/AndroidStudio*
rm -rf ~/Library/Android*
rm ~/Library/Preferences/com.google.android.studio.plist
cd repo
git remote rename origin bitbucket
git remote add origin https://github.com/user/repo.git
git push -u origin master
git remote rm bitbucket
@martin-cotta
martin-cotta / git.cmd
Created July 4, 2016 06:32
Configure Git on Windows
git config --global core.editor "'c:/program files/sublime text 3/subl.exe' -w"
@martin-cotta
martin-cotta / OpenSSL.sh
Created January 30, 2017 16:56
Goddady SSL/TSL Certificate (P7B + CRT) to Azure PFX Certificate
# Required files:
# domain.crt and godaddy.p7b: provided by Godaddy when exporting
# private.key: self-generated file that was needed to create CSR (Certificate signing request)
$ openssl pkcs12 -export -in domain.crt -inkey private.key -certfile godaddy.p7b -out domain.pfx
# or if you need intermediate .cer instead of .p7b
$ openssl pkcs7 -print_certs -in godaddy.p7b -out godaddy.crt
$ openssl pkcs12 -export -in domain.crt -inkey private.key -certfile godaddy.cer -out domain.pfx
import Foundation
import React
@objc(MyModule)
class MyModule: RCTEventEmitter {
@objc func loadProducts(_ orderId: NSNumber, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) {
let products = // load products somehow ...
if products {
resolve(products);