I've been trying to understand how to setup systems from
the ground up on Ubuntu. I just installed redis
onto
the box and here's how I did it and some things to look
out for.
To install:
// Generate unique IDs for use as pseudo-private/protected names. | |
// Similar in concept to | |
// <http://wiki.ecmascript.org/doku.php?id=strawman:names>. | |
// | |
// The goals of this function are twofold: | |
// | |
// * Provide a way to generate a string guaranteed to be unique when compared | |
// to other strings generated by this function. | |
// * Make the string complex enough that it is highly unlikely to be | |
// accidentally duplicated by hand (this is key if you're using `ID` |
document.getElementsByTagName('button')[0].onclick = function () { | |
scrollTo(document.body, 0, 1250); | |
} | |
function scrollTo(element, to, duration) { | |
var start = element.scrollTop, | |
change = to - start, | |
currentTime = 0, | |
increment = 20; | |
/* Polyfill indexOf. */ | |
var indexOf; | |
if (typeof Array.prototype.indexOf === 'function') { | |
indexOf = function (haystack, needle) { | |
return haystack.indexOf(needle); | |
}; | |
} else { | |
indexOf = function (haystack, needle) { | |
var i = 0, length = haystack.length, idx = -1, found = false; |
import Foundation | |
struct EquatableValueSequence<T: Equatable> { | |
static func ==(lhs: EquatableValueSequence<T>, rhs: T) -> Bool { | |
return lhs.values.contains(rhs) | |
} | |
static func ==(lhs: T, rhs: EquatableValueSequence<T>) -> Bool { | |
return rhs == lhs | |
} |
import CommonCrypto | |
extension String { | |
func hmac(key: String) -> String { | |
var digest = [UInt8](repeating: 0, count: Int(CC_SHA1_DIGEST_LENGTH)) | |
CCHmac(CCHmacAlgorithm(kCCHmacAlgSHA1), key, key.count, self, self.count, &digest) | |
let data = Data(bytes: digest) | |
return data.base64EncodedString() | |
} | |
} |
//: # Swift 3: Base64 encoding and decoding | |
import Foundation | |
extension String { | |
//: ### Base64 encoding a string | |
func base64Encoded() -> String? { | |
if let data = self.data(using: .utf8) { | |
return data.base64EncodedString() | |
} | |
return nil |
// | |
// HMAC.swift | |
// | |
// Created by Mihael Isaev on 21.04.15. | |
// Copyright (c) 2014 Mihael Isaev inc. All rights reserved. | |
// | |
// *********************************************************** | |
// | |
// How to import CommonCrypto in Swift project without Obj-c briging header | |
// |
/* | |
I've wrapped Makoto Matsumoto and Takuji Nishimura's code in a namespace | |
so it's better encapsulated. Now you can have multiple random number generators | |
and they won't stomp all over eachother's state. | |
If you want to use this as a substitute for Math.random(), use the random() | |
method like so: | |
var m = new MersenneTwister(); |