Skip to content

Instantly share code, notes, and snippets.

View vgrichina's full-sized avatar

Vladimir Grichina vgrichina

View GitHub Profile
@vgrichina
vgrichina / NSObject+KVOWeakPropertyDebug.h
Created January 12, 2013 01:09
NSObject category that logs calls to addObserver for weak properties (as they aren't fully KVO-compliant)
//
// NSObject+KVOWeakPropertyDebug.h
// KVOWeakPropertyDebug
//
// Created by Vladimir Grichina on 12.01.13.
// Copyright (c) 2013 Vladimir Grichina. All rights reserved.
//
#import <Foundation/Foundation.h>
//
// CXBinder.h
// TheList
//
// Created by Vladimir Grichina on 28.01.13.
// Copyright (c) 2013 TheList, LLC. All rights reserved.
//
#import <THObserversAndBinders/THBinder.h>
class Edge
attr_accessor :src, :dest, :length
def initialize(src, dest, length = 1)
@src = src
@dest = dest
@length = length
end
end
// 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
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]
/**
* 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 "\"".
*/
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
@vgrichina
vgrichina / booking.ts
Last active November 28, 2018 23:40
Booking train and hotel
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());
@vgrichina
vgrichina / generated_bindings.ts
Last active October 16, 2023 13:24
Sample generated AssemblyScript BSON bindings
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 / callback.js
Last active July 12, 2019 00:31
Spin up temporary webserver to handle callback from browser
const http = require('http');
const url = require('url');
const hostname = '127.0.0.1';
const port = 3000;
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/html');
try {