rails new my_app --rc=template.rc -m template.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
LINES=$(tput lines) | |
COLUMNS=$(tput cols) | |
declare -A snowflakes | |
declare -A lastflakes | |
clear |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule MyApp.YarnChecker do | |
use Credo.Check, | |
run_on_all: true, | |
category: :consistency, | |
base_priority: :high, | |
param_defaults: [ | |
package_json: "assets/package.json", | |
yarn_lock: "assets/yarn.lock", | |
packages: ["phoenix", "phoenix_html", "phoenix_live_view"] | |
], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule RequestCache do | |
@moduledoc """ | |
Simple ETS-based cache. | |
""" | |
use GenServer | |
@type t :: %{ttl: integer, invalidators: %{}} | |
@type cache_key :: any | |
@type cache_value :: any |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule MyApp.Foo do | |
@on_definition MyApp.SpecToCallback | |
@spec bar(String.t()) :: String.t() | |
def bar(foobar) do | |
impl().bar(foobar) | |
end | |
defp impl, do: Application.get_env(:my_app, :my_app_foo_impl, __MODULE__.DefaultImpl) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ name = 'string.quoted.other.sigil.live_view'; | |
comment = 'live_view sigil (allow for interpolation)'; | |
begin = '\s?(~L""")$'; | |
end = '^\s*("""[a-z]*)$'; | |
beginCaptures = { 0 = { name = 'punctuation.definition.string.begin.elixir'; }; }; | |
endCaptures = { 0 = { name = 'punctuation.definition.string.end.elixir'; }; }; | |
patterns = ( | |
{ include = 'text.elixir'; }, | |
{ include = 'text.html.basic'; }, | |
{ include = '#meta.embedded.line.elixir'; }, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Step 1 | |
def create_subscription(email, plan_id, payment_method_id) do | |
with %User{customer_id: nil, name: name} = user <- | |
Repo.get_by(User, email: email), | |
{:ok, %Stripe.Customer{id: customer_id}} <- | |
Stripe.Customer.create(%{ | |
name: name, | |
email: email, | |
payment_method: payment_method_id, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'taglib' | |
files_names = Dir["*.mp3"].sort | |
files_names.each do |file_name| | |
TagLib::MPEG::File.open(file_name) do |mp3_file| | |
## ID3 tag |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Day8 do | |
defmodule Node do | |
defstruct children_count: 0, metadata_count: 0, metadata: [], children: [] | |
def parse_header(numbers) do | |
{[children_count, metadata_count], numbers} = Enum.split(numbers, 2) | |
node = %Node{children_count: children_count, metadata_count: metadata_count} | |
{node, numbers} | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Polymer do | |
defstruct data: [] | |
def new do | |
%Polymer{} | |
end | |
def size(%Polymer{data: data}) do | |
data |> Enum.count() | |
end |
NewerOlder