Skip to content

Instantly share code, notes, and snippets.

@ljharb
ljharb / array_iteration_thoughts.md
Last active April 29, 2024 17:13
Array iteration methods summarized

Array Iteration

https://gist.github.com/ljharb/58faf1cfcb4e6808f74aae4ef7944cff

While attempting to explain JavaScript's reduce method on arrays, conceptually, I came up with the following - hopefully it's helpful; happy to tweak it if anyone has suggestions.

Intro

JavaScript Arrays have lots of built in methods on their prototype. Some of them mutate - ie, they change the underlying array in-place. Luckily, most of them do not - they instead return an entirely distinct array. Since arrays are conceptually a contiguous list of items, it helps code clarity and maintainability a lot to be able to operate on them in a "functional" way. (I'll also insist on referring to an array as a "list" - although in some languages, List is a native data type, in JS and this post, I'm referring to the concept. Everywhere I use the word "list" you can assume I'm talking about a JS Array) This means, to perform a single operation on the list as a whole ("atomically"), and to return a new list - thus making it mu

@evie404
evie404 / server.py
Last active September 14, 2016 00:07 — forked from ibeex/foo.log
Flask logging example
import logging
from logging.handlers import RotatingFileHandler
from flask import Flask
app = Flask(__name__)
@app.route('/')
def foo():
paifor x in range(0, 3):
@jonsuh
jonsuh / gist:e93fbfbf994b5478d4bc
Last active November 6, 2015 09:23
Change Twitter’s Heart Animation to Exploding Poopies
.HeartAnimationContainer .HeartAnimation {
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAC1QAAABkCAYAAAA7MJAoAABZBElEQVR42uzBAQEAAACAkP6v7ggCAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIDZgwMBAAAAACD/10ZQVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVXYuXuWKOAAjuP/paF3UO8gaAwJ90Ck1E49HygDL+ye8s5DF0kzMJCgGhxssMDFoRIqbPAp7zofwG5IaqkhagjaImhw/LdF0VbQqXw+b+G7/vjB/1cb6i4F9ECLA2B9dKBxdTTTGNg3VooXCwE9AAAAAAAAONzK7Q3HNy+dGd9OnDoW0IM/7PQ3na/1NyUCeqCHHmhxIJWLPaXHY6W4UuwbCeiBFvvccr6nupTvrQUAAAAAAADgcKukmi9UU83dgX1ha2JwrHItG7duDE4F9OA3cebOkZXJkXfLk8Mf9+5PHw3ogR56oMWB8yLd9nAp0/t5NZ1YDOiBFgAAAAAAAGDAS71VryYbXuaTn6r55PeNwa7Tgbp6kz53Ynm88PXB1ERcvD60t5vvOBnQg582My0L86Urca6Uj+V060JAD/TQAy0AAAAAAAAAAANe/sX2zeHF5zN349PpW3Hr9lg5UFeb2bbdR/2tca5QjPOpZKykW14H9ODX177b5Wzn20q2+/1auu1eQA/00AMtAAAAAAAAAMAbsgEvf2sn3dK+lOv6NltIxdnC5fgk1xtrA2c7AnWznkmkKrn2D6+G+p5t5Dq/rGUShYAeAAAAAMAP9u7npek4juP4hyAo+gfqTwi6RZDUSQJbufS7NbdpTTfS77bvvvsqbaBpP0AhITyUUIc6pUZ
@rondevera
rondevera / git-changelog
Created November 4, 2014 02:56 — forked from jfsiii/git-changelog
Generates a Markdown changelog for a npm/bower repo
#!/usr/bin/env bash
function printCommitLine(){
local FROM=$1
local TO=$2
if [ TO ]; then
git log $GIT_LOG_OPTS --format="$LOG_FORMAT_OPTS" $FROM..$TO
else
git log $GIT_LOG_OPTS --format="$LOG_FORMAT_OPTS" $FROM
fi
@jfsiii
jfsiii / git-changelog
Created October 9, 2014 23:55
Simple bash script to generate a changelog based on tags & commit messages
#!/usr/bin/env bash
function printCommitLine(){
local FROM=$1
local TO=$2
if [ TO ]; then
git log $GIT_LOG_OPTS --format="$LOG_FORMAT_OPTS" $FROM..$TO
else
git log $GIT_LOG_OPTS --format="$LOG_FORMAT_OPTS" $FROM
fi
@addyosmani
addyosmani / README.md
Last active April 2, 2024 20:18 — forked from 140bytes/LICENSE.txt
108 byte CSS Layout Debugger

CSS Layout Debugger

A tweet-sized debugger for visualizing your CSS layouts. Outlines every DOM element on your page a random (valid) CSS hex color.

One-line version to paste in your DevTools

Use $$ if your browser aliases it:

~ 108 byte version

@jfsiii
jfsiii / gist:ed665a1dec5381407b8e
Created June 29, 2014 21:26
Unexpected behavior from semver for pre-release versions.

From point 9 of the SemVer spec:

A pre-release version indicates that the version is unstable and might not satisfy the intended compatibility requirements as denoted by its associated normal version. Examples: 1.0.0-alpha, 1.0.0-alpha.1, 1.0.0-0.3.7, 1.0.0-x.7.z.92.

However, the package npm uses to process semver values provides no way to specify a range which excludes pre-release versions.

‣ semver --range '~1.2.3' 1.2.3 1.2.4-alpha 1.2.4 1.3.0-alpha 1.3.0 2.0.0-alpha
1.2.3
1.2.4-alpha
1.2.4
‣ semver --range '^1.2.3' 1.2.3 1.2.4-alpha 1.2.4 1.3.0-alpha 1.3.0 2.0.0-alpha
@gruber
gruber / Liberal Regex Pattern for Web URLs
Last active April 22, 2024 19:02
Liberal, Accurate Regex Pattern for Matching Web URLs
The regex patterns in this gist are intended only to match web URLs -- http,
https, and naked domains like "example.com". For a pattern that attempts to
match all URLs, regardless of protocol, see: https://gist.github.com/gruber/249502
# Single-line version:
(?i)\b((?:https?:(?:/{1,3}|[a-z0-9%])|[a-z0-9.\-]+[.](?:com|net|org|edu|gov|mil|aero|asia|biz|cat|coop|info|int|jobs|mobi|museum|name|post|pro|tel|travel|xxx|ac|ad|ae|af|ag|ai|al|am|an|ao|aq|ar|as|at|au|aw|ax|az|ba|bb|bd|be|bf|bg|bh|bi|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|cr|cs|cu|cv|cx|cy|cz|dd|de|dj|dk|dm|do|dz|ec|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gg|gh|gi|gl|gm|gn|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|im|in|io|iq|ir|is|it|je|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|me|mg|mh|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|mv|mw|mx|my|mz|na|nc|ne|nf|ng|ni|nl|no|np|nr|nu|nz|om|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|ps|pt|pw|py|qa|re|ro|rs|ru|rw|sa|sb|sc|sd|se|sg|sh|si|s
@gpessia
gpessia / Helvetica Neue stack
Created January 24, 2014 11:28
Helvetica Neue CSS font-family stack. Is there a web-safe Helvetica Neue CSS font-family stack? - See more at: http://rachaelmoore.name/posts/design/css/web-safe-helvetica-font-stack/#sthash.lt6rYYGz.dpuf
/**
* Helvetica Neue Normal (No Stretch)
*/
/* Helvetica Neue Black Font Stack */
.{font-family: "HelveticaNeueBlack", "HelveticaNeue-Black", "Helvetica Neue Black", "HelveticaNeue", "Helvetica Neue", 'TeXGyreHerosBold', "Arial Black", sans-serif; font-weight:800; font-stretch:normal;}
/* Helvetica Neue Heavy Font Stack */
.{font-family: "HelveticaNeueHeavy", "HelveticaNeue-Heavy", "Helvetica Neue Heavy", "HelveticaNeue", "Helvetica Neue", 'TeXGyreHerosBold', "Arial Black", sans-serif; font-weight:700; font-stretch:normal;}
@rixth
rixth / git-integrate.zsh
Created March 1, 2013 21:55
Usage: git-integrate base-branch <branches-to-merge>*
function git-integrate () {
integration_branch="integration_$RANDOM"
base_branch=$1
delete_integration_branch () {
echo "Checking back out to $base_branch"
git checkout $base_branch
echo "Deleting integration branch $integration_branch"
git branch -D $integration_branch
}