Skip to content

Instantly share code, notes, and snippets.

View velosipedist's full-sized avatar

Nick Konev velosipedist

View GitHub Profile
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@velosipedist
velosipedist / when.tsx
Created March 18, 2020 13:40
Conditional factory to replace `switch(true){}` in functional style
type Predicate<T> = (x: T) => boolean;
/**
* Usage:
* ```typescript
* const factory = when(something)
* .match( (x) => someLogicReturningTrue )
* .then( () => anyLogicToProduceResult )
* .byDefault( () => defaultLogicWhenNoMatches )
*
@velosipedist
velosipedist / reduce-reducers.js
Created September 17, 2019 09:34
Simplified reduce-reducers version, without any extra arguments supported
const rootReducer = (...reducers) => {
return (stateInit, action) => {
return reducers.reduce(
(state, reducer, at) => {
return reducer(state, action) || state
},
stateInit
);
}
};
@velosipedist
velosipedist / chmod.php
Last active January 2, 2016 17:59
Chmod over all dirs & files separately, when no ssh around
<?php
`cd "../.."; chmod 777 $(find ./* -type d); chmod 666 $(find ./* -type f)`;
@velosipedist
velosipedist / FileStreamWrapper.php
Created December 26, 2013 08:12
Stream wrapper around existing file
<?php
namespace velosipedist\sami\translator;
/**
* Implements necessary methods for use with stream_wrapper_register($this->protocol, FileStreamWrapper)
* There is only needed method to implement — process()
*/
abstract class FileStreamWrapper
{
/**
# PLUGIN MEDIATOR FOR DOC-BASED KEYS
class docStreamWrapper
# ... garbage
def getContents(filename)
return translator.translateFile(filename.withoutProtocol 'doc://')
end
end
# PLUGIN MEDIATOR FOR SIGNATURE BASED KEYS
class classVisitor
@velosipedist
velosipedist / var_debug.php
Last active December 31, 2015 22:29
Php var_dump() analog for console output, from this post: http://www.leaseweblabs.com/2013/10/smart-alternative-phps-var_dump-function/
<?php
function var_debug($variable,$strlen=100,$width=25,$depth=10,$i=0,&$objects = array())
{
$search = array("\0", "\a", "\b", "\f", "\n", "\r", "\t", "\v");
$replace = array('\0', '\a', '\b', '\f', '\n', '\r', '\t', '\v');
$string = '';
switch(gettype($variable)) {
case 'boolean': $string.= $variable?'true':'false'; break;
@velosipedist
velosipedist / emoji-img.html
Last active December 30, 2015 11:58
github emoji evrywhere
<img width=24 src=//github.global.ssl.fastly.net/images/icons/emoji/confused.png />
@velosipedist
velosipedist / todo.php
Last active December 28, 2015 10:49
Web script that exctracts 'todo' comments or all of comments from given dir. Use only on local machine! Unsafe!
<?php
//todo use composer global vendor path
require('c:\Users\user\AppData\Roaming\Composer\vendor\autoload.php');
use Underscore\Types\Arrays;
use Underscore\Types\String;
use CallbackFilterIterator as CI;
use RecursiveDirectoryIterator as DI;
use RecursiveiteratorIterator as RI;
use RecursiveRegexIterator as REI;
@velosipedist
velosipedist / ordered-lists.less
Last active December 27, 2015 20:29
HTML Ordered lists custom marker using CSS and `:before` pseudo-class
ol {
counter-reset: custom-counter-name; // any name, use afterwards for incrementing counter
// counter-reset: custom-counter-name 1; // can be started from custom index
li{
list-style:none;
counter-increment: custom-counter-name;
}
li:before {
content: "[" counter(custom-counter-name) "]";