Skip to content

Instantly share code, notes, and snippets.

Diogo Kersting diogovk

View GitHub Profile
View open_close vs keep_open.cpp
// program_start
fd_log = open("logfile.log")
fn log(msg) {
diogovk / get_by.ex
Last active May 25, 2016
mini select implementation
View get_by.ex
def get_by(module, params) do
Enum.find all(module), fn map ->
Enum.all?(params, fn {key, val} -> Map.get(map, key) == val end)
diogovk / Zip and Streams demonstration.ex
Created May 12, 2016
Zip and Streams demonstration
View Zip and Streams demonstration.ex
iex(1)> jump=4
iex(2)> s = Stream.unfold(0, fn x -> {x, x+jump} end)
#Function<1.133682015/2 in Stream.unfold/2>
iex(3)> items = [ "aba", "cate", "dood"]
["aba", "cate", "dood"]
iex(4)>, items)
[{0, "aba"}, {4, "cate"}, {8, "dood"}]
View How to make multiple (indepedent) pull requests
in master:
# create and checkout new branch
git checkout -b my_feature_1
# work
<my_feature_1> git commit
# I'm ready to push feature_1
# check which remote you want to push to (in exemple below, origin)
View test.exs
defp sign_in(%User{password_digest: password_digest, id: user_id}, password, conn) do
if checkpw(password, password_digest) do
|> put_session(:current_user, user_id)
|> put_flash(:info, "Sign in successful!")
|> redirect(to: page_path(conn, :index))
sign_in(nil, nil, conn)
diogovk / phoenix_belongs_to_catch
Last active Nov 30, 2018
protocol Ecto.Queryable not implemented for <Module>, the given module does not exist
View phoenix_belongs_to_catch
defmodule Freshcards.Post do
use Freshcards.Web, :model
schema "posts" do
field :title, :string
belongs_to :user, Freshcards.User # right!
# belongs_to :user, User <-- wrong
View elixir_no_currying
defmodule M do
def add(x, y) do
x + y
1 |> M.add(2) |> IO.puts #=> 3
# add1 = 1|> add #=> illegal undefined function add/1
# Em certas linguagens isto faria um currying que é uma aplicação parcial de 1 na função add
View Grunt versus makefile
### Grunt Dependencias ###
"envify": "~1.2.1",
"grunt": "~0.4.4",
"grunt-browserify": "~1.3.2",
"grunt-contrib-watch": "~0.6.1",
"grunt-env": "~0.4.1"
#Note que não faz o uglify!
#### Grunt ####
var fs = require('fs');
View inimplementation.ex
defmodule Stuff do
def inlist([search_item|_tail], search_item), do: true
def inlist([_head|tail], search_item) , do: inlist(tail, search_item)
def inlist([], _), do: false
View gist:4bca024e23c9a715c41b
defmodule ListOps do
# Please don't use any external modules (especially List) in your
# implementation. The point of this exercise is to create these basic functions
# yourself.
# Note that `++` is a function from an external module (Kernel, which is
# automatically important`) and so shouldn't be used either.
@spec count(list) :: non_neg_integer
You can’t perform that action at this time.