Skip to content

Instantly share code, notes, and snippets.

View angelikatyborska's full-sized avatar

Angelika Tyborska angelikatyborska

View GitHub Profile
@angelikatyborska
angelikatyborska / gist:6f7d2fe7df779ff87082af115093eda2
Created September 14, 2020 15:48
Count LOC in an Elixir project
git ls-files | egrep '\.erl|\.ex[s]$' | xargs cat | sed '/^$/d' | wc -l
@angelikatyborska
angelikatyborska / hello.md
Last active November 29, 2020 15:37
Exercism Elixir maintainers Slack channel welcome message

Hello!

So you want to help out with the Elixir track on Exercism? That's awesome! 💜

There are plenty of tasks that you can help with.

If you have any questions, if you're unsure where to start or you're stuck, do not hesitate to ask for help in our #maintaining-elixir Slack channel.

@angelikatyborska
angelikatyborska / myphoenixapp.service
Created March 10, 2021 18:37
Phoenix app serviced service file
# /etc/systemd/system/myphoenixapp.service
[Unit]
Description=Runner for My Phoenix App
After=network.target
StartLimitIntervalSec=500
StartLimitBurst=5
[Service]
WorkingDirectory=/path/to/myphoenixapp
@angelikatyborska
angelikatyborska / rpg.ex
Created August 15, 2021 09:35
Protocol consolidation vs mix test --no-compile
# 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)
@angelikatyborska
angelikatyborska / gettext_test.exs
Last active January 16, 2022 16:24
A unit test for Gettext translations that checks if the original and the translation use the same HTML tags. Uses Floki to parse HTML.
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
@angelikatyborska
angelikatyborska / gettext.ex
Last active March 11, 2024 13:50
A custom `gettext_with_link` macro for easily putting inline links into gettext strings
# Has one external dependency except for Gettext: https://github.com/rrrene/html_sanitize_ex
defmodule MyApp.Gettext do
@doc """
A helper for translations with links.
Pass in the translation string which must include
`%{link_start}`/`%{link_end}`. For multiple URLs, use
`%{link_start_<0,1,2...>}`.
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.:
@angelikatyborska
angelikatyborska / .zshrc
Last active May 30, 2022 09:35
Prevent yourself from using the wrong js package manager
npm() {
if [ -f yarn.lock ]; then
echo 'use yarn';
else
command npm $*;
fi
}
yarn() {
if [ -f package-lock.json ]; then
@angelikatyborska
angelikatyborska / index.js
Created September 30, 2022 10:34
Add event listeners to all possible events on an element
element = ...
listener = ...
for (const key in element) {
if(/^on/.test(key)) {
const eventType = key.substr(2);
element.addEventListener(eventType, listener);
}
}
@angelikatyborska
angelikatyborska / index.ts
Last active January 30, 2023 10:14
TypeScript notes
// 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