Skip to content

Instantly share code, notes, and snippets.

# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "precise32"
config.vm.box_url = "http://files.vagrantup.com/precise32.box"
config.vm.provider "virtualbox" do |v|
v.customize ["modifyvm", :id, "--memory", 384]
end
@santosh79
santosh79 / fib
Last active August 29, 2015 14:11
The correct way of calculating a fib in erlang
my_fib(N) when N =< 0 -> -1;
my_fib(N) when N =< 1 -> 1;
my_fib(N) -> my_fib_acc(N, 2, 1, 1).
my_fib_acc(N, N, FibMinusOne, FibMinusTwo) -> FibMinusOne + FibMinusTwo;
my_fib_acc(N, I, FibMinusOne, FibMinusTwo) ->
my_fib_acc(N, I + 1, (FibMinusOne + FibMinusTwo), FibMinusOne).
@santosh79
santosh79 / tokenize
Created December 13, 2014 23:00
String Tokenize
my_tokens(Str, Token) ->
my_tokens(Str, Token, [], []).
my_tokens([], _, _, Words) ->
lists:reverse(Words);
my_tokens([H|T], Delim, Chars, Words) when [H] =:= Delim ->
my_tokens(T, Delim, [], [lists:reverse(Chars)|Words]);
my_tokens([H|T], Delim, Chars, Words) ->
my_tokens(T, Delim, [H|Chars], Words).
-module(url_checker).
-export([is_working_url/2, is_working_url_sync/1]).
-spec is_working_url(PidOfCaller:: pid(), UrlToCheck:: string()) -> ok.
is_working_url(Caller, Url) ->
IsWorkingUrl = is_working_url_sync(Url),
Caller ! {self(), Url, IsWorkingUrl},
ok.
-spec is_working_url_sync(UrlToCheck:: string()) -> boolean().
@santosh79
santosh79 / play
Created January 9, 2015 22:04
Counts character occurrences in a string
defmodule Play do
import String, only: [split: 2]
import Enum, only: [filter: 2]
def count_chars_in_string(string) do
string
|> String.split("")
|> gen_count_map %{}
end
@santosh79
santosh79 / simple_hello.ex
Created February 5, 2015 19:14
simple_hello.ex
a = "hello"
function stack() {
return [];
}
function add(stack, item) {
stack.push(item);
}
function pop(stack) {
return stack.pop();
function stack() {
var outerArgs = Array.prototype.slice.call(arguments);
return {
push: function(element) {
return stack.apply(this, outerArgs.concat([element]));
},
pop: function() {
var initialArguments = outerArgs.slice(0, (outerArgs.length - 2));
var poppedItem = outerArgs[outerArgs.length - 1];
return [stack.apply(this, initialArguments), poppedItem];
function brokenUrls(urls, cb) {
var brokenUrls = [];
var pending = urls.length;
urls.forEach(function(url) {
urlChecker.isValidUrl(url, function(isValid) {
if (!isValidUrl) { brokenUrls.push(url); }
if(--pending === 0) { cb([brokenUrls]) }
});
});
}