Skip to content

Instantly share code, notes, and snippets.

def hsv2rgb(h,s,v):
"""
0 <= h < 360 # Hue
0 <= s <= 255 # Saturation
0 <= v <= 255 # Value
Hue: position on the color wheel (0 is red)
Saturation: How much of the color is present
Value: How bright the resultant color is
def hsv2rgb(h,s,v):
"""
0 <= h < 360 # Hue
0 <= s <= 255 # Saturation
0 <= v <= 255 # Value
Hue: position on the color wheel (0 is red)
Saturation: How much of the color is present
Value: How bright the resultant color is
@MatthaeusHarris
MatthaeusHarris / str_to_int.c
Created September 19, 2017 21:11
str_to_int function, with no bounds error checking
#include <stdio.h>
int char_is_int(char c) {
return c >= '0' && c <= '9';
}
int char_to_int(char c) {
return c - '0';
}
@MatthaeusHarris
MatthaeusHarris / fizzbuzz_no_conditional.c
Created September 1, 2017 22:39
Fizzbuzz no conditionals
#include <stdio.h>
char *fizz[3] = {"Fizz", "", ""};
char *buzz[5] = {"Buzz", "", "", "", ""};
void main(void) {
for (int i = 1; i <= 100; i++)
printf("%d\r%s%s\n", i, fizz[i%3], buzz[i%5]);
}
#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
#include "lcd.h"
// Shift register pin info
#define SRCLK_PIN 2
#define DATA_PIN 1
#define RCLK_PIN 0
@MatthaeusHarris
MatthaeusHarris / gist:128e53aacd74d83c6d3a
Created February 9, 2016 09:54
Proxmox LXC hang on backup
root@tiamat:~# ps faxo f,uid,pid,ppid,pri,ni,vsz,rss,wchan:20,stat,tty,time,comm | tee ps.log
F UID PID PPID PRI NI VSZ RSS WCHAN STAT TT TIME COMMAND
1 0 2 0 19 0 0 0 kthreadd S ? 00:00:00 kthreadd
1 0 3 2 19 0 0 0 smpboot_thread_fn S ? 00:00:02 \_ ksoftirqd/0
1 0 5 2 39 -20 0 0 worker_thread S< ? 00:00:00 \_ kworker/0:0H
1 0 7 2 19 0 0 0 rcu_gp_kthread S ? 00:03:19 \_ rcu_sched
1 0 8 2 19 0 0 0 rcu_gp_kthread S ? 00:00:00 \_ rcu_bh
1 0 9 2 19 0 0 0 rcu_nocb_kthread S ? 00:02:00 \_ rcuos/0
1 0 10 2 19 0 0 0 rcu_nocb_kthread S ? 00:00:00 \_ rcuob/0
1 0 11 2 139 - 0 0 smpboot_thread_fn S ? 00:00:04 \_ migration/0
var a = [1, 2, 3, 4, 5];
var b = function() {
if (null) {
var a = [1, 2, 3];
}
console.log(a);
}
console.log(a);
b();
app.get("/gamevil/privacy", function(req, res) {
if (cache.privacy && cache.privacy.timestamp > moment().unix() - 3600) {
res.end(cache.privacy.data);
} else {
cache.privacy = {"timestamp": moment().unix()};
http.get("http://us.gamevil.com/news.php?m=policy", function(r) {
var page = "";
r.on('data', function(chunk) {
page += chunk;
});
var feed_url = "http://dragonfinsoup.com/wp/wordpress/?json_route=/posts";
var data;
var masterTemplate;
var fetchPosts = function(num, offset) {
if (!masterTemplate) {
masterTemplate = $('.blogEntry').first().clone();
}
if (!data) {
@MatthaeusHarris
MatthaeusHarris / preload.js
Last active October 21, 2015 21:27
Javascript Preloader
function preload(urls, callback) {
console.log("Setting up preload");
// Container for the actual images
var images = [];
// List of images already loaded
var loaded = {};
// Initialize loaded array to all false