Skip to content

Instantly share code, notes, and snippets.

class FancyString {
let name: String
init () { // Called one time
print("init")
name = "Frederik"
}
deinit { // Called one time
print("deinit")
import DbManager from './dbManager';
let dbManager = new DbManager(process.env.DB_CONN_STRING);
(async function main() {
for(let entity of json) {
let { entityId } = await dbManager.insertEntity(entity);
}
})();
console.log('*** VARIABLES ***');
// Declaration (make a new variable, and give it a name)
var person;
// Assignment (put a value inside the variable)
person = "Tomomi";
console.log(person);
person = "Frederik";
@fnakstad
fnakstad / gist:9fc39aae92842d84df4e
Last active November 28, 2015 04:25
Check network availability in Swift
import SystemConfiguration
public class Reachability {
class func isConnectedToNetwork() -> Bool {
var zeroAddress = sockaddr_in()
zeroAddress.sin_len = UInt8(sizeofValue(zeroAddress))
zeroAddress.sin_family = sa_family_t(AF_INET)
let defaultRouteReachability = withUnsafePointer(&zeroAddress) {
SCNetworkReachabilityCreateWithAddress(nil, UnsafePointer($0))
}
@fnakstad
fnakstad / circShift.js
Created December 8, 2014 04:28
Circular shift
// First creates a shallow copy of array,
// then shifts contents circularly according to
// number of steps and direction given
function circularShift(arrayPar, steps, shiftLeft) {
var array = arrayPar.slice(0);
for(var i = 0; i < steps; i++) {
if(shiftLeft)
array.push(array.shift());
else
<!DOCTYPE html>
<html data-ng-app="angular-client-side-auth" lang="en">
<head>
<meta charset="utf-8">
<title>Angular Auth Example</title>
<link href="/css/app.css" rel="stylesheet">
<link href="/components/bootstrap/dist/css/bootstrap.min.css" rel=
"stylesheet">
var mongoose = require('mongoose')
, Schema = mongoose.Schema
, passport = require('passport')
, bcrypt = require('bcrypt')
, check = require('validator').check
, Validator = require('validator').Validator;
var userSchema = new Schema({
email: { type: String, unique: true, required: true },
salt: { type: String, required: true },
function ensureAuthorized(req, res, next) {
var role;
if(!req.user) role = userRoles.public;
else role = req.user.role;
var accessLevel = _.findWhere(routes, { path: req.route.path }).accessLevel || accessLevels.public;
if(!(accessLevel.bitMask & role.bitMask)) return res.send(403);
return next();
}
module.exports = function(app) {
_.each(routes, function(route) {
var args = _.flatten([route.path, route.middleware]);
switch(route.httpMethod.toUpperCase()) {
case 'GET':
app.get.apply(app, args);
break;
case 'POST':
<button access-level="accessLevels.user">Add</button>
<button access-level="accessLevels.user">Edit</button>
<button access-level="accessLevels.admin">Delete</button>