Skip to content

Instantly share code, notes, and snippets.

@scudelletti
scudelletti / composite_pattern.js
Last active August 29, 2015 14:09
Composite Pattern
// How To Use
// var categories = CategoryModule.Category.all();
// var categoryComposite = new CategoryModule.CategoryComposite('CategoryComposite', categories.categorias, null);
//
// var categoryComposities = categoryComposite.findByName('Bar');
//
// var originalCategories = categoryComposities.map(function(item) {
// return item.original;
// });
@scudelletti
scudelletti / vowels_count.clj
Last active August 29, 2015 14:16
Vowel Count using Clojure
(def vowels [\a \e \i \o \u])
(defn convert-to-num [letter]
(if (= (some #{letter} vowels) letter)
1
0)))
(defn count-vowels [phrase]
(reduce + (map convert-to-num (clojure.string/lower-case phrase))))
@scudelletti
scudelletti / count_words_loop.clj
Last active August 29, 2015 14:16
Count Words using Clojure - Loop and Map Reduce Way
(defn split-words
[phrase]
(clojure.string/split phrase #"\s"))
(defn count-words
[phrase word]
(let [words (split-words (clojure.string/lower-case phrase))
lower-case-word (clojure.string/lower-case word)]
(loop [head (first words)
tail (rest words)
@scudelletti
scudelletti / class_variable_example.rb
Last active August 29, 2015 14:17
Ruby Class Variable Examples without @@
# Ruby Class Variable Examples without @@
# http://www.sitepoint.com/class-variables-a-ruby-gotcha/
class Foo
def self.talk
puts 'Hey! I\'m talking'
end
end
class Bar
@scudelletti
scudelletti / lambda_calculus.rb
Last active November 22, 2016 11:54
If condition on lambda calculus
# Rules: A lamda always has 1 parameter, nothing more, nothing less
# Useful Content: https://en.wikipedia.org/wiki/Church_encoding
# Identity lambda
IDENTITY = ->x { x }
# True, returns the first argument
TT = ->x { ->y { x } }
# False, returns the last argument
@scudelletti
scudelletti / ssh_config
Last active April 22, 2016 10:27
Forward port on SSH
Host *.staging.something.com
User someuser
ForwardAgent yes
LocalForward localhost:43306 localhost:3306
LocalForward localhost:49200 localhost:9200
LocalForward localhost:49001 localhost:9001
@scudelletti
scudelletti / class_definition_in_specs.rb
Created May 27, 2016 07:21
How to avoid global constant in the specs
require 'spec_helper'
describe "Wow Coins" do
let(:klasz_class) do
Class.new do
attr_reader :title
def initialize(properties)
@title = properties[:title]
end
@scudelletti
scudelletti / Dockerfile
Last active June 21, 2017 16:26
Run GUI Linux Apps through Docker with xQuartz on MacOS
# How to Use
# open -a XQuartz
# socat TCP-LISTEN:6000,reuseaddr,fork UNIX-CLIENT:\"$DISPLAY\"
# docker build . -t ds-xclock
# docker run -e DISPLAY=YOUR_LOCAL_IP_HERE:0 -it ds-xclock
#
# Useful Links:
# https://github.com/moby/moby/issues/8710
# http://kartoza.com/en/blog/how-to-run-a-linux-gui-application-on-osx-using-docker/
@scudelletti
scudelletti / numbers_in_lambda_calculus.lisp
Last active December 10, 2018 10:21
Numbers in Lambda Calculus - Following Destroy All Software approach
;; Church Numbers
(setq zero (lambda (f) (lambda (x) x)))
(setq one (lambda (f) (lambda (x) (funcall f x))))
(setq two (lambda (f) (lambda (x) (funcall f (funcall f x)))))
;; Manual Calc
(funcall (funcall zero (lambda (x) (+ 1 x))) 0)
(funcall (funcall one (lambda (x) (+ 1 x))) 0)
(funcall (funcall two (lambda (x) (+ 1 x))) 0)
@scudelletti
scudelletti / export_env.sh
Created April 13, 2018 14:47
Export Env Variables stored on /etc/environment
# Loan Env Variables
while read line; do
export $(echo $line | sed 's/"//g')
done < /etc/environment