Skip to content

Instantly share code, notes, and snippets.

@jstn
jstn / min.tumblr.html
Last active December 27, 2023 19:51
min theme for tumblr
<!--
(c) {CopyrightYears} {Title}
{BlogURL}
min theme by jstn
https://gist.github.com/jstn/5a67fd6c035bb86d1c504c98fa9cac07
-->
<html>
@jstn
jstn / RandomNumbers.swift
Last active May 5, 2023 03:26
generate random numbers for 64-bit types while mitigating modulo bias
/*
`arc4random_uniform` is very useful but limited to `UInt32`.
This defines a generic version of `arc4random` for any type
expressible by an integer literal, and extends some numeric
types with a `random` method that mitigates for modulo bias
in the same manner as `arc4random`.
`lower` is inclusive and `upper` is exclusive, thus:
@jstn
jstn / Timer.swift
Last active June 19, 2022 15:14
simple nanosecond timer using mach_absolute_time
/*
var t = Timer()
t.start()
// do something
t.stop()
print("took \(t.seconds)")
*/
@jstn
jstn / MD5.swift
Last active January 24, 2022 15:33
MD5 with CommonCrypto in Swift 3.0
// requires a bridging header with this:
// #import <CommonCrypto/CommonCrypto.h>
func MD5(_ string: String) -> String? {
let length = Int(CC_MD5_DIGEST_LENGTH)
var digest = [UInt8](repeating: 0, count: length)
if let d = string.data(using: String.Encoding.utf8) {
d.withUnsafeBytes { (body: UnsafePointer<UInt8>) in
CC_MD5(body, CC_LONG(d.count), &digest)
}
I am attesting that this GitHub handle jstn is linked to the Tezos account tz1dW4z811rbrACxH5PTu5VtdhRisLZUDhdU for tzprofiles
sig:edsigtvwUeibQMzSm2pfT6gSJYfSXcBxkcUUATAMid3s9sm5D1k2KSXjzMY7r3ticACeMSqivxvpew2n9AgCJNpVpcyB6miduhC
@jstn
jstn / JSTN.css
Last active March 1, 2021 02:28
limechat theme
/*
JSTN THEME FOR LIMECHAT 1.0
put this and the other thing in ~/Library/Application Support/LimeChat/Themes/
bg 1a2230
hlight 273146
red e44347
purps 8b84d0
fuscia c2339a
{
"caret_extra_bottom": 2,
"caret_extra_top": 2,
"caret_extra_width": 1,
"caret_style": "phase",
"color_scheme": "Packages/Base16 Color Schemes/Themes/base16-oceanicnext.tmTheme",
"create_window_at_startup": false,
"ensure_newline_at_eof_on_save": true,
"fold_buttons": false,
"folder_exclude_patterns":
function git_prompt() {
local dirty=""
if [[ -n $(git ls-files --other --exclude-standard 2> /dev/null) ]]; then
dirty="*"
fi
if ! git diff --quiet 2> /dev/null; then
dirty="*"
fi
@jstn
jstn / keybase.md
Created January 13, 2017 10:38
Keybase proof

Keybase proof

I hereby claim:

  • I am jstn on github.
  • I am ouellette (https://keybase.io/ouellette) on keybase.
  • I have a public key ASCnfu-Ia5yAtEsb4pUhLwOpUbODSRFNuSJDG6LcbLPwxwo

To claim this, I am signing this object:

@jstn
jstn / mutexes.swift
Last active September 6, 2016 15:28
/*
No-Starve and Read/Write mutexes, based on GCD in Swift 3.0
Inspired by the Little Book of Semaphores: http://greenteapress.com/wp/semaphores/
*/
import Foundation
final class NoStarveMutex {
private final let _semaphoreA = DispatchSemaphore(value: 1)
private final let _semaphoreB = DispatchSemaphore(value: 0)