Skip to content

Instantly share code, notes, and snippets.

View KiaraGrouwstra's full-sized avatar
💁‍♀️

Kiara Grouwstra KiaraGrouwstra

💁‍♀️
  • BIJ1
  • Utrecht, the Netherlands
  • 16:51 (UTC +02:00)
View GitHub Profile
// This work is licensed under the Creative Commons Attribution 3.0 United States License. To view
// a copy of this license, visit http://creativecommons.org/licenses/by/3.0/us/ or send a letter
// to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA.
// Copyright 2009 John Tantalo <john.tantalo@gmail.com>
(function () {
// get selection
var selection = window.getSelection ? window.getSelection() :
document.getSelection ? document.getSelection() :
@KiaraGrouwstra
KiaraGrouwstra / alias.json
Last active July 19, 2016 13:12
PoC for OpenAPI's `$ref` (no spec changes) to demonstrate (1) detection of models semantic and (2) the info needed to link parameters to model properties
export const alias = {
"openapi": "2.0",
"paths": {
"/path1": {
"get": {
"parameters": [
{
"in": "path",
"name": "my_param",
"schema": { "$ref": "#/x-MyDefs/person_id" }
@KiaraGrouwstra
KiaraGrouwstra / iteramda.js
Created February 17, 2017 19:55
point-free ES6 iterator manipulation
// install repos: https://github.com/jb55/javascript-iterators/wiki/Registry
const iterator = R.map({
map: require('map-iterator'),
filter: require('filter-iterator'),
groupBy: require('groupby-iterator'),
sortBy: require('sortby-iterator'),
concat: require('concat-iterator'),
skip: require('skip-iterator'),
take: require('take-iterator'),
@KiaraGrouwstra
KiaraGrouwstra / crudOpenApiEndpoints.js
Last active April 5, 2017 11:05
generate crud endpoints for Swagger/OpenAPI
let R = require('ramda');
const up = (s) => s[0].toUpperCase() + s.substring(1).replace(/\-(\w)/, (match, letter) => letter.toUpperCase());
// JSON.stringify(crudOpenApiEndpoints({ single: 'app' }))
function crudOpenApiEndpoints ({ single, plural = single + 's', id = 'id', type = 'integer' }) {
let $ref = `#/definitions/${up(single)}`;
let resp = (schema) => ({ description: 'OK', schema });
let responses = { 204: resp({}) }; // empty non-GET response
let idPar = { name: id, in: 'path', required: true, type };
var R = require('ramda');
var deps = R.pipe(
R.match(/Depends: ([\w-]+)/g),
R.map(R.replace('Depends: ', '')),
R.join(' '),
R.concat('sudo apt-get install '),
);
/*
@KiaraGrouwstra
KiaraGrouwstra / patch-style.js
Last active August 23, 2017 07:51
Patch Style: get the CSS snippet needed to give one element the style of another
// get the CSS snippet needed to give one element the style of another
var R = require('ramda');
var getPx = (str) => /(\d+)\s*px/g.test(str) ? Number(str.replace(/[^\d]/g, '')) : null;
var px2rem = R.curry((base, str) => str.replace(/(\d+)\s*px/g, (match, px) => Number(px)/base + 'rem'));
var base = getPx(getComputedStyle(document.documentElement).fontSize);
var toRem = px2rem(base);
var patchStyle = (fromEl, toEl, asRem = false) => {
let [styles, stylesTo] = [fromEl, toEl].map(getComputedStyle);
let css = R.pipe(
@KiaraGrouwstra
KiaraGrouwstra / docker-alias.sh
Created May 25, 2018 22:54
hide docker (run commands thru docker as if they were installed locally)
function docker_alias () {
file=$1
img=$2
[[ "${3+set}" = set ]] && tag=$3 || tag="latest"
[[ "${4+set}" = set ]] && cmd=$4 || cmd=$file
printf "docker images | grep $img > /dev/null || docker pull $img:$tag\nid=\`docker images | grep -E "$img" | awk '{print \$3}'\`\ndocker run \$id $cmd \$@" | sudo tee /usr/bin/$file > /dev/null
sudo chmod +x /usr/bin/$file
}
# example usage:
sudo ~/Android/Sdk/platform-tools/fastboot flash system ./SYSTEM.img
sudo ~/Android/Sdk/platform-tools/fastboot flash boot ./BOOT.img
sudo ~/Android/Sdk/platform-tools/fastboot flash recovery ./RECOVERY.img
sudo ~/Android/Sdk/platform-tools/fastboot flash cust ./CUST.img
sudo ~/Android/Sdk/platform-tools/fastboot flash cache ./CACHE.img
sudo ~/Android/Sdk/platform-tools/fastboot flash userdata ./USERDATA.img
sudo ~/Android/Sdk/platform-tools/fastboot reboot
@KiaraGrouwstra
KiaraGrouwstra / twitch.sh
Created September 14, 2018 14:13
stop-gap solution to ODS Studio
STREAM_KEY=`cat ~/.twitch_key`
INRES=`xwininfo -root | awk '/geometry/ {print $2}'i` # input resolution
OUTRES="1280" # output resolution horizontal. vertical is calculated. screen width 1920.
FPS="10" # target FPS
GOP="20" # i-frame interval, should be double of FPS,
GOPMIN="10" # min i-frame interval, should be equal to fps,
THREADS="2" # max 6
CBR="1000k" # constant bitrate (should be between 1000k - 3000k)
QUALITY="ultrafast" # one of the many FFMPEG preset, e.g. ultrafast, veryfast
AUDIO_SRATE="44100"
@KiaraGrouwstra
KiaraGrouwstra / elixir.ex
Created September 14, 2018 15:37
scraping with elixir
# Agent:
# static:
# declare
defmodule Mix.TasksServer do
def start_link do
Agent.start_link(fn -> HashSet.new end, name: __MODULE__)
end
def put_task(task, project) do
item = {task, project}