Skip to content

Instantly share code, notes, and snippets.

View keybase.md

Keybase proof

I hereby claim:

  • I am macil on github.
  • I am macil (https://keybase.io/macil) on keybase.
  • I have a public key ASCdSs0kwynStovfiulSBV6G5PcQhbDC--cWtrV-a5g28Qo

To claim this, I am signing this object:

@Macil
Macil / fetchRecursively.js
Created Jul 4, 2018
An example of using Kefir streams with a recursive function.
View fetchRecursively.js
'use strict';
const Kefir = require('kefir');
// fetch takes a url string, pretends to fetch it over the network, and returns
// a Kefir stream that emits a Page object when it's done, and then the stream
// ends.
function fetch(url) {
let links;
switch (url) {
case 'foo.com': links = ['bar.com', 'baz.com']; break;
@Macil
Macil / loadInContentScript.js
Created Mar 7, 2018
This function allows you to load javascript from a remote url with an extension content script, and have the loaded javascript execute within the content script's isolated world.
View loadInContentScript.js
async function loadInContentScript(url) {
// Note that this extension must either have permission to the domain of this
// URL, or the URL must be served with the correct CORS HTTP headers to allow
// this script to fetch it (ie. "Access-Control-Allow-Origin: *").
const response = await fetch(url);
const scriptText = await response.text();
// Let Chrome devtools know where this code came from.
const codeToRun = scriptText + "\n//# sourceURL=" + url + "\n";
View content.js
// This code is assumed to be part of one of the extension's content scripts
function addIframe() {
const iframe = document.createElement('iframe');
iframe.addEventListener('load', () => {
iframe.contentWindow.postMessage({
eventName: 'init',
iframeSrc: 'https://xkcd.com/' // whatever url you want. Probably will be a URL to your own domain in practice
}, '*');
}, false);
@Macil
Macil / gist:7369c93de844f8e785b0
Created Dec 17, 2014
eval with chrome debugger support
View gist:7369c93de844f8e785b0
function evalFromUrl(code, url) {
// jshint evil:true
// Q: Why put the code into a function before executing it instead of
// evaling it immediately?
// A: Chrome would execute it before applying any remembered
// breakpoints.
// Q: Why not just use `... = new Function(...)`?
// A: The sourcemaps would be off by one line in Chrome because of
// https://code.google.com/p/chromium/issues/detail?id=109362
@Macil
Macil / reporter.js
Created Jan 19, 2014
Automatically report unhandled javascript exceptions to your server!
View reporter.js
(function(exports) {
function nop() {}
// IE doesn't always have console, place a no-op shim for it.
if (!window.console) {
window.console = {log: nop, info: nop, warn: nop, error: nop};
}
// Transforms an Error to a simple object that can be JSONified.
function error_to_object(error) {
@Macil
Macil / encryption
Created Nov 12, 2013
Experimenting with exploiting KusabaX's encryption algorithms.
View encryption
<?php
function get_rnd_iv($iv_len) {
$iv = '';
while ($iv_len-- > 0) {
$iv .= chr(mt_rand() & 0xff);
}
return $iv;
}
function md5_encrypt($plain_text, $password, $iv_len = 16, $iv_init = false) {
@Macil
Macil / local.usr.bin.skype
Last active Jan 31, 2017
Skype AppArmor profile(tested with Ubuntu 14.10 and Skype 4.3)
View local.usr.bin.skype
#include <tunables/global>
/usr/bin/skype {
#include <abstractions/base>
#include <abstractions/user-tmp>
#include <abstractions/audio>
#include <abstractions/nameservice>
#include <abstractions/ssl_certs>
#include <abstractions/fonts>
#include <abstractions/ibus>
#include <abstractions/dbus>
You can’t perform that action at this time.