Skip to content

Instantly share code, notes, and snippets.

@nin-jin
nin-jin / tests.ts
Last active Mar 13, 2020
Статикодинамические валидаторы
View tests.ts
type TestUserType = Assert<
typeof User.Value,
{
readonly name: string
readonly birthday: Moment
readonly email: string & { Brand: "Email" } | undefined
}
>
@nin-jin
nin-jin / harp-request.md
Last active Feb 23, 2020
HARP - Hypermedia Abstract Resource Protocol
View harp-request.md

Requirements:

  1. One line query through uri.
  2. Filtering
  3. Sorting
  4. Limitation
  5. Partial fetching
  6. Fetching linked resources
  7. Normalized response
  8. Bulk requests
@nin-jin
nin-jin / args.js
Created May 2, 2017
NodeJS arguments processing
View args.js
var args = {}
process.argv.slice(2).forEach( param => {
var values = param.split( '=' )
var key = values.shift()
args[ key ] = ( args[ key ] || [] ).concat( values.join( '=' ) )
} )
var actions = {
'help help' : args => `help\t\tPrints help (default action)\n` ,
'help' : args => `\nSuper-puper server!\n${ actions['actions']() }${ actions['options']() }`,
@nin-jin
nin-jin / gist:111f32935da5c758a1c8
Last active Nov 25, 2015
Dlang non blocking messaging
View gist:111f32935da5c758a1c8
import std.stdio;
import std.concurrency;
import std.conv;
import core.thread;
shared class Msg
{
string value;
Msg next = null;
Tid from;
View string-mixin-runtime-error.d
import std.stdio;
T eval( string op , T )( T a , T b ) {
return mixin( q{a} ~ op ~ q{b} );
}
unittest {
writeln( eval!q{/}( 123 , 0 ) );
}
@nin-jin
nin-jin / coroutine.d
Last active Oct 9, 2015
Sorting comparison
View coroutine.d
import vibe.core.core;
import core.time;
import std.stdio;
int counter;
void say( string name ) {
for ( int i = 0 ; i < 3; i++ ) {
sleep( 100.msecs );
writeln( ++counter , " " , name );
@nin-jin
nin-jin / gist:13297c8723ecf4516dda
Last active Aug 29, 2015
Инкапсуляция и сокрытие
View gist:13297c8723ecf4516dda
/**
* Инкапсуляция
*
* @class Greeter1
*/
var Greeter1 = function(){}
/**
* Генерирует прикольное имя
*
View example.jin.atom.js
var userData = $jin.atom({ pull: function( ){
setTimeout( function( ){
userData.put({ name: 'User', time: Date.now() })
}, 1000 )
}})
userData
.then( function( val ){
View comments
Содержимое удалено по требованию правообладателя.
You can’t perform that action at this time.