Skip to content

Instantly share code, notes, and snippets.

Vladimir Grichina vgrichina

View GitHub Profile
@vgrichina
vgrichina / generated_bindings.ts
Last active Dec 7, 2018
Sample generated AssemblyScript BSON bindings
View generated_bindings.ts
import "allocator/arena";
// TODO: Why cannot import from index?
// import { BSONEncoder, BSONDecoder } from "../../../assemblyscript-bson/assembly";
import { BSONEncoder } from "../../../assemblyscript-bson/assembly/encoder";
import { BSONDecoder } from "../../../assemblyscript-bson/assembly/decoder";
declare function sayHello(): void;
export class FooBar {
foo: i32 = 0;
@vgrichina
vgrichina / booking.ts
Last active Nov 28, 2018
Booking train and hotel
View booking.ts
book_train_and_hotel() : void { // Needs 6 MANA.
// 3 for train and callback and 3 for hotel and callback.
// E.g. book_train and book_hotel doesn't need additional mana, so only 1 MANA for a call.
// Callback may need 1 additional to cancel train or hotel booking if one of them failed.
assert_has_mana(6);
let hotelBooking = bookHotel.withMana(3).withCoins(1000).book(sender());
let trainBooking = bookTrain.withMana(3).withCoins(1000).book(sender());
View ropes.hs
data Rope = Empty | Concat Int Rope Rope | Leaf String deriving (Show, Eq)
rope :: String -> Rope
rope "" = Empty
rope s = Leaf s
len :: Rope -> Int
len Empty = 0
len (Leaf s) = length s
len (Concat length _ _) = length
View gist:57796fb8d9a8ae41fc0d
/**
* CSV Parser. Takes a string as input and returns
* an array of arrays (for each row).
*
* @param input String, CSV input
* @param separator String, single character used to separate fields.
* Defaults to ","
* @param quote String, single character used to quote non-simple fields.
* Defaults to "\"".
*/
View word_ladder.py
import string
class Solution:
# @param start, a string
# @param end, a string
# @param dict, a set of string
# @return an integer
def ladderLength(self, start, end, dict):
dict += [end]
View quicksort.swift
// Playground - noun: a place where people can play
import UIKit
let b = [1, 2, 3][1..2].filter { $0 < 3 }
let c = b + [5, 6]
func quicksort<T : Comparable>(arr : Array<T>) -> Array<T> {
if arr.count <= 1 {
return arr
View Dijkstra 5 lines
class Edge
attr_accessor :src, :dest, :length
def initialize(src, dest, length = 1)
@src = src
@dest = dest
@length = length
end
end
View CXBinder.h
//
// CXBinder.h
// TheList
//
// Created by Vladimir Grichina on 28.01.13.
// Copyright (c) 2013 TheList, LLC. All rights reserved.
//
#import <THObserversAndBinders/THBinder.h>
@vgrichina
vgrichina / NSObject+KVOWeakPropertyDebug.h
Created Jan 12, 2013
NSObject category that logs calls to addObserver for weak properties (as they aren't fully KVO-compliant)
View NSObject+KVOWeakPropertyDebug.h
//
// NSObject+KVOWeakPropertyDebug.h
// KVOWeakPropertyDebug
//
// Created by Vladimir Grichina on 12.01.13.
// Copyright (c) 2013 Vladimir Grichina. All rights reserved.
//
#import <Foundation/Foundation.h>
@vgrichina
vgrichina / CellBackgroundView.h
Created Nov 12, 2012
Customizable background view for UITableViewCell in grouped table view
View CellBackgroundView.h
//
// CellBackgroundView.h
//
//
#import <UIKit/UIKit.h>
typedef enum {
CellPositionTop,
CellPositionMiddle,
You can’t perform that action at this time.