Skip to content

Instantly share code, notes, and snippets.

View simonewebdesign's full-sized avatar
🇺🇦
💙 💛

Simone Vittori simonewebdesign

🇺🇦
💙 💛
View GitHub Profile
@simonewebdesign
simonewebdesign / main.js
Created September 25, 2017 10:11
Useful JS functions: camelize and parameterize
// Converts 'foo-bar' to 'fooBar'
// Credits: https://stackoverflow.com/a/6661012
export function camelize(str) {
return str.replace(/-([a-z])/g, g => g[1].toUpperCase());
}
// Converts 'fooBar' to 'foo-bar'
// Credits: https://gist.github.com/youssman/745578062609e8acac9f
export function parameterize(str) {
@simonewebdesign
simonewebdesign / open_pr.fish
Created August 31, 2017 13:26
Fish shell function to open a pull request on BitBucket
# fill the dots with proper information
function open_pr
set commit_info (git log -1 --pretty=%B)
set title (echo $commit_info | sed -n '1p')
set description (echo $commit_info | tail -n +3 | sed -E ':a;N;$!ba;s/\r{0,1}\n/ \\n/g')
set source_branch (git rev-parse --abbrev-ref HEAD)
set destination_branch develop
set repo_full_name "foo/bar"
set reviewers "[ { \"username\": \"someusername\" }, ... ]"
.text
main:
li $t1, 1 # load immediate value 1 into $t1
add $t0, $t1, 2 # $t1 + 2 and put result into $t0
li $v0, 10 # 10 is the the exit syscall num
syscall
@simonewebdesign
simonewebdesign / example.erl
Created March 26, 2017 16:08
tail-recursive sum in Erlang and LFE
sum(L) -> sum(L,0).
sum([], Total) -> Total;
sum([H|T], Total) -> sum(T, H+Total).
@simonewebdesign
simonewebdesign / gpg.md
Last active November 17, 2020 18:58
My GPG Cheatsheet

GPG Getting Started

Initial setup - Make sure you installed:

brew install gnupg pinentry-mac

You also have to do:

export GPG_TTY=$(tty)
@simonewebdesign
simonewebdesign / arrayMap.js
Created January 26, 2017 10:01
JavaScript implementation of Array#map with Array#reduce
function arrayMap(arr, fn) {
return arr.reduce(function (prev, current) {
return prev.concat(fn(current));
}, []);
};
@simonewebdesign
simonewebdesign / gameoflife.ex
Last active January 7, 2017 18:07
Game of Life 2D list
# Game of life
# Goal is to have a 2D list that looks like:
[ [false, false, true, false, false],
[true, true, false, false, false],
...
]
# data is a list of coordinates {row, col} where {0,0} is the top-left origin
data = [{0,1}, {2,3}, {3,4}, {4,4}]
@simonewebdesign
simonewebdesign / test.ex
Created January 7, 2017 11:54
Ways of looping through a collection/enumerable in Elixir
iex(6)> for _ <- 1..10 do
...(6)> end
[nil, nil, nil, nil, nil, nil, nil, nil, nil, nil]
iex(7)> Enum.map(1..10, fn _ -> end)
warning: an expression is always required on the right side of ->. Please provide a value after ->
iex:7
[nil, nil, nil, nil, nil, nil, nil, nil, nil, nil]
def calc_next_grid(grid) do
Enum.reduce(alive_plus_neighbors(grid), MapSet.new, fn({x, y}, grid2) ->
is_alive = MapSet.member?(grid, {x, y})
num_neighbors = count_neighbors(grid, {x, y})
if should_live?(is_alive, num_neighbors) do
MapSet.put(grid2, {x, y})
else
grid2
end
@simonewebdesign
simonewebdesign / hosts
Created November 26, 2016 20:35
Ban these domains
# /etc/hosts
# Ad servers
127.0.0.1 101com.com
127.0.0.1 101order.com
127.0.0.1 123found.com
127.0.0.1 180hits.de
127.0.0.1 180searchassistant.com
127.0.0.1 1x1rank.com