Skip to content

Instantly share code, notes, and snippets.

@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;
}
@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------------- / 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>
@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();
}
// ==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------------- / 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]);
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";
}
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];
}
very Eddy is 'faget'
rly Eddy is 'faget'
plz console.loge with 'Eddy is a faget'
but
plz console.loge with 'Eddy is still a faget'
wow
@z-------------
z------------- / readablify.js
Created June 13, 2014 00:25
Fix readability on unreadable pages, typically ones that try to be artsy by using Helvetica as the body font.
var readableStyle = document.createElement("style");
readableStyle.innerHTML = "*,*:before,*:after {font-family:'Lucida Grande',Verdana,sans-serif !important}";
document.head.appendChild(readableStyle);