Skip to content

Instantly share code, notes, and snippets.

View gunar's full-sized avatar

Gunar Gessner gunar

View GitHub Profile
class RowNotFound extends Error {
constructor() {
const message = `Row not found`;
super(message);
this.message = message;
this.name = 'RowNotFound';
}
}
function checkRowExists(row) {
@ChrisPenner
ChrisPenner / heyting-validation.js
Created August 23, 2017 14:32
Heyting Algebra Validation
const all = (...preds) => (obj) => preds.map(f => f(obj)).reduce((a, b) => a && b, true)
const any = (...preds) => (obj) => preds.map(f => f(obj)).reduce((a, b) => a || b, false)
const oneOf = (...preds) => (obj) => preds.map(f => f(obj)).reduce((a, b) => a ? !b : b, false)
const has = (prop) => (obj) => obj[prop] !== undefined
const not = (pred) => (obj) => !pred(obj)
const equals = (prop, val) => (obj) => obj[prop] === val
const implies = (f, g) => (obj) => !f(obj) || g(obj);
const validate = all(implies(has('selectedIndex'), equals('isOpen', true)))
@klzns
klzns / picture-in-picture.js
Last active July 2, 2018 15:11
Adicione esse script para abrir a transmissão da copa em picture in picture no Safari.
(function () {
var video = document.querySelector('video:not([title="Advertisement"])')
if (!video.webkitSupportsPresentationMode || typeof video.webkitSetPresentationMode !== 'function') {
console.error('Esse código só funciona no Safari!')
return
}
var scoreX = document.querySelector('.placar__equipes')
var button = document.createElement('button')
@benjamincharity
benjamincharity / circle.yml
Last active April 23, 2019 14:43
CircleCI deploy to NPM
machine:
node:
version: 6.9.5
dependencies:
pre:
- 'echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc'
test:
override:
- rm -rf $CIRCLE_ARTIFACTS/coverage
@zmalltalker
zmalltalker / README.org
Created July 20, 2012 08:55
Thinkpad fan control

Thinkpad fan control

My Thinkpad T400s kept shutting down when it was busy doing CPU intensive work. It turns out that the fan did not speed up to a high enough level to cool down the CPU, and I’d find messages in /var/log/messages stating that the CPU was dangerously hot.

Load the thinkpad_acpi module with manual fan control enabled

The first thing I did was to make it possible to manually control the fan speed. In order for this to work, the thinkpad_acpi kernel module needs to be loaded with a specific parameter. This can be

@ericelliott
ericelliott / cancellable-wait.js
Last active October 8, 2019 08:06
Cancellable wait -- an ES6 promise example
const wait = (
time,
cancel = Promise.reject()
) => new Promise((resolve, reject) => {
const timer = setTimeout(resolve, time);
const noop = () => {};
cancel.then(() => {
clearTimeout(timer);
reject(new Error('Cancelled'));
@gunar
gunar / curryNamed.js
Last active November 11, 2019 22:20
Currying Functions with Named Parameters in JavaScript
/**
* Currying Functions with Named Parameters.
* @gunar, @drboolean, @dtipson 2016
*
* Why does it return a thunk, though?
* Because in JS named arguments are opaque. There is no way of getting a function's named arguments list.
* e.g.
* const foo = function ({ a, b }) { }
* console.log(foo.arguments) // Throws. Ideally would return ['a', 'b'].
*
@mikaelz
mikaelz / rtc.lua
Created May 11, 2015 16:07
Awesome WM config for multimedia keys to control Spotify
awful.key({ }, "XF86AudioPlay", function () awful.util.spawn_with_shell("dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause") end),
awful.key({ }, "XF86AudioNext", function () awful.util.spawn_with_shell("dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Next") end),
awful.key({ }, "XF86AudioPrev", function () awful.util.spawn_with_shell("dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Previous") end)
@rjz
rjz / stdin-and-fs-stream.js
Created March 12, 2014 05:18
Streaming from stdin or a file
// Depends on `through`
//
// $ npm install through
//
// Usage:
//
// $ echo 'hello' | node stdin-and-fs-stream.js
// $ echo 'hello' > tmp && node stdin-and-fs-stream.js tmp
//
var fs = require('fs'),
@tirumaraiselvan
tirumaraiselvan / shim.js
Last active July 31, 2023 17:05
Mount Hasura on Apollo federated gateway
const { ApolloServer } = require("apollo-server");
const gql = require("graphql-tag");
const fetch = require("node-fetch");
const {
introspectionQuery,
buildClientSchema,
printSchema
} = require("graphql");
const typeDefs = gql`