Skip to content

Instantly share code, notes, and snippets.

View samoshkin's full-sized avatar

Alexey Samoshkin samoshkin

View GitHub Profile
@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 / 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 / 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;
// inspired by this http://stackoverflow.com/a/12506613
// + emit SIGINT, and handle "exit" event
var stdin = process.stdin;
// without this, we would only get streams once enter is pressed
stdin.setRawMode( true );
// resume stdin in the parent process (node app won't quit all by itself
// unless an error or process.exit() happens)
@samoshkin
samoshkin / constructor_function_as_class.js
Created December 27, 2012 01:03
Constructor function as class in JavaScript.
// type declaration
var A = makeType({
init: function(x, y){
this.x = x;
this.y = y;
},
hello: function(){
console.log(this.x, this.y)
}
@samoshkin
samoshkin / prototype_as_class.js
Created December 27, 2012 01:01
Prototype as class in Javascript.
// type declaration
var A = makeType({
init: function(x, y){
this.x = x;
this.y = y;
},
hello: function(){
console.log(this.x, this.y)
}
@samoshkin
samoshkin / gist:2704886
Created May 15, 2012 20:29
Creating method overloads in JS using Function.length
function addMethod(object, name, fn){
// Save a reference to the old method
var old = object[ name ];
// Overwrite the method with our new one
object[ name ] = function(){
// Check the number of incoming arguments,
// compared to our overloaded function
if ( fn.length == arguments.length )
// If there was a match, run the function
@samoshkin
samoshkin / JS and jQuery learning resources
Created February 16, 2012 22:24
JS and jQuery learning resources
JavaScript learning resources.
Starting point for those, who have already learned JS, but forgotten. Good article. Quite compact.
https://developer.mozilla.org/en/JavaScript/A_re-introduction_to_JavaScript
Question: what's the best learning source on JS. Some answers.
http://stackoverflow.com/questions/11246/best-resources-to-learn-javascript
http://stackoverflow.com/questions/2687566/learning-javascript-in-one-weekend
http://net.tutsplus.com/tutorials/javascript-ajax/the-best-way-to-learn-javascript/
@samoshkin
samoshkin / gist:1446254
Created December 8, 2011 06:08
tdd-time-to-live-class-tests
[TestFixture]
public class TimeToLiveTests
{
[Test]
public void never_expiring_ttl_should_not_expire_at_relative_time()
{
TimeToLive.CreateNeverExpiring().ExpiresAtRelativeTime.Should().BeFalse();
}
[Test]
@samoshkin
samoshkin / gist:1422969
Created December 2, 2011 11:48
Find common root node for given nodes in a tree
public class TreeAnalyzer
{
public Node FindCommonRoot(IEnumerable<Node> nodes)
{
var walkedNodes = new HashSet<Node>();
var branches = nodes.ToList();
int nextIterationBranchRangeStartIndex = 0;
do
{
for (int i = nextIterationBranchRangeStartIndex; i < branches.Count; i++)