Skip to content

Instantly share code, notes, and snippets.

@leakypixel
leakypixel / mongo-search-all.js
Last active May 11, 2017 15:45
Search all collections and fields in mongoDB
function SearchAll(regexp) {
var results = {};
var all = db.getCollectionNames();
var results = [];
for (var i in all) {
var coll = all[i];
if (coll == "system.indexes") continue;
results[coll] = [];
db[coll].find().forEach(
function(doc) {
@leakypixel
leakypixel / always-mobile-wikipedia.js
Last active May 26, 2019 22:19
UserScript: Redirect desktop Wikipedia to mobile
// ==UserScript==
// @name always_mobile_wikipedia
// @namespace https://gist.github.com/leakypixel
// @description Redirect desktop Wikipedia to mobile
// @author leakypixel
// @include http://*.wikipedia.org/*
// @include https://*.wikipedia.org/*
// @version 0.2
// @grant none
// ==/UserScript==
@leakypixel
leakypixel / bem-style-guide.md
Last active August 29, 2015 14:27
My BEM Style Guide

BEM Guidelines

This is my personal preference for writing BEM SCSS, I don't have any assumptions that this is 'the best way' or anything like that - just what works for me. I'm interested to hear any comments or suggestions, there's always room for improvement!

Preamble

BEM allows us to use a single classname for an element (thus speeding up it's selection), while making it clear what elements belong to which blocks. This aids in maintainability, as you get context from a file without needing to see the DOM while not making our CSS dependent on the DOM structure.

BEM's methodology relies on the following naming convention: .block__element--modifier, which you can read more about here.

The goals for this BEM style are:

@leakypixel
leakypixel / responsive-fairy-cakes.md
Last active August 29, 2015 14:22
Responsive Fairy Cakes

Responsive Fairy Cakes

James has a really good recipe for fairy cakes that he's going to take to a party, but he knows that people's tastes and dietary requirements are different, so he compiles a list of the considerations:

  • Angie doesn't want aspartame, because she's read some pseudo-scientific bullshit that tells her it's poisonous.
  • Jack is diabetic, so can't have sugar.
  • Harry really doesn't like coconut.
  • Lisa doesn't like real strawberries, but does like strawberry-flavoured things.

James' budget only goes so far, so there's that to consider, and his original recipe has the following ingredients:

  • Sugar
@leakypixel
leakypixel / considered-css.md
Last active September 29, 2015 21:12
Writing considered CSS

Writing considered CSS

CSS is read from right to left

  • This means that your browser finds the right-most sub-selector first, then tests each item that matches to see if it matches the next sub-selector
  • Avoid using element sub-selectors, and the * for this reason - every element that matches this sub-selector will be tested (that can be a lot of elements!)

Specificity - keep it short

  • Specificity is the biggest pain in the arse about CSS, so make it easier for future-you by not being overly specific
  • If you make a selector overly specific, the next time you use that component you'll have to be more specific and so on - imagine that after using something 5+ times
  • Consider that every time you nest something in your SCSS, you're adding another sub-selector - do you really need to nest it there, or would it style it without being even more specific?
@leakypixel
leakypixel / js-comparison-notes.md
Last active August 29, 2015 14:02
JavaScript comparison notes

###JavaScript has both strict and type-converting comparison.

For strict equality the objects being compared must have the same type, and:

  • Two strings are strictly equal when they have the same sequence of characters, same length, and same characters in corresponding positions.
  • Two numbers are strictly equal when they are numerically equal (have the same number value).
  • NaN is not equal to anything, including NaN.
  • Positive and negative zeros are equal.
  • Boolean operands are strictly equal if both are true or both are false.
  • Objects are strictly equal only if they refer to the same Object instance.
  • Null and Undefined are ==, but not === (they're not of the same type, because they have no real type - they're absence).