Skip to content

Instantly share code, notes, and snippets.

/*
* Copyright 2009-2011 Mozilla Foundation and contributors
* Licensed under the New BSD license. See LICENSE.txt or:
* http://opensource.org/licenses/BSD-3-Clause
*/
/**
* Define a module along with a payload.
* @param moduleName Name for the payload
@joewalker
joewalker / ssh.js
Created February 23, 2022 14:36
Prototype SSH version of ZX
// @ts-check
import { readFile } from 'fs/promises';
import { Client } from 'ssh2';
import { ProcessPromise, ProcessOutput, $ } from 'zx';
import chalk from 'chalk';
/**
* @typedef {import('ssh2/lib/Channel.js').Channel} Channel)}
* @typedef {import('./ssh-types').HostConfig} HostConfig
* @typedef {import('./ssh-types').SshZx} SshZx
@joewalker
joewalker / bootstrap.js
Created June 17, 2012 13:56
Hello Command
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
Components.utils.import("resource:///modules/devtools/gcli.jsm");
var helloCommandSpec = {
name: 'hello',
description: 'Show a message',
params: [
{
@joewalker
joewalker / flatmap.js
Created May 11, 2017 16:43
Annoying flow problem
// @flow
type FlatMapMapper<In, Out> = (elem: In, index: number, arr: In[]) => Out | Out[];
function flatMap<In, Out>(arr: In[], mapFunc: FlatMapMapper<In, Out>): Out[] {
const result = [];
for (const [ index, elem ] of arr.entries()) {
const x = mapFunc(elem, index, arr);
// We allow mapFunc() to return non-Arrays
if (Array.isArray(x)) {
@joewalker
joewalker / repl_against_tofino.clj
Created December 12, 2016 17:48
Get a repl that allows you to use your tofino profile to practice your datascript
; $ cd .../datomish
; lein repl
(require '[datomish.api :as d])
(require '[datomish.sqlite])
(require '[datomish.jdbc-sqlite])
(require '[clojure.core.async :as async])
; You'll need to replace $HOME with whatever $HOME is, and if not on a mac, do something AppData like
import webpack from 'webpack';
import config from './webpack.config';
import { mapObject } from './web/util/util';
export const original = config;
/**
* Development config. Inspired by
* https://github.com/gaearon/react-transform-boilerplate/blob/master/webpack.config.dev.js
@joewalker
joewalker / webpack.mutate.js
Created January 27, 2016 21:32
Keep your core webpack config simple and mutate it with ES.whatever Object Rest/Spread
import webpack from 'webpack';
import config from './webpack.config';
import { mapObject } from './web/util/util';
export const original = config;
/**
* Development config. Inspired by
* https://github.com/gaearon/react-transform-boilerplate/blob/master/webpack.config.dev.js
XPCOMUtils.defineLazyGetter(this, "require", function() {
let { require } = Cu.import("resource://gre/modules/devtools/Require.jsm", {});
Cu.import("resource://gre/modules/devtools/gcli.jsm", {});
return require;
});
XPCOMUtils.defineLazyGetter(this, "Requisition", () => require("gcli/cli").Requisition);
function execGcliCommand(command) {
@joewalker
joewalker / helpers.audit.js
Last active December 11, 2015 16:08
An example of the new way to write GCLI tests
/**
* An example of the new way to write GCLI tests
*/
var promise = helpers.audit([ // Tests can be async. They're done when the promise resolves
{
name: 'a test', // Optional test name, we'll use the 'setup' string if there is no name
setup: 'help search', // A string to type (which can include control chars like <TAB>),
// or a function to do custom setup. return a promise to be async
skipIf: function() { ... }, // If you need to skip tests in some cases e.g. private browsing
check: { // Some stuff to check ...
@joewalker
joewalker / promise.js
Last active December 11, 2015 13:38
Logging errors in promises
let console = (Cu.import("resource://gre/modules/devtools/Console.jsm", {})).console;
// ...
/**
* Internal utility: Decorates given `f` function, so that on exception promise
* rejected with thrown error is returned.
*/
function attempt(f) {
return function effort(input) {