Skip to content

Instantly share code, notes, and snippets.

View angelikatyborska's full-sized avatar

Angelika Tyborska angelikatyborska

View GitHub Profile
@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...>}`.
@mixin button_reset {
background: none;
border: 0;
border-radius: 0;
-webkit-appearance: none;
padding: 0;
text-align: inherit;
color: inherit;
&:active {
@mixin sr_only() {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0,0,0,0);
border: 0;
text-transform: unset;
@angelikatyborska
angelikatyborska / index.ts
Created March 24, 2023 09:52
TipTap recipes
// Copy the HTML of the current selection
import { getHTMLFromFragment } from "@tiptap/core";
import { Fragment, Node } from "prosemirror-model";
getHTMLFromFragment(
editor.view.state.selection.content().content,
editor.schema
)
// Copy the text of the current selection
@angelikatyborska
angelikatyborska / index.ts
Last active February 16, 2023 16:20
TypeScript tasks
// Task 1:
// copy-paste start ----------------------------------------
// TODO: define function argument type
function addOne(numberOrNumbers) {
if (typeof numberOrNumbers === 'number') {
return numberOrNumbers + 1
} else {
@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
@angelikatyborska
angelikatyborska / index.html
Last active January 19, 2023 21:52
Providing custom error messages for built-in HTML5 form validation
<!DOCTYPE html>
<html lang="en">
<head>
<title>Form Validation</title>
<style>
body { padding: 10px; }
</style>
</head>
<body>
<form>
@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);
}
}
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
@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