Skip to content

Instantly share code, notes, and snippets.

@PAEz
PAEz / client.js
Created August 10, 2015 11:33
The gists to plugin sockets with NodeBB 0.7.x
function callBack(config) {
+ Katex.dollarInline = config.dollarInline;
+ deferred.resolve(config);
+ }
+ // do the async call to the socket.
+ socket.emit('plugins.Katex.getConfig', callBack);
@PAEz
PAEz / shuffle.js
Created August 4, 2015 08:39
Shuffle an array in JS
// http://bost.ocks.org/mike/shuffle
function shuffle(array) {
var len = array.length;
var temp, i;
while(len) {
i = Math.floor(Math.random() * len--);
temp = array[len];
array[len] = array[i];
@PAEz
PAEz / [QtTabBar] OneDot - Remove all dots in file name except the last one
Created June 29, 2015 08:03
[QtTabBar] OneDot - Remove all dots in file name except the last one
This script is for QtTabBar, an awesome extension for windows explorer.
It just removes all dots from the selected file names except the last dot.
@PAEz
PAEz / [QtTabBar] Flatten Selected Folders
Last active August 29, 2015 14:23
[QtTabBar] Flatten Selected Folders
This script is for QtTabBar, an awesome extension for windows explorer.
This will copy the contents of all selected folders into the current folder and delete the folder if afterwards its empty.
I have a habit of putting everything my mates drop off in new folders so I can keep track of where I and others are up to.
Eventually I sort all the files out and its a bit of a pain going in them all, this fixes that.
@PAEz
PAEz / [QtTabBar] Delete Wav file if Flac of same name exists
Last active August 29, 2015 14:23
[QtTabBar] Delete Wav file if Flac of same name exists
Goes through all selected folders (one deep) and checks if a wav file with the same name of a flac files exists and if it does then delete it.
This is my first script for QtTabBar....one of the best extensions to Windows, EVER!
`qs.InvokeCommand( "DeleteFile", fc.item().Path);`
Didnt work for me, complains the command doesnt exist. If I try using the command code of 125 then it doesnt bitch but it doesnt seem to do anything either. Using the fso.DeleteFile worked fine, except it didnt send it to the recycle bin which would have been nice, but I spose theres something for that but didnt look coz its working ;).
var p1 = {
x: 20,
y: 20
};
var p2 = {
x: 40,
y: 40
};
@PAEz
PAEz / template.js
Last active December 9, 2015 20:24
Simple compiled template thingy
var all = [];
function parseTemplate (str) {
var re = /(\\r\\n|\\r|\\n)|{[(](.*?)[)]}|{{(.*?)}}/g;
re.lastIndex = 1;
var matches;
var last = 1;
var line = lastLine = lineEndPos = lineReturnPos = returnPos = 0;
str = JSON.stringify(str); // dont forget that this adds a quote character at the beginning and end of the string
parseTemplate.template = str;
while ((matches = re.exec(str)) !== null) {
function getFnName(fn) {
var f = typeof fn == 'function';
var s = f && ((fn.name && ['', fn.name]) || fn.toString().match(/function ([^\(]+)/));
return (!f && 'not a function') || (s && s[1] || 'anonymous');
}
console.log(getFnName(String)); // 'String'
console.log(getFnName(function test(){})); // 'test'
console.log(getFnName(function (){})); // 'anonymous'
@PAEz
PAEz / colors.js
Last active August 29, 2015 14:15
Chrome/Skia's Color Routines in JS
function colorToHSL(red, green, blue) {
var luminance, hue, saturation;
red = red / 255;
green = green / 255;
blue = blue / 255;
var vmax = Math.max(Math.max(red, green), blue);
var vmin = Math.min(Math.min(red, green), blue);
var delta = vmax - vmin;
var luminance = (vmax + vmin) / 2;
if (delta > 0) {
@PAEz
PAEz / LineIntersection.js
Created January 14, 2015 07:35
Check Line Intersection
// http://jsfiddle.net/justin_c_rounds/Gd2S2/
function checkLineIntersection(startX1, startY1, endX1, endY1, startX2, startY2, endX2, endY2, result) {
// if the lines intersect, the result contains the x and y of the intersection (treating the lines as infinite) and booleans for whether line segment 1 or line segment 2 contain the point
var denominator, a, b, numerator1, numerator2, result = result || {
x: 0,
y: 0,
onLine1: false,
onLine2: false
};
denominator = ((endY2 - startY2) * (endX1 - startX1)) - ((endX2 - startX2) * (endY1 - startY1));