Skip to content

Instantly share code, notes, and snippets.

View diogovk's full-sized avatar

Diogo Kersting diogovk

  • Astra Finance
  • Jaraguá do Sul - SC - Brazil
View GitHub Profile
@diogovk
diogovk / GAE_SDK.xml
Created May 20, 2020 15:08
project_dir/.idea/libraries/GAE_SDK.xml
<component name="libraryTable">
<library name="GAE_SDK" type="python">
<CLASSES>
<root url="file:///opt/google-cloud-sdk/platform/google_appengine" />
<root url="file:///opt/google-cloud-sdk/platform/google_appengine/lib/django-1.5" />
<root url="file:///opt/google-cloud-sdk/platform/google_appengine/lib/jinja2-2.6" />
<root url="file:///opt/google-cloud-sdk/platform/google_appengine/lib/webapp2-2.5.2" />
<root url="file:///opt/google-cloud-sdk/platform/google_appengine/lib/protorpc-1.0" />
</CLASSES>
<SOURCES />
@diogovk
diogovk / phoenix_belongs_to_catch
Last active November 30, 2018 21:31
protocol Ecto.Queryable not implemented for <Module>, the given module does not exist
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
timestamps
end
// program_start
fd_log = open("logfile.log")
fn log(msg) {
fd_log.write(msg)
fd_log.flush()
}
@diogovk
diogovk / get_by.ex
Last active May 25, 2016 19:48
mini select implementation
def get_by(module, params) do
Enum.find all(module), fn map ->
Enum.all?(params, fn {key, val} -> Map.get(map, key) == val end)
end
end
@diogovk
diogovk / Zip and Streams demonstration.ex
Created May 12, 2016 18:34
Zip and Streams demonstration
iex(1)> jump=4
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)> Enum.zip(s, items)
[{0, "aba"}, {4, "cate"}, {8, "dood"}]
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)
defp sign_in(%User{password_digest: password_digest, id: user_id}, password, conn) do
if checkpw(password, password_digest) do
conn
|> put_session(:current_user, user_id)
|> put_flash(:info, "Sign in successful!")
|> redirect(to: page_path(conn, :index))
else
sign_in(nil, nil, conn)
end
end
defmodule M do
def add(x, y) do
x + y
end
end
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
### 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');
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
end
IO.inspect(Stuff.inlist([1,2,3],1))