Skip to content

Instantly share code, notes, and snippets.

View dkarbayev's full-sized avatar
🏠
Working from home

Dan Karbayev dkarbayev

🏠
Working from home
  • Army of One
  • Your Neighbourhood
View GitHub Profile
global.THREE = require("three");
const canvasSketch = require('canvas-sketch');
const Random = require('canvas-sketch-util/random');
const gradientHeight = 512;
const settings = {
dimensions: [ 2048, gradientHeight * 2 ]
};
@dkarbayev
dkarbayev / bounded_goroutines.go
Created January 6, 2019 12:13
Limit the number of concurrently running goroutines
package main
import (
"fmt"
"math/rand"
"sync"
"time"
)
func main() {
package main
import (
"fmt"
)
// tl = top left
// tr = top right
// bl = bottom left
// br = bottom right
package main
import (
"fmt"
"reflect"
)
type MyType struct {
Name string
Age int
import UIKit
extension UIAlertController {
public enum TextInputResult {
/// The user tapped Cancel.
case cancel
/// The user tapped the OK button. The payload is the text they entered in the text field.
case ok(String)
}
@dkarbayev
dkarbayev / console.js
Last active July 19, 2018 23:35
Overrides console log, error and other functions
if (typeof JSON !== "object") {
JSON = {};
}
(function () {
"use strict";
var rx_one = /^[\],:{}\s]*$/;
var rx_two = /\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g;
var rx_three = /"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g;
var rx_four = /(?:^|:|,)(?:\s*\[)+/g;
@dkarbayev
dkarbayev / MultiDirectionAdjudicatingScrollView.swift
Created June 25, 2018 23:16 — forked from andymatuschak/MultiDirectionAdjudicatingScrollView.swift
Source for the Khan Academy app's unusual scrolling interactions
//
// MultiDirectionAdjudicatingScrollView.swift
// Khan Academy
//
// Created by Andy Matuschak on 12/16/14.
// Copyright (c) 2014 Khan Academy. All rights reserved.
//
import UIKit
import UIKit.UIGestureRecognizerSubclass
let golf:(Int)->Int={n in(n+1...).first(where:{k in String(k)==String(String(k).reversed())&&Array(2...k/2).filter({k%$0<1}).isEmpty})!}
@dkarbayev
dkarbayev / Slicing.swift
Last active February 10, 2018 00:51
Slicing sequence by predicate
extension Sequence {
func sliced(by predicate: (Element, Element) -> Bool) -> [[Element]] {
var result = [[Element]]()
for element in self {
guard let previous = result.last?.last, !predicate(previous, element) else { result.append([element]); continue }
result[result.count - 1].append(element)
}
return result
//
// ViewController.swift
//
import UIKit
public protocol Tapable {}
extension Tapable where Self: AnyObject {
public func tap(_ block: (Self) -> Void) -> Self {
block(self)