Skip to content

Instantly share code, notes, and snippets.

View SPY's full-sized avatar

Ilya Rezvov SPY

  • Roblox, Luau VM. Ex: Google, V8; Meta, Erlang/Thrift
  • Denver/SF Bay Area, USA
View GitHub Profile
proc enumDef(x: NimNode): NimNode =
result = quote do:
type `x` = enum enOne, enTwo
macro one(x): stmt {. immediate .} =
echo treeRepr(x)
result = enumDef(x)
echo treeRepr(result)
one SuperEnum
proc get*(client: MemcacheAsyncClient, key: string): Future[string] =
let res = newFuture[string]()
client.sendCommand(CommandOpcode.Get, key = key.toRawData()).callback = proc(future: Future[Response]) {.closure, gcsafe.} =
let response = future.read()
if response.header.status == ResponseStatus.KeyNotFound:
res.fail(newException(KeyNotFoundError, "Key " & key & " is not found"))
else:
res.complete(response.value)
res
import asyncdispatch
type KeyNotFoundError* = object of IOError
proc get*(key: string): Future[string] =
let res = newFuture[string]()
sleepAsync(500).callback = proc(future: Future[void]) {.closure, gcsafe.} =
if key != "hello":
res.fail(newException(KeyNotFoundError, "Key " & key & " is not found"))
else:
{-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies #-}
-- works too
class Message params msg | msg -> params, params -> msg where
create :: params -> msg
data FooMessage = FooMessage { from, to :: Int } deriving (Show)
data FooMessageParams = FooMessageParams { _from, _to :: Maybe Int }
@SPY
SPY / App.tsx
Last active November 18, 2015 10:56
import {actionCreators, Action} from '../actions/Action'
export class App extends React.Component<AppProps, {}> {
public static childContextTypes: any = {}
private getChildContext() {
const context: any = {}
const props = this.props as any
Object.keys(this.props).forEach(prop => {
if (typeof props[prop] == 'function' && prop in actionCreators) {
@SPY
SPY / rbtree.ml
Last active December 16, 2015 20:54
Naive implementation of red-black tree with OCaml
module RBTree : sig
type 'a t
val empty : 'a t
val insert : 'a t -> 'a -> 'a t
val exists : 'a t -> 'a -> bool
val remove : 'a t -> 'a -> 'a t
val fold_left : ('b -> 'a -> 'b) -> 'b -> 'a t -> 'b
val fold_right : ('a -> 'b -> 'b) -> 'a t -> 'b -> 'b
val balanced : 'a t -> bool
val from_list : 'a list -> 'a t
import * as React from 'react'
interface Point {
x: number,
y: number
}
interface DraggableState {
dragStartPoint?: Point
}
exports.up = function(db) {
return new Promise(function (resolve, reject) {
db.dropTable('companies')
}).then(
db.createTable('companies', {
company_id: { type: 'bigserial', primaryKey: true },
company_name: { type: 'string', unique: true },
domain: { type: 'string', unique: true },
owner: 'bigint'
})
var ExtractTextPlugin = require('extract-text-webpack-plugin')
var ExtendedDefinePlugin = require('extended-define-webpack-plugin')
var path = require('path')
module.exports = {
entry: './src/index.tsx',
resolve: {
alias: {
src: path.join(__dirname, 'src'),
store: path.join(__dirname, 'src', 'store'),
@SPY
SPY / slice_to_i32.rs
Created April 18, 2016 09:11
Convert Rust u8 slice to i32
fn slice_to_i32_be(data: &[u8]) -> i32 {
assert!(data.len() >= 4);
let first = data[0];
let sign = if first & 0x80 != 0 { -1 } else { 1 };
sign * (
(((first & 0x7F) as i32) << 24) +
((data[1] as i32) << 16) +
((data[2] as i32) << 8 ) +
( data[3] as i32 )
)