Skip to content

Instantly share code, notes, and snippets.

View blixt's full-sized avatar
🚀
???

Blixt blixt

🚀
???
View GitHub Profile
@blixt
blixt / getPath.js
Created April 23, 2015 21:13
getPath+
/*
The MIT License (MIT)
Copyright (c) 2010 Blixt
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
@blixt
blixt / gist:9416b03b33ed7e3fbe6c
Created June 29, 2015 04:06
Dieharder output
#=============================================================================#
# dieharder version 3.31.1 Copyright 2003 Robert G. Brown #
#=============================================================================#
rng_name | filename |rands/second|
file_input| dieharder.txt| 4.17e+06 |
#=============================================================================#
test_name |ntup| tsamples |psamples| p-value |Assessment
#=============================================================================#
diehard_birthdays| 0| 100| 100|0.80634484| PASSED
diehard_operm5| 0| 1000000| 100|0.02613178| PASSED
@blixt
blixt / Math.random.txt
Created June 29, 2015 12:41
Dieharder output
#=============================================================================#
# dieharder version 3.31.1 Copyright 2003 Robert G. Brown #
#=============================================================================#
rng_name | filename |rands/second|
file_input| dieharder.txt| 4.11e+06 |
#=============================================================================#
test_name |ntup| tsamples |psamples| p-value |Assessment
#=============================================================================#
diehard_birthdays| 0| 100| 100|0.37793720| PASSED
diehard_operm5| 0| 1000000| 100|0.25454738| PASSED
@blixt
blixt / arbit.txt
Created June 29, 2015 18:32
Dieharder output
#=============================================================================#
# dieharder version 3.31.1 Copyright 2003 Robert G. Brown #
#=============================================================================#
rng_name | filename |rands/second|
file_input| dieharder.txt| 4.31e+06 |
#=============================================================================#
test_name |ntup| tsamples |psamples| p-value |Assessment
#=============================================================================#
diehard_birthdays| 0| 100| 100|0.15936729| PASSED
diehard_operm5| 0| 1000000| 100|0.95725635| PASSED
class ListDiff<T : Hashable> {
typealias IndexList = [Int]
typealias FromIndexToIndexList = [(from: Int, to: Int)]
// A list of indexes of where items were added.
let added: IndexList
// A list of indexes where items that have disappeared used to be.
let deleted: IndexList
// A list of tuples of indexes representing the old and new indexes of items that moved.
let moved: FromIndexToIndexList
@blixt
blixt / OrderedDictionary.swift
Created August 19, 2015 23:45
Somewhat complete ordered dictionary implementation
struct OrderedDictionary<Key : Hashable, Value> {
typealias Element = (key: Key, value: Value)
private var dictionary = [Key: Value]()
private var orderedKeys = [Key]()
var count: Int {
return self.orderedKeys.count
}
// Update: See a solution here:
// https://gist.github.com/blixt/08434b74f0c043f83fcb
// (NSMapTable holds onto the weak keys longer than I expected)
import Foundation
private class ClosureWrapper<EventData> {
typealias EventHandler = (EventData) -> Void
let closure: EventHandler
init(_ closure: EventHandler) {
@blixt
blixt / Event.swift
Last active January 19, 2023 19:42
A simple Event class for handling events in Swift without strong retain cycles.
import Foundation
private class Invoker<EventData> {
weak var listener: AnyObject?
let closure: (EventData) -> Bool
init<Listener : AnyObject>(listener: Listener, method: (Listener) -> (EventData) -> Void) {
self.listener = listener
self.closure = {
[weak listener] (data: EventData) in
@blixt
blixt / formatting.js
Created September 27, 2015 15:36
Formatting templating strings in ES6
function format(strings, ...values) {
const pieces = [];
for (let [index, string] of strings.entries()) {
let value = values[index];
const formatIndex = string.lastIndexOf('$');
if (formatIndex != -1) {
const format = string.substr(formatIndex + 1);
string = string.substr(0, formatIndex);
// TODO: Use an actual format engine here.
@blixt
blixt / HexToUIColor.swift
Last active July 28, 2021 05:19
A Swift String extension that converts a hexadecimal color to a UIColor.
import UIKit
extension String {
var hexColor: UIColor? {
let hex = self.stringByTrimmingCharactersInSet(NSCharacterSet.alphanumericCharacterSet().invertedSet)
var int = UInt32()
guard NSScanner(string: hex).scanHexInt(&int) else {
return nil
}
let a, r, g, b: UInt32