Skip to content

Instantly share code, notes, and snippets.

View stefan-vatov's full-sized avatar
🦀
rock on

Stefan Vatov stefan-vatov

🦀
rock on
View GitHub Profile
@stefan-vatov
stefan-vatov / post-merge.sh
Last active June 13, 2021 03:30 — forked from sindresorhus/post-merge
[Post Merge Hook]
#/usr/bin/env bash
# MIT © Sindre Sorhus - sindresorhus.com
# git hook to run a command after `git pull` if a specified file was changed
# Run `chmod +x post-merge` to make it executable then put it into `.git/hooks/`.
changed_files="$(git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD)"
check_run() {
echo "$changed_files" | grep --quiet "$1" && eval "$2"
@stefan-vatov
stefan-vatov / codemods.sh
Created January 10, 2017 15:21 — forked from JamieMason/codemods.sh
Run some useful codemods together in bulk **hard-coded to run against `$pwd/src/app` currently**
#!/bin/bash
function codemods() {
echo "-----"
echo "Running $1 from https://github.com/JamieMason/codemods.git"
jscodeshift -t "${TMPDIR}codemods/transforms/$1.js" "$2"
}
function js_codemod() {
echo "-----"
@stefan-vatov
stefan-vatov / optimize.sh
Created August 21, 2017 17:52 — forked from ryansully/optimize.sh
image optimization script (pngcrush & jpegtran)
#!/bin/sh
# script for optimizing images in a directory (recursive)
# pngcrush & jpegtran settings from:
# http://developer.yahoo.com/performance/rules.html#opt_images
# pngcrush
for png in `find $1 -iname "*.png"`; do
echo "crushing $png ..."
pngcrush -rem alla -reduce -brute "$png" temp.png
@stefan-vatov
stefan-vatov / snippet.ex
Created June 13, 2021 03:20
[Ping clustered notes] #horde
{Task, fn -> ping_nodes() end}
defp ping_nodes() do
Process.sleep(1_000)
Node.list()
|> Enum.each(fn node ->
IO.puts("[#{inspect(Node.self())} -> #{inspect(node)}] #{inspect(Node.ping(node))}")
end)
ping_nodes()
end
@stefan-vatov
stefan-vatov / index.js
Created June 13, 2021 03:22
[Get youtube channel RSS]
(() => {
let getMeta = (itemProp) => {
let metas = document.getElementsByTagName('meta');
for (let i = 0; i < metas.length; i++) {
if (metas[i].getAttribute('itemprop') === itemProp) {
return metas[i].getAttribute('content');
}
}
@stefan-vatov
stefan-vatov / IValidators.ts
Created June 13, 2021 03:26
[Validation with folktale]
import { IBasicObject } from './objects';
export interface IValidator<T> {
run: IValidatorRun<T>;
concat: (other: IValidator<T>) => IValidator<T>;
}
export type ValidatorTypes = [] | undefined | string;
export type IValidatorRun<T> = (key: string, x: T, rec: IBasicObject) => IValidator<T>;
@stefan-vatov
stefan-vatov / index.ts
Created June 13, 2021 03:29
[Async Wrap]
export const asyncWrap = (promise: Promise<any>) =>
promise.then((res) => ({ res, error: null })).catch((error) => ({ res: null, error }));
@stefan-vatov
stefan-vatov / script.sh
Created June 23, 2021 18:14
[Check exit code of last command] #bash #shell
if [[ $? -eq 22 ]];
then
// code
else
// code
fi
@stefan-vatov
stefan-vatov / script.sh
Created August 29, 2021 19:17
[ffmpeg flac to alac]
ffmpeg -i "<name>.flac" -acodec alac "<name>.m4a"
@stefan-vatov
stefan-vatov / snippet.sh
Created September 28, 2021 11:53
[capture curl http code and result]
STATUSCODE=$(curl --silent --output result.txt --write-out "%{http_code}" --request GET URL)
cat result.txt
if test $STATUSCODE -ne 200; then
exit 1
fi