Skip to content

Instantly share code, notes, and snippets.

function avgRGB() {
var args = arguments;
var total = [0,0,0];
for (i=0; i<args.length; i++) {
total[0] += args[i][0];
total[1] += args[i][1];
total[2] += args[i][2];
}
var fontFamily = getComputedStyle(document.body).getPropertyValue("font-family");
if (fontFamily.indexOf("Arial") < fontFamily.indexOf("Helvetica") || fontFamily.indexOf("Helvetica") == -1) {
document.body.style.fontFamily = "'Helvetica Neue', Helvetica, Arial, sans-serif";
}
@z-------------
z------------- / server.js
Created June 23, 2014 06:40
Simple node.js server
var express = require("express");
var app = express();
var http = require("http").Server(app);
app.get("/", function(req, res) {
res.sendfile(__dirname + "/index.html");
});
app.get(/^(.+)$/, function(req, res) {
res.sendfile(__dirname + "/" + req.params[0]);
// ==UserScript==
// @name ARR Grade Changer
// @namespace http://zacharyguard.co.nf/
// @version 0.1
// @description Changes all of your grades below B to a B
// @include https://*.tg.esf.edu.hk/src/module/arr_parent/*
// @copyright 2014+, Zachary Guard
// ==/UserScript==
var tds = document.querySelectorAll("td:not(.arr_indi_borderR)");
@z-------------
z------------- / loadScriptAsync.js
Created June 23, 2014 13:24
Asynchronously load external JavaScript files
var loadScriptAsync = function(urls, callback) {
var loadedList = [];
for (i=0; i<urls.length; i++) {
var scriptElem = document.createElement("script");
scriptElem.src = urls[i];
scriptElem.onload = function(){
loadedList.push(true);
if (loadedList.length == urls.length) {
callback();
}
@z-------------
z------------- / index.html
Last active August 29, 2015 14:04
WDMNM?
<!doctype html>
<html>
<head>
<title>WDMNM?</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<header>
<h1>WDMNM?</h1>
</header>
@font-face {
font-family: "My Cool Font";
font-weight: 400;
font-style: normal;
src: local("My Cool Font"), url("my-cool-font.ttf") format("truetype"); /* tries to use installed version, if that doesn't work uses the ttf */
}
/* then just use it as usual */
something {
@z-------------
z------------- / isPrime.js
Last active August 29, 2015 14:04
Foolproof prime number test
function isPrime(n) {
var fact = (function(x) {
for (i=x-1; i>=1; i--) {
x*=i;
}
return x;
})(n-1);
return (fact + 1) % n === 0;
}
@z-------------
z------------- / baseConvert.js
Created September 14, 2014 13:34
Convert integers between any two bases
function base(n, from, to) {
if (typeof n === "number") {
n = n.toString();
}
var baseTen = parseInt(n, from);
return baseTen.toString(to);
}
/*
base("f", 16, 10)
@z-------------
z------------- / nntpSwagTitle.html
Created September 15, 2014 06:45
Paste this in the "New tab title text" box in options for extreme swag
<marquee scrollamount="100" style="font-family:Impact; text-shadow: 7px 7px 5px black, -7px 7px 5px black, -7px -7px 5px black, 7px -7px 5px black, 0 7px 5px black, 7px 0 5px black, 0 -7px 5px black, -7px 0 5px black, 0 0 5px black">xX_N3wt4b_Xx</marquee>