Skip to content

Instantly share code, notes, and snippets.

var font = "Comic Sans MS"; // set what font you want
// the easy way
document.body.style.fontFamily = font;
// the more robust but slightly more complicated way
var allElements = document.querySelectorAll("*");
for (i=0;i<allElements.length;i++) {
allElements[i].style.fontFamily = font;
@z-------------
z------------- / simple-chrome-storage.js
Last active March 21, 2016 11:20
A simple, localStorage-like way to interact with Chrome's Storage API.
var scs = {
set: function(key,value,type) {
var kvo = {};
kvo[key] = value;
var cs;
if (type == "local") {
cs = chrome.storage.local;
} else {
cs = chrome.storage.sync;
}
function getPixelColor(x,y,canvas){ // where canvas is an HTMLCanvasElement
var ctx = canvas.getContext("2d");
var idata = ctx.getImageData(0,0,canvas.width,canvas.height);
var p = ((y*(idata.width*4)) + (x*4));
var d = idata.data;
return [d[p],d[p+1],d[p+2]]; // returns an array of that pixel's red, green and blue values
}
@z-------------
z------------- / average-color.js
Created April 27, 2014 12:57
Calculate the average color of a canvas
function avgColor(canvas){ // where canvas is an HTMLCanvasElement
var tr = 0, tg = 0, tb = 0;
var idata = canvas.getContext("2d").getImageData(0,0,canvas.width,canvas.height).data;
for (i=0;i<idata.length;i+=4) { // red
tr += idata[i];
}
for (i=1;i<idata.length;i+=4) { // green
tg += idata[i];
}
for (i=2;i<idata.length;i+=4) { // blue
@z-------------
z------------- / henrify.js
Created May 7, 2014 01:32
Microsoftifies everything. Named after my very good friend Henry, who has a more-than-obsessive love of the Segoe font.
(function(word){
var hStyle = document.createElement("style");
hStyle.innerHTML = "*{font-family:'Segoe UI',Segoe,sans-serif !important;font-weight:100 !important}";
document.querySelectorAll("head")[0].appendChild(hStyle);
var targets = document.querySelectorAll("h1,h2,h3,h4,h5,h6,p,a");
for (i in targets) {
targets[i].innerHTML = word + ", " + targets[i].innerHTML;
}
})("Honestly");
import java.util.*;
public class Androo {
public static void main(String []args){
String[] phrases = {"WERE U BORN IN A BARN???", "GET SUM WERK DUN", "Useless scrub...", "Stop jacking off", "I'LL BUST YOUR CHOPS", "R U BORN IN A WATER PARK??", "Stop fapping around", "R U BORN IN A BARN???", "LATER, SHIZLORD", "OI!!"};
String chosenPhrase = phrases[new Random().nextInt(phrases.length)];
on quit
display dialog "Really shut down?" buttons {"No", "Yes"} default button "No"
if the button returned of the result is "Yes" then
display dialog "Are you sure?" default answer "No"
if text returned of the result is "Yes" then
display dialog "Are you really sure?" default answer "Really no"
if text returned of the result is "Really yes" then
continue quit
end if
end if
@z-------------
z------------- / stringContainsArrayElement.js
Created May 14, 2014 11:43
Check if a string contains at least one element of an array
String.prototype.containsArrayElement = function(array) {
var returnVal = false;
for(i=0;i<array.length;i++){
if (this.indexOf(array[i]) != -1){
returnVal = true;
}
}
return returnVal;
}
@z-------------
z------------- / easyMouseCoords.js
Last active August 29, 2015 14:01
Get mouse coordinates with mouse.coords object. The script handles the event for you.
var mouse = {};
mouse.coords = {x:-1,y:-1};
window.addEventListener("mousemove",function(e){
mouse.coords.x = e.clientX;
mouse.coords.y = e.clientY;
});
/* example:
if (mouse.coords.x > window.innerWidth / 2) {
@z-------------
z------------- / factRecursiveAndIterative.js
Created May 19, 2014 14:12
Two ways to calculate factorials: recursively and iteratively. http://jsperf.com/recursive-vs-iterative-factorial
// recursive
var factorial = function(n) {
if (n == 1) {
return 1;
} else {
return n * factorial(n-1);
}
}
// iterative