Skip to content

Instantly share code, notes, and snippets.

@tastywheat
tastywheat / elixir-connect-nodes.ex
Last active April 8, 2016 21:57
elixir connecting nodes
# iex --sname b1 --cookie monster -S mix
# iex --sname b2 --cookie monster -S mix
# Node.connect(:"b1@localhost")
# http://www.brianstorti.com/getting-started-with-plug-elixir/
defmodule HelloPlug.Worker do
use GenServer
def start_link do
Plug.Adapters.Cowboy.http(MyPipeline, %{})
@tastywheat
tastywheat / What makes functional programming languages declarative as opposed to Imperative?
Last active March 19, 2016 18:18
What makes functional programming languages declarative as opposed to Imperative?
# http://programmers.stackexchange.com/questions/283989/what-makes-functional-programming-languages-declarative-as-opposed-to-imperative
```
The basic unit of an imperative program is the statement. Statements are executed for their side effects.
They modify the state they receive. A sequence of statements is a sequence of commands, denoting do this then do that.
The programmer specifies the exact order to perform the computation. This is what people mean by telling the computer
how to do it.
The basic unit of a declarative program is the expression. Expressions do not have side effects. They specify
a relationship between an input and output, creating a new and separate output from their input, rather than
@tastywheat
tastywheat / es-aggs.js
Created March 13, 2016 23:08
elasticsearch aggregation formula
{
query: {
filter: {...}
}
aggs: {
impressions: {...},
gender: {
@tastywheat
tastywheat / d3 notes
Last active February 18, 2016 15:02
d3 notes
# SVG group
https://www.dashingd3js.com/svg-group-element-and-d3js
Guides
https://www.dashingd3js.com/table-of-contents
@tastywheat
tastywheat / pmap.exs
Created January 20, 2016 13:03
elixir parallel map
defmodule Foo do
def map([], _func) do
[]
end
def map([head|tail], func) do
[func.(head) | map(tail, func)]
end
@tastywheat
tastywheat / validator5.js
Created January 14, 2016 03:24
validator attempt #5
var isPlainObject = require('lodash.isplainobject');
var reduce = require('lodash.reduce');
function validate (source, validatorMapping, path) {
var _path = path || [];
if (!isPlainObject(source)) { throw new Error('@source must be a plain object') }
if (!isPlainObject(validatorMapping)) { throw new Error('@validatorMapping must be a plain object') }
@tastywheat
tastywheat / capistrano-sshkit.rb
Created January 12, 2016 20:38
capistrano sshkit
require 'sshkit'
require 'sshkit/dsl'
on 'brian@someserverip' do
within "/opt/somewhere" do
puts capture(:pwd)
end
end
@tastywheat
tastywheat / uncaught-exception-email-notification.js
Created January 10, 2016 13:32
uncaught exception email notification
var nodemailer = require('nodemailer')
var transport = nodemailer.createTransport('SMTP', { // [1]
service: "Gmail",
auth: {
user: "[email protected]",
pass: "userpass"
}
})
if (process.env.NODE_ENV === 'production') { // [2]
@tastywheat
tastywheat / server-http-persistent-connection-stream.js
Created December 30, 2015 20:16
server http persistent connection stream
var express = require('express');
var app = express();
var server = app.listen(3005);
var id = 1;
app.get('/stream', function (req, res, next) {
var clearId = setInterval(function() {
@tastywheat
tastywheat / client-http-persistent-connection.js
Created December 30, 2015 20:15
client http persistent connection
import request from 'request';
import follow from 'follow';
// follow("http://127.0.0.1:5984/anything", function(error, change) {
// if(!error) {
// console.log("Got change number " + change.seq + ": " + change.id);
// }
// })
// request