Skip to content

Instantly share code, notes, and snippets.

@Richienb
Richienb / index.js
Created March 13, 2020 11:12
globalThis ponyfill.
function getGlobalThis() {
if (typeof globalThis === 'object') return globalThis;
Object.defineProperty(Object.prototype, '__magic__', {
get: function() {
return this;
},
configurable: true
});
@Richienb
Richienb / index.js
Created March 13, 2020 10:36
Speak text in supported browsers.
const speakText = (text) => speechSynthesis.speak(new SpeechSynthesisUtterance(text))
@Richienb
Richienb / i.html
Created March 12, 2020 15:30
Github notification count in badge
<span class="js-indicator-modifier mail-status unread" style="
font-size: 0.4rem;
text-align: center;
">2</span>
@Richienb
Richienb / index.js
Created February 22, 2020 18:00
MPlayer slave mode in Node.js
"use strict"
const execa = require("execa")
const { default: ow } = require("ow")
module.exports = class Audic {
constructor(src) {
ow(src, ow.string)
this._src = src
@Richienb
Richienb / index.js
Created January 28, 2020 07:25
Kve colour
const kve = require("kve")
const fontColourContrast = require("font-color-contrast")
const parseColour = require("parse-color")
kve.colour = (object) => {
const { hex } = parseColour(object)
const fontColour = fontColourContrast(hex)
const html = `
<style>
.item {
@Richienb
Richienb / app.js
Created January 26, 2020 12:09
Run code in an electron environment
const { app, BrowserWindow, ipcMain: ipc } = require('electron')
let win
function createWindow() {
win = new BrowserWindow({
webPreferences: {
nodeIntegration: true,
},
show: false
@Richienb
Richienb / index.js
Created January 4, 2020 10:55
Read file as binary
const basea = require("basea")
const val = [...fs.readFileSync("example.js")]
const res = val.map(val => basea(val.toString(), 2))
console.log(res)
@Richienb
Richienb / winds.cc
Created January 3, 2020 11:55
Get the currently open windows in C++ - Node.js addon
#include <node.h>
#include <windows.h>
#include <iostream>
#include <list>
#include <iterator>
using namespace std;
namespace winds {
using namespace v8;
@Richienb
Richienb / script.sh
Created December 28, 2019 08:41
Gource command
gource -f -1920x1080 --multi-sampling --camera-mode track --seconds-per-day 1 --auto-skip-seconds 1 --file-idle-time 0 --bloom-multiplier 1.5 --bloom-intensity 1.0 -e 0.5 --font-colour FFFFFF --background 212121 --font-size 18 --hide mouse,progress
@Richienb
Richienb / index.js
Created November 28, 2019 10:33
secureMathRandom
const chance = require('secure-chance')
function secureMathRandom() {
const res = chance.floating({ min: 0, max: 1, fixed: 15 });
return res !== 1 ? res : secureMathRandom()
}
module.exports = secureMathRandom