Skip to content

Instantly share code, notes, and snippets.

View alexanderkhitev's full-sized avatar

Alexander Khitev alexanderkhitev

View GitHub Profile
import Foundation
// Inspired by
struct JSONCodingKeys: CodingKey {
var stringValue: String
init?(stringValue: String) {
self.stringValue = stringValue
// RBResizer.swift
// Locker
// Created by Hampton Catlin on 6/20/14.
// Copyright (c) 2014 rarebit. All rights reserved.
// Updated by Justin Winter on 11/29/15.
extension UIImage {
entropiae /
Last active February 3, 2022 23:32
git: how to solve "SSLRead() return error -9806" in OSX using brew
$ brew remove git
$ brew remove curl
$ brew install openssl
$ brew install --with-openssl curl
$ brew install --with-brewed-curl --with-brewed-openssl git
ericdke / splitBy.swift
Last active July 10, 2023 09:55
Swift: split array by chunks of given size
let arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
extension Array {
func splitBy(subSize: Int) -> [[Element]] {
return 0.stride(to: self.count, by: subSize).map { startIndex in
let endIndex = startIndex.advancedBy(subSize, limit: self.count)
return Array(self[startIndex ..< endIndex])
mikelehen / generate-pushid.js
Created February 11, 2015 17:34
JavaScript code for generating Firebase Push IDs
* Fancy ID generator that creates 20-character string identifiers with the following properties:
* 1. They're based on timestamp so that they sort *after* any existing ids.
* 2. They contain 72-bits of random data after the timestamp so that IDs won't collide with other clients' IDs.
* 3. They sort *lexicographically* (so the timestamp is converted to characters that will sort properly).
* 4. They're monotonically increasing. Even if you generate more than one in the same timestamp, the
* latter ones will sort after the former ones. We do this by using the previous random bits
* but "incrementing" them by 1 (only in the case of a timestamp collision).
justmoon / custom-error.js
Last active April 22, 2024 17:19 — forked from subfuzion/
Creating custom Error classes in Node.js
'use strict';
module.exports = function CustomError(message, extra) {
Error.captureStackTrace(this, this.constructor); =;
this.message = message;
this.extra = extra;
require('util').inherits(module.exports, Error);
HamptonMakes / RBResizer.swift
Created June 27, 2014 14:45
Swift Image Resizer
// RBResizer.swift
// Locker
// Created by Hampton Catlin on 6/20/14.
// Copyright (c) 2014 rarebit. All rights reserved.
import UIKit
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:
simenbrekken /
Last active January 7, 2017 13:44
Firebase NPM doesn't expose the token generator dependency

There are some ways to fix this:

  1. Remove dependency and let users install it manually as needed, the token generator isn't really a hard dependency of Firebase anyway
  2. Expose the dependency from the firebase module:
    var Firebase = require('firebase')
        FirebaseTokenGenerator = Firebase.TokenGenerator
jacobbubu / ioslocaleidentifiers.csv
Created February 15, 2012 14:41
iOS Locale Identifiers
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
mr Marathi
bs Bosnian
ee_TG Ewe (Togo)
ms Malay
kam_KE Kamba (Kenya)
mt Maltese
ha Hausa
es_HN Spanish (Honduras)
ml_IN Malayalam (India)
ro_MD Romanian (Moldova)