Skip to content

Instantly share code, notes, and snippets.

import Foundation
extension String
{
var length: Int {
get {
return countElements(self)
}
}
@briscula
briscula / es7-async-await.js
Created March 30, 2018 15:25
Javascript fetch JSON with ES7 Async Await
// Async/Await requirements: Latest Chrome/FF browser or Babel: https://babeljs.io/docs/plugins/transform-async-to-generator/
// Fetch requirements: Latest Chrome/FF browser or Github fetch polyfill: https://github.com/github/fetch
// async function
async function fetchAsync () {
// await response of fetch call
let response = await fetch('https://api.github.com');
// only proceed once promise is resolved
let data = await response.json();
// only proceed once second promise is resolved
@briscula
briscula / node-red
Last active March 25, 2018 14:07 — forked from Belphemur/node-red
#!/bin/bash
### BEGIN INIT INFO
# Provides: node-red
# Required-Start: $local_fs $remote_fs $network
# Required-Stop: $local_fs $remote_fs $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start or stop the node-red server
### END INIT INFO
# Can be downloaded and installed in one go by using this command
@briscula
briscula / README.md
Last active March 25, 2018 15:03 — forked from bigmonkeyboy/README.md
init.d script for Node-RED

This gist creates an init.d script to automatically run Node-RED at boot time.

To run it as a single step you can cut paste the following single line command

sudo wget -O /tmp/download https://gist.github.com/bigmonkeyboy/9962293/download && sudo tar -zxf /tmp/download --strip-components 1 -C /etc/init.d && sudo chmod 755 /etc/init.d/nodered && sudo update-rc.d nodered defaults

or click right-click "save as" this link - But please read the script first and satisfy yourself it's safe to execute in your environment...

@briscula
briscula / nginx.conf
Created February 26, 2018 21:31 — forked from plentz/nginx.conf
Best nginx configuration for improved security(and performance). Complete blog post here http://tautt.com/best-nginx-configuration-for-security/
# to generate your dhparam.pem file, run in the terminal
openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048
@briscula
briscula / LocalAuthenticationExample.swift
Created February 8, 2018 21:31
Example of user authentication via LocalAuthentication.framework
import LocalAuthentication
func afterUserAuthorized(perform handler: @escaping (Bool)->()) {
let context = LAContext()
var error:NSError?
/* .deviceOwnerAuthentication - using Touch ID or the device password
.deviceOwnerAuthenticationWithBiometrics - use Touch ID only */
guard context.canEvaluatePolicy(.deviceOwnerAuthentication, error: &error) else {
fatalError("No TouchID or passcode set on this device")
@briscula
briscula / floatsign.sh
Created December 21, 2017 14:58
A small bash script to re-sign iOS applications.
# !/bin/bash
# Copyright (c) 2011 Float Mobile Learning
# http://www.floatlearning.com/
#
# Extended by Ronan O Ciosoig January 2012
#
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the "Software"),
1. Use openssl
openssl smime -in /path/to/your.mobileprovision -inform der -verify
2. Use security command
security cms -Di /path/to/your.mobileprovision
REPO="$HOME/src/dotfiles.git"
GITHUB_REPO_URL="https://github.com/fornellas/dotfiles.git"
mkdir -p "$REPO"
cd "$REPO"
git init --bare
cd -
echo '*' >> "$REPO/info/exclude"
echo "alias dotfiles='git --git-dir=\"""$REPO""\" --work-tree=\"\$HOME\"'" >> ~/.bashrc
source ~/.bashrc
@briscula
briscula / NibLoadableView.swift
Created November 2, 2017 11:15 — forked from eMdOS/NibLoadableView.swift
Reusable views and cell registration and dequeuing (for table views and collection views)
protocol NibLoadableView: class {
static var nibName: String { get }
}
extension NibLoadableView where Self: UIView {
static var nibName: String {
return String(describing: self)
}
}