Skip to content

Instantly share code, notes, and snippets.

View rlemon's full-sized avatar
🍋
Hanging around.

Robert Lemon rlemon

🍋
Hanging around.
  • Dryer Moisture Systems Inc.
  • Kitchener, Ontario. Canada.
View GitHub Profile
const {fork} = require('child_process');
const child = fork('./foo.js', {
stdio: [
0, // Use parent's stdin for child
'pipe', // Pipe child's stdout to parent
process.stdout // send it to the parents stdout? do whatever really.
]
});
@rlemon
rlemon / chat-stats.js
Created March 30, 2017 19:31
bot plugin to display chat statistics.
(function() {
function getChatStats(userid) {
return fetch(`http://chat.stackoverflow.com/users/${userid}`)
.then(res => res.text())
}
function chatStat(msg, cb) {
const args = msg.parse();
let [id = msg.get('user_id')] = args;
if (!/^\d+$/.test(id)) {
id = msg.findUserId(args.length > 1 ? id : args.join(' '));
@rlemon
rlemon / moving-nodes.canvas.js
Created February 24, 2017 14:09
moving nodes canvas
const canvas = document.getElementById('canvas');
const context = canvas.getContext('2d');
const width = document.body.offsetWidth;
const height = document.body.offsetHeight;
canvas.width = width;
canvas.height = height;
const nodes = [];
@rlemon
rlemon / getmost.js
Last active December 13, 2016 20:04
get Most Occurances In Array
function getMostOccurancesInArray(array) {
const sums = array.reduce((obj, item) => {
const key = String(item);
obj[key] = key in obj ? obj[key] + 1 : 1;
return obj;
}, {});
return Object.keys(sums).reduce((array, value, index) => {
if (!index) return [value];
if (sums[value] >= sums[array[0]]) {
if (sums[value] > sums[array[0]]) {
@rlemon
rlemon / sample-css-file-one.css
Last active November 10, 2016 19:45
sample gist for robogist, name: spinner, id: 7fd04fa87bb99589786f4b69e5dbb662, matching: .*
.robogist-spin {
transition: all 500ms linear;
}
.robogist-spin:hover {
transform: rotate(360deg);
}
@rlemon
rlemon / emoji-translator.js
Last active January 5, 2017 14:56
stand alone emoji translator for so chat use this for matching: ^https?:\/\/chat\.stackoverflow\.com\/rooms\/\d+
// TODO :: remove dupe triggers
const emojiData = [{
"emoji": "😀",
"triggers": [":grinning:", ":smile:", ":happy:", ":)"]
}, {
"emoji": "😬",
"triggers": [":grimacing:", ":("]
}, {
"emoji": "😁",
@rlemon
rlemon / checkignore.js
Last active November 10, 2016 19:38
is a user ignoring you?
function checkIgnore(id) {
return $.post(`/users/thumbs/${id}`, fkey({showUsage:true}));
}
function ignoreParser(node) {
if( !node.classList || !node.classList.contains('user-container') ) return;
let id = node.className.match(/user-([0-9]+)/);
if( !id ) return; // cases where we match the node but has no user class
id = id.pop(); // just want the id. this is very ugly.
if( !id ) return console.log('error');
checkIgnore(id).then( ret => {
function getColorWeight(clr1, clr2) {
return Math.sqrt(Math.pow((clr2.r - clr1.r), 2) +
Math.pow((clr2.g - clr1.g), 2) +
Math.pow((clr2.b - clr1.b), 2))
}
function getClosestColor(clr) {
const chosen = {
code: null,
value: 1e9,
@rlemon
rlemon / terrain.js
Created August 17, 2016 20:48
diamond square working
class Terrain {
constructor(d) {
this.size = Math.pow(2,d) + 1;
this.max = this.size - 1;
this.map = new Float32Array(this.size * this.size);
}
get(x,y) {
if( x < 0 || x > this.max || y < 0 || y > this.max ) return -1;
return this.map[x + this.size * y];
}
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
pins = [17,22,23,24]
for pin in pins:
GPIO.setup(pin, GPIO.OUT)
GPIO.output(pin, False)