Skip to content

Instantly share code, notes, and snippets.

What kind of iteration to use when in JavaScript

For loops

for (var i = 0; i < array.length; i++) {
}
  • Code has to run in old versions of IE.
@tmcw
tmcw / code_style.md
Last active June 3, 2016 19:06
On Code Style

You might be expecting a long rant on why code style matters and tabs are sinful in your JavaScript code. This isn't that, thankfully.

If you've been snooping around ★★REDACTED★★★, you may have noticed that, in contrast to our other projects, it uses 2 spaces for indentation instead of 4. This was a decision Eden, Lauren, and I made, given that we kind of just started out that way, and that two-tab indentation makes our somewhat absurd functional chains easier on the eyes and the widths.

This also allows us to say that we simply use the Airbnb code style rather than saying we use it with a carveout as we've written for mapbox.js and iD.

This isn't an announcement that we're switching to 2 spaces, but rather a statement of how we treat code style and deal with these differences:

Use one code style for your whole project, and be consistent

@mrmrs
mrmrs / github-display-none.css
Last active November 2, 2019 03:09
Single purpose rulesets to set an element to display none from githubs production css
.table-list-triage {
display: none;
}
.triage-mode .table-list-non-triage, .triage-mode .table-list-filters {
display: none;
}
.boxed-group-list>li.approved .btn-sm, .boxed-group-list>li.rejected .btn-sm {
display: none;
}
.repo-list .participation-graph.disabled {
@opattison
opattison / 2016-02-13-example.md
Last active April 25, 2016 20:34
Jekyll srcset imgix implementation with include file, srcset/sizes in config, YAML-provided images, and temporarily assigned variables
title image
example srcset implementation
src alt
/images/example.jpg
Don’t forget alt text.

{% assign image = page.image[0] %} {% include srcset.html %}

const fs = require('fs');
const d3 = require('d3-dsv');
const path = require('path');
const yaml = require('js-yaml');
const toMarkdown = require('to-markdown');
d3.csvParse(
fs.readFileSync('./goodreads_library_export.csv', 'utf8')
).filter(row => {
return row['Exclusive Shelf'] !== 'to-read';