Skip to content

Instantly share code, notes, and snippets.

View mwcz's full-sized avatar
🏠
Working from home

Michael Clayton mwcz

🏠
Working from home
View GitHub Profile
@mwcz
mwcz / godzilla.js
Last active January 22, 2016 13:35
Godzilla Rampage
// ==UserScript==
// @name Godzilla Rampage
// @namespace godzilla.substitution.fun
// @description Replaces 'God' with 'Godzilla'
// @version 1.0.0
// @grant none
// @include http://*
// @require https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
// ==/UserScript==
@mwcz
mwcz / nth.js
Created February 11, 2016 15:55
nth function, execute a function every nth invocation
/**
* Wrap your function such that it will be executed every N times it's called.
* This is useful in a long-running loop such as the main loop in a game, where
* you want to execute certain functions every 10 frames, or similar, but don't
* want to manage a dozen separate "timers".
*
* @param {Function} f the function to wrap
* @param {Number} n execute the function every `n` times
*/
function nth(f, n) {
@mwcz
mwcz / watchrun.sh
Last active May 28, 2016 06:42
watchrun script for running a command when any file in the current dir tree changes
#!/bin/sh
# USAGE: ./watchrun.sh COMMAND
# New credit to: http://exyr.org/2011/inotify-run/
# this script will wait for changes in the current directory tree, and when one occurs, it will run COMMAND, then resume waiting
# requires inotify-tools:
# sudo apt-get install inotify-tools
# or:
@mwcz
mwcz / gif.sh
Created September 27, 2016 17:31
gif command for recording animated gifs in Linux
#!/bin/bash
# USAGE: gif SECONDS FILENAME
# example: gif 4 out.gif
# then drag a box :D
# Delay before starting
DELAY=0
# Duration and output file
<script src="typed.js"></script>
@mwcz
mwcz / jsdoc_AMD_module.md
Last active February 26, 2017 05:36
Michael Mathews (JSDoc founder) explains how @name works and how to document my IIFE-nested multiple-AMD module definitions (wow, that sounds cooooool).

#########

Me:

#########

It's not that I want to avoid those particular tags; I just want to generate the most documentation with the fewest number of tags. Lots of tags start impacting code readability.

Here's a better illustration of my use case. A few constructors are defined inside of an IIFE in order to keep them out of the global namespace. They are then exported with an AMD module definition at the bottom:

(function () {
<p>I am your snippet.</p>
@mwcz
mwcz / gist:7b96a741d2f1431c8199
Last active August 12, 2018 08:29
casperjs test case example
// googletesting.js
casper.test.begin('Google search retrieves 10 or more results', 5, function suite(test) {
casper.start("http://www.google.fr/", function() {
test.assertTitle("Google", "google homepage title is the one expected");
test.assertExists('form[action="/search"]', "main form is found");
this.fill('form[action="/search"]', {
q: "casperjs"
}, true);
});
<script type="module" src="https://unpkg.com/@patternfly/pfe-icon@latest/pfe-icon.js"></script>
@mwcz
mwcz / pfe-unpkg.html
Created February 14, 2020 17:30
Example of pulling PatternFly Elements into a static HTML page using unpkg.com. Good for toying around with elements without having to set up NPM tooling, build process, etc.
<!-- Pull in pfelement.css -->
<link rel="stylesheet" href="https://unpkg.com/@patternfly/pfelement/dist/pfelement.min.css">
<!-- Add an import statement for each PatternFly Element you want .ES Modules++ -->
<script type="module">
import "https://unpkg.com/@patternfly/pfe-card/dist/pfe-card.min.js";
import "https://unpkg.com/@patternfly/pfe-cta/dist/pfe-cta.min.js";
</script>