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
# /etc/systemd/system/myphoenixapp.service | |
[Unit] | |
Description=Runner for My Phoenix App | |
After=network.target | |
StartLimitIntervalSec=500 | |
StartLimitBurst=5 | |
[Service] | |
WorkingDirectory=/path/to/myphoenixapp |
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
# test/rpg_test.exs | |
defmodule RPGTest do | |
use ExUnit.Case | |
alias RPG.{Edible, LoafOfBread} | |
describe "LoafOfBread" do | |
test "implements the Edible protocol" do | |
{:consolidated, modules} = Edible.__protocol__(:impls) |
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
const { spawnSync } = require('child_process') | |
const fs = require('fs') | |
const path = require('path') | |
const os = require('os') | |
const glob = require('glob') | |
// this loader "imports" a .pot file by compiling all of the .po files under the same domain | |
// into a JSON with translations that can be used by vue-gettext | |
// | |
// E.g.: |
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 MyAppWeb.GettextTest do | |
use ExUnit.Case | |
import MyAppWeb.Gettext | |
# A unit test for Gettext translations that checks if the original and the translation | |
# use the same HTML tags. | |
# | |
# Uses Floki to parse HTML. | |
describe "translations" do |
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
npm() { | |
if [ -f yarn.lock ]; then | |
echo 'use yarn'; | |
else | |
command npm $*; | |
fi | |
} | |
yarn() { | |
if [ -f package-lock.json ]; then |
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.Repo.Migrations.AddUuidOssp do | |
use Ecto.Migration | |
def up do | |
execute("CREATE EXTENSION IF NOT EXISTS \"uuid-ossp\" WITH SCHEMA public;") | |
end | |
def down do | |
execute("DROP EXTENSION \"uuid-ossp\";") | |
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
element = ... | |
listener = ... | |
for (const key in element) { | |
if(/^on/.test(key)) { | |
const eventType = key.substr(2); | |
element.addEventListener(eventType, listener); | |
} | |
} |
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<title>Form Validation</title> | |
<style> | |
body { padding: 10px; } | |
</style> | |
</head> | |
<body> | |
<form> |
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
// If I define a union type of strings and want to use it as a type for object keys: | |
type Food = 'Banana' | 'Berries' | |
const calorieCounts: { [index in Food]: number } = {} // <- NOT `index: Food` | |
// ---------- | |
// If I define an object and want to use its keys as a type: | |
// NOTE the object shouldn't have a type definition for this to work! | |
const planetYearsToEarthYears = { earth: 1, mercury: 0.24 } | |
type Planet = keyof typeof planetYearsToEarthYears |
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
// Task 1: | |
// copy-paste start ---------------------------------------- | |
// TODO: define function argument type | |
function addOne(numberOrNumbers) { | |
if (typeof numberOrNumbers === 'number') { | |
return numberOrNumbers + 1 | |
} else { |