Skip to content

Instantly share code, notes, and snippets.

View mrjacobbloom's full-sized avatar
🎄

Jacob mrjacobbloom

🎄
View GitHub Profile
@mrjacobbloom
mrjacobbloom / swizzler.js
Last active March 14, 2019 23:47
Use JS proxies to make a `vec(1,2,3,4)` class that allows for swizzling like in GLSL -- https://www.khronos.org/opengl/wiki/Data_Type_(GLSL)#Swizzling
export class Vec {
constructor(...values) {
this.values = this.constructor.flatten(values);
this.self = this;
this.proxy = new Proxy(this, this.constructor.handler);
return this.proxy;
}
static flatten(values) {
const flatValues = [];
for(const value of values) {
@mrjacobbloom
mrjacobbloom / servicenow-bookmarklets.js
Created November 26, 2018 21:05
Bookmarklets I use to make ServiceNow good
/* Get a markdown link to the current record
* Copies it to clipboard, adds nav stuff to URL if there isn't any
* Nice for Trello
* e.g. [INC123456](whatever.service-now.com/...)
*/
javascript:(() => { let copy = text => { let input = document.createElement('textarea'); input.textContent = text; document.body.appendChild(input); input.select(); document.execCommand("copy"); input.remove(); }; let navUrl = (() => { let [, path] = /^https:\/\/.+\.service-now\.com(.+)$/.exec(location.href) || []; return path && path.match(/^\/nav/) ? location.href : location.origin + `/nav_to.do?uri=${encodeURIComponent(path)}`; })(); let number = document.title.split('|')[0].trim(); let out = `[${number}](${navUrl})`; copy(out); return undefined; })();
/* Get code for a GlideRecord that gets the current record
* Copies it to clipboard so you can paste it into a BG script/Xplore/whatever
*/
@mrjacobbloom
mrjacobbloom / getIPs.js
Created November 26, 2018 20:53
get IPs using WebRTC and promises
// adapted from https://stackoverflow.com/a/32838936
// (which was adapted from https://github.com/diafygi/webrtc-ips)
getIPs = (doStun = false) => new Promise((resolve, reject) => {
let RTCPeerConnection = window.RTCPeerConnection || window.mozRTCPeerConnection || window.webkitRTCPeerConnection;
let servers = {iceServers: doStun ? [{urls: "stun:stun.services.mozilla.com"}] : []};
let pc = new RTCPeerConnection(servers, {optional: [{RtpDataChannels: true}]});
let IPs = new Set();
pc.createDataChannel(""); //create a bogus data channel
pc.createOffer(pc.setLocalDescription.bind(pc), () => {}); // create offer and set local description
pc.onicecandidate = ice => { //listen for candidate events
// ==UserScript==
// @name Scratch 3.0: Collapsible C-Blocks
// @author NickyNouse
// @include /^.*/vertical_playground.html?$/
// @grant none
// @require https://airhogs777.github.io/sb3-theme/sb3-theme.js
// ==/UserScript==
(function() {
'use strict';
// ==UserScript==
// @name Unflat Scratch-Blocks
// @version 0.1
// @description make Scratch-Blocks look more like Scratch 2.0
// @author NickyNouse
// @include /^https?://.*/(vertical|horizontal)_playground.html?$/
// @grant none
// ==/UserScript==
(function() {
@-moz-document url-prefix("http://tosh.tjvr.org/app/") {
body {
background: #555;
}
#menu {
box-shadow: 0 0 5px #000;
color: #ddd;
background: #888;
}
@-moz-document url("https://scratch.mit.edu/") {
@import url(https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css);
/** page width -- if you nee a different width, just change this **/
body, #navigation {
width: 500px;
}
#view, #view > .splash > .inner{
width: 100%;
box-sizing: border-box;
// ==UserScript==
// @name Kernt Events
// @version 1
// @description Make all the kerning bad
// @author NickyNouse
// @match *://*/*
// @grant none
// ==/UserScript==
'use strict';
//from http://stackoverflow.com/a/29301739/1784306
// ==UserScript==
// @name :package2: adder
// @version 0.1
// @description replaces :package2: with the bbcode for package
// @author NickyNouse
// @match https://scratch.mit.edu/discuss/*
// @grant none
// ==/UserScript==
/* jshint -W097 */
'use strict';
// ==UserScript==
// @name Scratch Project Analytics
// @version 1
// @description adds engagement rates for a project's likes/fav's out of total views an to MyStuff
// @author NickyNouse
// @match https://scratch.mit.edu/projects/*
// @match https://scratch.mit.edu/mystuf*
// @grant none
// ==/UserScript==