This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {-# 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 } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import * as React from 'react' | |
| interface Point { | |
| x: number, | |
| y: number | |
| } | |
| interface DraggableState { | |
| dragStartPoint?: Point | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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' | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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'), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 ) | |
| ) |