Skip to content

Instantly share code, notes, and snippets.

@jasonrhodes
jasonrhodes / memoize-throttle-how.md
Last active February 24, 2018 21:44
I want to throttle a function but split up by args, is there an easy way?

Say you have a function that takes a single argument like this:

// return a string date that is "n" days before "right now"
function backInTime(n) {
  return subtract(new Date(), n, 'days').toString();
}

So if you call this (on Thurs, Feb 22) a few times in a row (pretending each one takes a full second to run) you would get:

@m3g4p0p
m3g4p0p / dom-helper.js
Last active June 23, 2020 05:05
Mini jQuery, sort of.
/**
* A collection of helper prototype for everyday DOM traversal, manipulation,
* and event binding. Sort of a minimalist jQuery, mainly for demonstration
* purposes. MIT @ m3g4p0p
*/
window.$ = (function (undefined) {
/**
* Duration constants
* @type {Object}
@JoelQ
JoelQ / README.md
Created October 15, 2015 13:50
Using Shell Scripts for a Better User Experience (source for https://robots.thoughtbot.com/improving-user-experience-with-shell-scripts)

Server scripts

This is the source for the scripts discussed in https://robots.thoughtbot.com/improving-user-experience-with-shell-scripts

Both scripts are in the bin/ directory of the repo that contains all the markdown documents for blog posts. Users run bin/server and everything is automatically set up for them to view a local preview of the blog. bin/server-setup is a dependency of bin/server and is never run directly by users.

Maitre-d is the name of the "blog engine" discussed in the article.

@jasonm23
jasonm23 / upgrade-or-install-emacs-mac-port-with-custom-icon-via-homebrew.sh
Last active March 25, 2024 16:08
Upgrade emacs-mac homebrew and move app to Applications and apply custom icon
#!/bin/bash
# Update brew and upgrade Emacs mac (tap railwaycat in-case it's not already)
brew tap railwaycat/emacsmacport
brew update
if [[ -d /usr/local/Cellar/emacs-mac ]]; then
brew upgrade emacs-mac
else
brew install emacs-mac
@aolde
aolde / static_server.js
Last active February 27, 2024 23:00 — forked from ryanflorence/static_server.js
Simple web server in Node.js. This fork added mime types for common file types.
var http = require("http"),
url = require("url"),
path = require("path"),
fs = require("fs")
port = process.argv[2] || 8888,
mimeTypes = {
"html": "text/html",
"jpeg": "image/jpeg",
"jpg": "image/jpeg",
"png": "image/png",
@hofmannsven
hofmannsven / README.md
Last active July 16, 2024 01:30
Git CLI Cheatsheet
@zakhardage
zakhardage / Much much simpler option selector for Shopify
Last active July 13, 2024 21:36
Much simpler version of Shopify's option_selection.js for separating product options into their own dropdown menus.
<form action="/cart/add" method="post">
{% if product.variants.size > 1 %}
{% if product.options[0] %}
{% assign used = '' %}
<label for="select-one">{{ product.options[0] }}</label>
<select id='select-one' onchange="letsDoThis()">
{% for variant in product.variants %}
{% unless used contains variant.option1 %}
<option value="{{ variant.option1 }}">{{ variant.option1 }}</option>
{% capture used %}{{ used }} {{ variant.option1 }}{% endcapture %}
@willurd
willurd / web-servers.md
Last active July 23, 2024 12:11
Big list of http static server one-liners

Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.

Discussion on reddit.

Python 2.x

$ python -m SimpleHTTPServer 8000
@grevory
grevory / bootstrap-photo-with-caption.html
Created April 12, 2013 04:47
Simple markup for adding captions and credits to images with Twitter Bootstrap.
<style>
.thumbnail.with-caption {
display: inline-block;
background: #f5f5f5;
}
.thumbnail.with-caption p {
margin: 0;
padding-top: 0.5em;
}
.thumbnail.with-caption small:before {
@cobyism
cobyism / gh-pages-deploy.md
Last active July 18, 2024 05:22
Deploy to `gh-pages` from a `dist` folder on the master branch. Useful for use with [yeoman](http://yeoman.io).

Deploying a subfolder to GitHub Pages

Sometimes you want to have a subdirectory on the master branch be the root directory of a repository’s gh-pages branch. This is useful for things like sites developed with Yeoman, or if you have a Jekyll site contained in the master branch alongside the rest of your code.

For the sake of this example, let’s pretend the subfolder containing your site is named dist.

Step 1

Remove the dist directory from the project’s .gitignore file (it’s ignored by default by Yeoman).