Skip to content

Instantly share code, notes, and snippets.

Avatar

Diogo Kersting diogovk

View GitHub Profile
@diogovk
diogovk / GAE_SDK.xml
Created May 20, 2020
project_dir/.idea/libraries/GAE_SDK.xml
View 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 />
View open_close vs keep_open.cpp
// 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
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)
end
end
@diogovk
diogovk / Zip and Streams demonstration.ex
Created May 12, 2016
Zip and Streams demonstration
View Zip and Streams demonstration.ex
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"}]
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
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
@diogovk
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
timestamps
end
View elixir_no_currying
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
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
end
IO.inspect(Stuff.inlist([1,2,3],1))
You can’t perform that action at this time.