Skip to content

Instantly share code, notes, and snippets.

View sorteio.ex
defmodule Sorteio do
@moduledoc false
@people """
Fernando Collor
Fernando Henrique Cardoso
Luiz da Silva
"""
def people do
View ecto-wtf.halp.ex
# 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()
View mdn-always-en-US.user.js
// ==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;
View list_ops.ex
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
View fruit-list.example.js
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 — forked from allefgomes/twitter_client.ex
Twitter Client in elixir
View twitter_client.ex
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()
View case-private-scopes.ex
person = :joel
given_person = :john
case given_person do
^person -> "Hi, Joel!"
person -> "Hi, #{person}!"
end
# => "Hi, john!"
View document-version.ts
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;
View react-components-sample.js
const Option = ({ option, onChange }) => {
return (
<label for="">
<option onChange={onChange} /> {option.title}
</label>
);
};
const Question = ({ question, onSubmit }) => {
return (
View iife.js
// IIFE - Immediately Invoked Function Expression
(function () {
"use strict"
console.log("I'm inside a private scope!")
})()