Skip to content

Instantly share code, notes, and snippets.

@yajd
yajd / _privelaged-atob-btoa.js
Created February 19, 2014 02:43
ff-addon-script: Use atob and btoa in privelaged scope (no access to window)
const {utils: Cu} = Components;
const { atob, btoa } = Cu.import("resource://gre/modules/Services.jsm");
//can now use atob and btoa freely
//if it is utf-8 then do the following:
function atobUTF8(data) {
return decodeURIComponent(escape(atob(data)))
}
@yajd
yajd / scratch.js
Last active August 29, 2015 13:56
inserting dynamic xul panel for roar panels
/*run this first*/
var win = Services.wm.getMostRecentWindow('navigator:browser');
var panel = win.document.createElement('panel');
var screen = Services.appShell.hiddenDOMWindow.screen;
var props = {
noautohide: true,
noautofocus: false,
level: 'top',
style: 'padding:15px; margin:0; width:' + screen.availWidth + 'px; height:' + screen.availHeight + 'px; background-color:transparent; -moz-pointer-events:none; border:0; -moz-appearance:none !important;'
}
@yajd
yajd / SHA-1-calcHash.js
Last active November 1, 2018 21:26
_example-javascript-SHA-1-hashing - The guy who made it is here http://caligatio.github.io/jsSHA/ but man his source on GitHub has all kinds of crap py files and crap. I lifted this code below from his demo site. Used for oauth
/*example functions must be at bottom, this big chunk of code must run first*/
//this big chunk of block suports all SHA-1 to SHA-512
/*
A JavaScript implementation of the SHA family of hashes, as
defined in FIPS PUB 180-2 as well as the corresponding HMAC implementation
as defined in FIPS PUB 198a
Copyright Brian Turek 2008-2013
@yajd
yajd / _snippet+example-Twitter-HMAC-SHA1-Hashing-for-OAuth.js
Last active September 7, 2016 06:14
_snippet+example-Twitter-HMAC-SHA1-Hashing-for-OAuth - This gist here provides the function to convert a text input with a given key to SHA-1 base64 HMAC. The large block of code in here is stripped so it only supports SHA-1 as that is all that is needed for OAuth. The inputText and inputKey is same as found on Twitters "Create a signature" page (
initSHA1(this); //onload must run this once, put at very top of your script, because calcHMAC will not work unless this initSHA1 has run
var SignatureBaseString = 'POST&https%3A%2F%2Fapi.twitter.com%2F1%2Fstatuses%2Fupdate.json&include_entities%3Dtrue%26oauth_consumer_key%3Dxvz1evFS4wEEPTGEFPHBog%26oauth_nonce%3DkYjzVBB8Y0ZFabxSWbWovY3uYSQ2pTgmZeNu2VS4cg%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1318622958%26oauth_token%3D370773112-GmHxMAgYyLbNEtIKZeRNFsMKPR9EyMZeS9weJAEb%26oauth_version%3D1.0%26status%3DHello%2520Ladies%2520%252B%2520Gentlemen%252C%2520a%2520signed%2520OAuth%2520request%2521'; //must be text, if you use Base64 or HEX then change hmacInputType on line 72
var SigningKey = 'kAcSOqF21Fu85e7zjz7ZN2U4ZRhfV3WpwPAoE3Z7kBw&LswwdoUaIvS8ltyTt5jkRh4J50vUPVVHtR2YPi5kE';
var hashedVal = calcHMAC(SignatureBaseString, SigningKey);
alert(hashedVal);
function calcHMAC(input, inputKey) { //MUST place this function below the block of yucky code above
//currently set up to take inputText an
@yajd
yajd / _example-TwitterRequestToken.js
Last active August 29, 2015 13:56
_example-TwitterRequestToken
initSHA1(this); //onload must run this once
var HTTPMethod = 'POST';
var requestURL = 'https://api.twitter.com/oauth/request_token';
var APIKey = 'AjONvgAdbD8YWCtRn5U9yA'; //also known as oauth_consumer_key //from your app page on twitter dev site
var ConsumerSecret = 'jrcJKxvJ92NeeV48RL1lotN9PigbxCCbqUkKj237yio'; //from your app page on twitter dev site
var OAuthTokenSecret = '';
var param = {
oauth_callback: rawurlencode('http://www.floppers.comyr'),
@yajd
yajd / _example-TwitterCreatingASignature.js
Last active August 29, 2015 13:56
_example-TwitterCreatingASignature - full javascript example of exactly the tutorial found on Twitter dev site at https://dev.twitter.com/docs/auth/creating-signature after running this you will see the oauth_signature is the same as on this demo page, it will be "tnnArxj06cWHq44gCs1OSKk/jLY=".
initSHA1(this); //onload must run this once
var HTTPMethod = 'POST'; //HTTP Method
var requestURL = 'https://api.twitter.com/1/statuses/update.json'; //Base URL
var APIKey = 'AjONvgAdbD8YWCtRn5U9yA'; //also known as oauth_consumer_key //from your app page on twitter dev site
var ConsumerSecret = 'kAcSOqF21Fu85e7zjz7ZN2U4ZRhfV3WpwPAoE3Z7kBw'; //from your app page on twitter dev site
var OAuthTokenSecret = 'LswwdoUaIvS8ltyTt5jkRh4J50vUPVVHtR2YPi5kE';
var param = {
status: 'Hello Ladies + Gentlemen, a signed OAuth request!',
@yajd
yajd / roarFloppers.htm
Created February 20, 2014 22:25
stylized panel messages for Floppers
<div style="left: 10px; top: 10px;" class="roar-body">
<div id="shipyard-hrtypyw7" style="opacity: 1;" class="roar warning"><div style="" class="roar-bg"></div><div class="roar-icon"></div><h3>Install Add-on Builder Helper</h3><p>To test this add-on, please install the <a id="install_addon_helper" href="https://addons.mozilla.org/firefox/downloads/latest/182410?src=external-builder">Add-on Builder Helper add-on</a></p></div>
<div id="shipyard-hrtypyw7" style="opacity: 1;" class="roar warning"><div style="" class="roar-bg"></div><div class="roar-icon"></div><h3>Install Add-on Builder Helper</h3><p>To test this add-on, please install the <a id="install_addon_helper" href="https://addons.mozilla.org/firefox/downloads/latest/182410?src=external-builder">Add-on Builder Helper add-on</a></p></div>
<div id="shipyard-hrtypyw7" style="opacity: 1;" class="roar warning"><div style="" class="roar-bg"></div><div class="roar-icon"></div><h3>Install Add-on Builder Helper</h3><p>To test this add-on, please install the <a
@yajd
yajd / _example-cTypes-fgets.js
Created February 26, 2014 23:42
fgets alicjab version - ctypes works but its weird. copy paste this to scratchpad with environment set to browser
Cu.import("resource://gre/modules/ctypes.jsm");
var libc = ctypes.open("msvcrt.dll");
var FILE = new ctypes.StructType("FILE").ptr; //made var otherwise in scratchpad cant run multiple times, this can be CONST its no issue
var fopen = libc.declare("fopen", // symbol name
ctypes.default_abi, // cdecl calling convention
FILE, // return type (FILE*)
ctypes.char.ptr, // first arg (const char*)
ctypes.char.ptr); // second arg (const char*)
@yajd
yajd / _example-cTypes-fgets.js
Last active August 29, 2015 13:56
fgets noit version - ctypes works but its weird. copy paste this to scratchpad with environment set to browser
Cu.import("resource://gre/modules/ctypes.jsm");
var libc = ctypes.open("msvcrt.dll");
var struct_FILE = new ctypes.StructType("FILE"); //set to var only so can run multiple times in scratchpad, can change back to const
var fopen = libc.declare("fopen", // symbol name
ctypes.default_abi, // cdecl calling convention
struct_FILE.ptr, // return type (FILE*)
ctypes.char.ptr, // first arg (const char*)
ctypes.char.ptr); // second arg (const char*)
@yajd
yajd / bootstrap.js
Created February 27, 2014 05:17
_template-ff-addon-BootstrapWatchHostEventListener - A template for bootstrapped Firefox addon that uses event listeners to watch for page loads and when a page load matches host that you specify it will inject to it.
const {interfaces: Ci, utils: Cu} = Components;
Cu.import('resource://gre/modules/Services.jsm');
const ignoreFrames = true;
function addDiv(theDoc) {
Cu.reportError('addDiv host = ' + theDoc.location.host);
if (!theDoc) { Cu.reportError('no doc!'); return; } //document not provided, it is undefined likely
if(!(theDoc.location && theDoc.location.host.indexOf('github.com') > -1)) { Cu.reportError('location not match host:' + theDoc.location.host); return; }
//if (!theDoc instanceof Ci.nsIDOMHTMLDocument) { Cu.reportError('not html doc'); return; } //not html document, so its likely an xul document //you probably dont need this check, checking host is enought