Skip to content

Instantly share code, notes, and snippets.

View gunar's full-sized avatar

Gunar Gessner gunar

View GitHub Profile
@gunar
gunar / 00-lenovo-x1-5th-gen-thinkfan-setup.md
Created February 27, 2019 19:05 — forked from abn/00-lenovo-x1-5th-gen-thinkfan-setup.md
Fedora thinkfan configuration for Lenovo X1 Carbon (5th Gen)

Thinkfan Configuration Notes

This are notes for configuration thinkfan for Fedora. This configuration procedure was followed on a Lenovo Thinkpad X1 Carbon (5th Gen) running Fedora 25.

Non standard (default) configuration was required for this machine as the default sensors are not available. Eg: /proc/acpi/ibm/thermal does not exist for this model.

An annoted configuration file has been included below. However, there is no guarentee that this will work as-is on every machine.

Installation

dnf -y install thinkfan
@gunar
gunar / Dockerfile
Created November 5, 2018 19:02
Dockerfile
FROM alpine:latest
WORKDIR /usr/src/app
RUN apk add --no-cache --update 'nodejs~8' yarn
RUN yarn global add node-gyp
RUN export PATH=$PATH:./node_modules/.bin
# http://bitjudo.com/blog/2014/03/13/building-efficient-dockerfiles-node-dot-js/
ADD package.json yarn.lock ./
RUN yarn install -s --ignore-scripts
ADD . .
RUN yarn build
@gunar
gunar / release_heroku_image.sh
Last active November 5, 2018 18:57
release_heroku_image.sh
#!/bin/sh
http_code=$(curl -s -o out.json -w '%{http_code}' -n -X PATCH https://api.heroku.com/apps/$HEROKU_APP_NAME/formation \
-d "{
\"updates\": [
{
\"type\": \"web\",
\"docker_image\": \"$IMAGE_ID\"
}
]
@gunar
gunar / .zshrc
Created March 13, 2018 22:20
Help mocha find mocha.opts
m() {
# mocha default path is test/mocha.opts
file=$(readlink -f $1)
[ -f "test/mocha.opts" ] && (mocha $file)
[ -f "../../mocha.opts" ] && (cd ../../../ && mocha $file)
[ -f "../../../mocha.opts" ] && (cd ../../../../ && mocha $file)
[ -f "../../../../mocha.opts" ] && (cd ../../../../../ && mocha $file)
[ -f "../../../../../mocha.opts" ] && (cd ../../../../../../ && mocha $file)
[ -f "../../../../../../mocha.opts" ] && (cd ../../../../../../../ && mocha $file)
}
Verifying my Blockstack ID is secured with the address 1BGu3RMtzjXsaE3adDzdnkyrQMDNzovxnr https://explorer.blockstack.org/address/1BGu3RMtzjXsaE3adDzdnkyrQMDNzovxnr
@gunar
gunar / await-to-js-no-throw.js
Last active January 5, 2021 00:26
Async Control Flow without Exceptions nor Monads
'use strict'
const toUpper = async string => {
if (string === 'invalid') return [Error('Invalid input')]
return [null, string.toUpperCase()]
}
const errorHandler = () => { console.log('There has been an error. I\'ll handle it.') }
const print = console.log
const foo = async input => {
@gunar
gunar / irpf.js
Created September 11, 2017 12:01
IRPF
function aliquota(x) {
if (x < 22847.77) return 0
else if (x < 33919.81) return 7.5/100
else if (x < 45012.61) return 15/100
else if (x < 55976.16) return 22.5/100
else return 27.5/100
}
function aDeduzir(x) {
if (x < 22847.77) return 0
@gunar
gunar / circle.yml
Created August 17, 2017 19:59
CircleCI Publish to npm
dependencies:
pre:
- 'echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc'
override:
- yarn
machine:
environment:
# For yarn
PATH: "${PATH}:${HOME}/${CIRCLE_PROJECT_REPONAME}/node_modules/.bin"
@gunar
gunar / cycleSort.js
Created May 4, 2017 02:37
Cycle sort implemented in JavaScript
'use strict'
// ref https://en.wikipedia.org/wiki/Cycle_sort
const cycleSort = array => {
// last item will already be in place
for (let cycleStart = 0; cycleStart < array.length-1; cycleStart++) {
let item = array[cycleStart]
// find where to put the item
let pos = cycleStart
@gunar
gunar / exceptionsAndPromises.js
Created November 1, 2016 12:20
How to differentiate exceptions from rejections
// 1. Using rejections for both exceptions and rejections
foo(5)
.then(bar)
.catch(err => {
if (!(err instanceof MyError)) {{
// exception!
throw err
}
// else, process business logic error properly
})