Skip to content

Instantly share code, notes, and snippets.

View samoshkin's full-sized avatar

Alexey Samoshkin samoshkin

View GitHub Profile
@samoshkin
samoshkin / index.ts
Created July 27, 2016 14:31
Naive implementation of Redux pattern in RxJS
import { OpaqueToken } from '@angular/core';
import { Subject } from 'rxjs/Subject';
import 'rxjs/add/operator/do';
import 'rxjs/add/operator/scan';
import 'rxjs/add/operator/observeOn';
import { queue } from 'rxjs/scheduler/queue';
import { ReplaySubject } from 'rxjs/ReplaySubject';
export interface Action {
type: string;
@samoshkin
samoshkin / heathrow-to-london.hs
Created December 4, 2016 23:12
Algorithm to find best path from Heathrow to London. Exercise is taken from the book "Learn you a Haskell"
{-
Implementation of "Heathrow to London" algorithm
from a task in the book "Learn you a Haskell"
http://learnyouahaskell.com/functionally-solving-problems
Example input:
```
$ echo "50 10 30 5 90 20 40 2 25 10 8 0 " | tr ' ' '\n' | runhaskell heathrow-to-london.hs
```
@samoshkin
samoshkin / cloudSettings
Last active May 4, 2017 19:46
Visual Studio Code Sync Settings Gist
{"lastUpload":"2017-05-04T19:44:30.519Z","extensionVersion":"v2.7.0"}
@samoshkin
samoshkin / toggle_keybindings.tmux.conf
Last active February 5, 2024 02:26
tmux.conf excerpt to toggle on/off session keybindings and prefix handling
bind -T root F12 \
set prefix None \;\
set key-table off \;\
set status-style "fg=$color_status_text,bg=$color_window_off_status_bg" \;\
set window-status-current-format "#[fg=$color_window_off_status_bg,bg=$color_window_off_status_current_bg]$separator_powerline_right#[default] #I:#W# #[fg=$color_window_off_status_current_bg,bg=$color_window_off_status_bg]$separator_powerline_right#[default]" \;\
set window-status-current-style "fg=$color_dark,bold,bg=$color_window_off_status_current_bg" \;\
if -F '#{pane_in_mode}' 'send-keys -X cancel' \;\
refresh-client -S \;\
bind -T off F12 \
@samoshkin
samoshkin / remote.tmux.conf
Created November 25, 2017 19:04
remote specific tmux configuration
# show status bar at bottom for remote session,
# so it do not stack together with local session's one
set -g status-position bottom
# In remote mode we don't show "clock" and "battery status" widgets
set -g status-left "$wg_session"
set -g status-right "#{prefix_highlight} $wg_is_keys_off $wg_is_zoomed #{sysstat_cpu} | #{sysstat_mem} | #{sysstat_loadavg} | $wg_user_host | #{online_status}"
@samoshkin
samoshkin / generator_runner.js
Created January 15, 2018 20:02
Simple "generator + promise" runner routine. Write sync - execute async.
function r(genFn, context){
return function(...args){
const iter = genFn.apply(context || this, args);
return traverse(iter);
}
function traverse(iter){
return new Promise((res, rej) => {
function step(err, arg) {
@samoshkin
samoshkin / es-module-syntax.js
Created January 16, 2018 20:09
ES module syntax examples
// import a module with side-effect without any import bindings
import 'jquery';
// import the default export of a module
import $ from 'jquery';
// import a named export of a module
import { reduce } from 'underscore';
// import a named export to a different name
@samoshkin
samoshkin / js-to-primitive-internal.js
Created January 17, 2018 13:42
EcmaScript ToPrimitive internal operation pseudo-code
function ToPrimitive(input, preferredType){
switch (preferredType){
case Number:
return toNumber(input);
break;
case String:
return toString(input);
break
default:
@samoshkin
samoshkin / date-object-to-primitive-conversion.js
Created January 17, 2018 17:57
Date assumes string conversion as a default
let d = new Date();
// get string representation
let str = d.toString(); // 'Wed Jan 17 2018 16:15:42'
// get numeric representation, num of milliseconds since Unix epoch
let num = d.valueOf(); // 1516198542525
// compare with a string representation
// true because d is converted to same string
@samoshkin
samoshkin / es5-toprimitive-hooks.js
Created January 17, 2018 18:02
Custom toString() and valueOf() methods
var obj = {
prop: 101,
toString(){
return 'Prop: ' + this.prop;
},
valueOf() {
return this.prop;
}
};