Skip to content

Instantly share code, notes, and snippets.

View andresilveirah's full-sized avatar
💭
🤖

André Herculano andresilveirah

💭
🤖
View GitHub Profile
@andresilveirah
andresilveirah / todos.json
Created April 29, 2017 19:24
an attempt to use gist as an data store
{
"todos": [
{
"id": "fa7639c3-c19d-4038-9ac3-10ddc816074b",
"text": "test",
"completed": false
},
{
"id": "7691c444-b37d-44ad-aeaa-5ecaf5f2fc79",
"text": "hellow",
@andresilveirah
andresilveirah / lost_n_found.txt
Last active March 24, 2017 10:38
Search on the lost and found Berlin
http://fundsuche02.kivbf.de/MyApp.asp?wci=FundHeader&Mdt=berlin-ZFB&format=&PLZ=10999&KM=100&DATUM=20.03.2017&VOLLSUCHE=geldbeutel
26|08|braun|Führerschein|Theresa|Tobollik|1991|1989|Andre|Herculano|TK|BMW|Babbel
@andresilveirah
andresilveirah / map_exercise.exs
Created January 17, 2017 13:00
An exercise to implement map, reduce and other iterating functions
defmodule Map do
def map([], _), do: []
def map([head|tail], fun), do: [fun.(head) | map(tail, fun)]
def reduce([], acumulator, _), do: acumulator
def reduce([head|tail], acumulator, fun), do: reduce(tail, fun.(head, acumulator), fun)
def mapsum(list, fun) do
map(list, fun)
|> reduce(0, &(&1 + &2))
@andresilveirah
andresilveirah / specs_times.sh
Created November 17, 2016 14:42
A uber ugly script to compute how much time each kind of specs are taking.
#!/bin/bash
echo "spec_type,examples,time" > specs_times.csv
for spec_type in "helpers" "models" "features" "services" "observers" "policies" "validators" "routing" "controllers" "serializers"
do
total_time=0
examples=$(gtime --format="%e" -o time_output.txt bundle exec rake SPEC=spec/$spec_type 2>/dev/null | grep 'examples' | cut -d" " -f1)
real_time=`cat time_output.txt`
total_time=$(echo "scale=3; $total_time + $real_time" | bc -l)
@andresilveirah
andresilveirah / underscorify.js
Created May 10, 2016 13:25
A short helper to 'underscorify' strings and objects (taking nesting into account). It uses underscore (though vanilla js shouldn't be difficult) and ES6 syntax.
import _ from 'underscore';
// Convert fooBar to foo_bar
const underscoreCase = function(str) {
return str.replace(/([a-z])([A-Z]+)/g, function(terms) {
return terms[0] + '_' + terms[1].toLowerCase();
});
};
const underscorify = function(stringOrObject) {
@andresilveirah
andresilveirah / counter_reduxy_react.js
Created February 22, 2016 14:01
A (ultra) simple Counter app using Redux and React.
import {createStore} from 'redux';
import React from 'react';
import ReactDOM from 'react-dom';
// the reducer is a pure function which is the responsible for changing
// the state of the application (without mutating the parameters)
const counter = (state = 0, action) => {
switch (action.type) {
case 'INCREMENT':
return state + 1;
@andresilveirah
andresilveirah / counter_reduxy.js
Last active February 22, 2016 13:22
A (ultra) simple implementation of a Redux app using the ES6 syntax.
// A crude implementation of a Redux store
// It keeps track of the state of the application and calls the listeners
// whenever there's a action dispatch
const createStore = (reducer) => {
let state;
const listeners = [];
const getState = () => state;
const dispatch = (action) => {