Skip to content

Instantly share code, notes, and snippets.

View joeljuca's full-sized avatar
👨‍💻
Working on smt new

Joel Jucá joeljuca

👨‍💻
Working on smt new
View GitHub Profile
defmodule Sorteio do
@moduledoc false
@people """
Fernando Collor
Fernando Henrique Cardoso
Luiz da Silva
"""
def people do
# lib./my_app/entries.ex
defmodule MyApp.Entries do
alias MyApp.Entry
# Aqui, eu espero erros serem retornados (como tuplas)
# ao invés de serem lançados (com throw, etc.)
def create_entry(attrs \\ %{}) do
%Entry{}
|> Entry.changeset(attrs)
|> Repo.insert()
// ==UserScript==
// @name MDN always in en-US
// @version 1
// @grant none
// @match https://developer.mozilla.org/*
// @run-at document-start
// ==/UserScript==
(function () {
const url = document && document.location && document.location.host;
defmodule ListOps do
# Please don't use any external modules (especially List or Enum) in your
# implementation. The point of this exercise is to create these basic
# functions yourself. You may use basic Kernel functions (like `Kernel.+/2`
# for adding numbers), but please do not use Kernel functions for Lists like
# `++`, `--`, `hd`, `tl`, `in`, and `length`.
@spec count(list) :: non_neg_integer
# def count(l), do: count(0, l)
# defp count(counter, []), do: counter
const FruitList = (() => {
// Aqui, PRODUCT_LABELS passa a existir apenas dentro desse bloco,
// o que na prática funciona igual a uma closure.
const PRODUCT_LABELS = {
456: { single: "Apple", plural: "Apples" },
123: { single: "Banana", plural: "Bananas" },
789: { single: "Oranges", plural: "Orangess" },
};
// O fato do nome interno ser o mesmo do nome externo é apenas para
@joeljuca
joeljuca / twitter_client.ex
Last active May 23, 2020 02:29 — forked from allefgomes/twitter_client.ex
Twitter Client in elixir
defmodule TwitterClient do
use Tesla
@token System.get_env("TWITTER_TOKEN")
plug(Tesla.Middleware.BaseUrl, "https://api.twitter.com")
plug(Tesla.Middleware.DecodeJson)
def get_tweets do
{:ok, response} = make_request()
person = :joel
given_person = :john
case given_person do
^person -> "Hi, Joel!"
person -> "Hi, #{person}!"
end
# => "Hi, john!"
type DocumentVersion = {
// CouchDB's own ID system
_id: string;
// Your document history ID - the same across all versions of a document
historyId: string;
// The _id of the ancestor document (undefined if first version)
parentId: string;
const Option = ({ option, onChange }) => {
return (
<label for="">
<option onChange={onChange} /> {option.title}
</label>
);
};
const Question = ({ question, onSubmit }) => {
return (
// IIFE - Immediately Invoked Function Expression
(function () {
"use strict"
console.log("I'm inside a private scope!")
})()