Skip to content

Instantly share code, notes, and snippets.

View oleganza's full-sized avatar

Oleg Andreev oleganza

View GitHub Profile
### Keybase proof
I hereby claim:
* I am oleganza on github.
* I am oleganza (https://keybase.io/oleganza) on keybase.
* I have a public key whose fingerprint is AB70 0EB4 91D6 3812 D5B0 AE40 6456 F1F5 C543 2530
To claim this, I am signing this object:
@oleganza
oleganza / gist:10458460
Created April 11, 2014 11:00
js password generator
// Based on oi.js by Dan Kaminsky https://gist.github.com/PaulCapestany/6148566
var base58alphabet = '123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ';
function millis() { return Date.now(); }
function flip_coin() { n=0; then = millis()+1; while(millis()<=then) { n=!n; } return n; }
function get_fair_bit() { while(1) { a=flip_coin(); if(a!=flip_coin()) { return(a); } } }
function get_random_6bit(){ n=0; bits=6; while(bits--){ n<<=1; n|=get_fair_bit(); } return n; }
function get_password(length) {
var password = "";
var offset = 0; // offset allows us to go through the infinite alphabet thus minimizing bias towards lower characters.
@oleganza
oleganza / BIP-Fractional-Storage-Identifier.md
Last active August 29, 2015 14:00
BIP: Fractional Storage Identifier

BIP: Fractional Storage Identifier

Abstract

In Bitcoin we might want to have fractional storage of blocks and transaction state so that many more nodes can fully validate incoming blocks without sacrificing a lot of disk space. We propose a scheme that allows nodes to advertise which fraction of the data set they can provide and enables uniform distribution of such fractions among nodes. The scheme also allows reducing individual fraction at no extra cost to scale with the gbrowth of the network.

Scheme

@oleganza
oleganza / BIP-Fractional-Full-Node.md
Created April 30, 2014 12:07
BIP-Fractional-Full-Node

BIP Draft: Fractional Full Node

Abstract

We explore the way to make full Bitcoin nodes store only a fraction of data while being able to fully validate every incoming block and get information about any output or transaction.

Strategy

@oleganza
oleganza / filter-api-diff.rb
Created June 5, 2014 06:10
Strip away "method->property" updates from iOS/OSX API diffs
# Oleg Andreev @oleganza
#
# This is a script that strips away all lines about converting methods to properties.
# Filtered file is easier to read to find what's new.
#
# 1. Save html file with API diff.
# 2. Run filter-api-diff.rb <name-of-the-file.html>
# 3. Open <name-of-the-file.html>-filtered.html in Safari.
#
# This script adds absolute URLs for stylesheets, no worries about them.
// Y-combinator in Swift.
func Y<y,⒴>(𝖸:((y)->⒴)->((y)->⒴))->((y)->⒴){
var Y:((y)->⒴)!;Y=𝖸{Y($0)};return Y
}
// Couldn't find a way to avoid such explicitness.
// If types are defined in the inner function, compiler cannot infer type of 'f'.
let factorial = Y {(f:((Int)->Int)) -> ((Int)->Int) in
return {n in
@oleganza
oleganza / gist:9805d0c42172803253a7
Last active August 29, 2015 14:02
Replacement for ?: operator in Clang
// Replacement for Clang's (a ?: b) in Swift.
// Note: does not yet handle case when 'false' is supplied as Any? or AnyObject? type.
operator infix ||| { associativity left precedence 140 }
// Version for arbitrary optionals.
@infix func |||<A>(a:A?, b: @auto_closure ()->A?) -> A? {
if let x = a {
return a
}
@oleganza
oleganza / gist:bd14f60643395706efaa
Last active August 29, 2015 14:02
Reply on Ghash

A reader asked me over email recently:

Have you posted anything or had any thoughts on Ghash.IO situation?

Nothing on this. I think it's just early volatility in bitcoin space. Some company (CEX) got serious about making a private mining farm and made a whopping share. Others will follow soon.

The dirty little secret of the blockchain is that it's not secure until increasing the hashrate by even 1% is an enormous economic feat. Currently it's not impossibly expensive to build your own farm with significant share - therefore the network is not very theoretically secure. Even if every existing pool had no more than 10%, you can't be sure that some guy does not unleash enormous hashing power at once and reverts some transactions.

When more companies start building private farms (and they will, it's the only cost-efficient way to mine; individual miners will soon disappear), you'll see more even distribution of the hashrate, but most importantly, the growth of hashrate will get slower. Because the slo

@oleganza
oleganza / async_swift_promises.md
Created June 25, 2015 13:32
Async Swift with explicit Promises
// Before
func makeSandwich(completionHandler: (result:Sandwich)->Void)

// After
async func makeSandwich() -> Sandwich

// Informally equivalent to:
# Subject: f.rb
# From: Oleg Andreev <oleganza@gmail.com>
# Date: November 9, 2008
module Kernel
# Private functions for mixins (to avoid private methods clash)
# Usage:
# module MyModule
# def my_api_method
# F.some_private_function()