Skip to content

Instantly share code, notes, and snippets.

View gyzerok's full-sized avatar
🏠
Working from home

Fedor Nezhivoi gyzerok

🏠
Working from home
View GitHub Profile
@igstan
igstan / state-monad.coffee
Created April 22, 2011 11:57
State Monad in CoffeeScript
push = (element) -> (stack) ->
newStack = [element].concat stack
{value: element, stack: newStack}
pop = (stack) ->
element = stack[0]
newStack = stack.slice 1
{value: element, stack: newStack}
bind = (stackOperation, continuation) -> (stack) ->
@igstan
igstan / state-monad.js
Created May 1, 2011 23:09
State Monad in JavaScript
var push = function (value) {
return function (stack) {
var newStack = [value].concat(stack);
return { value:undefined, stack:newStack };
};
};
var pop = function () {
return function (stack) {
var value = stack[0];
@igstan
igstan / fp.md
Created June 14, 2011 14:41
Patterns and idioms in functional languages

I'll throw my opinion in here, but take it with a pretty large grain of salt as I've done no professional development in a functional language yet. Just tinkering with (quite a few of) them in my spare time. Some of the patterns I spotted are irrespective of type systems (static, dynamic).

  • lists, sequences or similar primitives are ubiquitous
  • abstract away duplicate code using higher-order functions
  • no iteration constructs, recursion is the only way to traverse lists
  • watch out your recursion, be sure it's tail-recursive
  • abstract over this tail-recursive pattern with a higher-order function: foldLeft or foldRight. So, know your language's equivalent of foldLeft/foldRight and prefer these over explicit recursion.
  • abstract over folds in an even more general way and provide folding functions for arbitrary data structures, not just list, e.g., trees.
  • provide a few convenience higher-order functions (implementable using fold) like: map, filter, any/some, all/every, zip, `zipWith
@jpoehls
jpoehls / node-cluster-messaging.js
Created March 29, 2012 01:48
Simple message passing between cluster master and workers in Node.js
var cluster = require('cluster');
if (cluster.isWorker) {
console.log('Worker ' + process.pid + ' has started.');
// Send message to master process.
process.send({msgFromWorker: 'This is from worker ' + process.pid + '.'})
// Receive messages from the master process.
@igstan
igstan / anonymous-recursion.js
Created April 27, 2012 19:14
Anonymous recursion in JavaScript
(function privateName(i) {
if (i === 0)
return;
console.log(i);
privateName(i - 1);
})(5);
@MohamedAlaa
MohamedAlaa / tmux-cheatsheet.markdown
Last active March 28, 2024 04:34
tmux shortcuts & cheatsheet

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
@staltz
staltz / introrx.md
Last active March 26, 2024 00:52
The introduction to Reactive Programming you've been missing
/* Name of Gist */
@evancz
evancz / Guidelines.md
Last active October 17, 2023 05:36
Some thoughts on how to have nicer discussions online

Towards Discussion Guidelines

I personally like to have discussions in the spirit of the Socratic method. Instead of declaring my opinion, I ask a relevant question. How about this situation? What about this case? This has two possible outcomes.

  1. The other person explains to me how things work in that case. I realize that I misunderstood, and we both come out enriched and in agreement.
  2. The other person realizes that those situations are not covered. They realize they misunderstood, and we both come out enriched and in agreement.

In both cases, it could have been a conflict, egos crashing together. But by asking questions, it becomes a collaboration to find the best answer. Even the simple act of asking a question in the first place says, "I care what you have to say, we can agree on this." That said, I have noticed that it is definitely still possible for things to go wrong within this framework. How can this happen?

There was a passage from [The

@ericelliott
ericelliott / essential-javascript-links.md
Last active February 24, 2024 17:28
Essential JavaScript Links