Skip to content

Instantly share code, notes, and snippets.

David Normington davidnormo

  • UK
Block or report user

Report or block davidnormo

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@davidnormo
davidnormo / pixelToTwips.js
Created Apr 6, 2014
CSS Pixel to Twips Conversion
View pixelToTwips.js
/**
* Pixels to Twips conversion
* @param {Int} pixels
* @return {Int}
* /
var pixelsToTwips = function(pixels){
return pixels * 15;
};
/**
@davidnormo
davidnormo / prayer pre-commit hook
Last active Aug 29, 2015
A pre-commit hook to remember to pray over your work
View prayer pre-commit hook
#!/bin/sh
#accept stdin input
exec < /dev/tty
#prompt user
read -p "Have you prayed? " -n 1 -r
#complete on new line
echo
@davidnormo
davidnormo / closures.js
Created Jul 28, 2014
Javascript Closures
View closures.js
/**
* Be careful of closure behaviour, it might not give you values you expect!
* For example when you have timeouts or event listeners.
*/
(function(){
var i = 0,
arr = ['a','b','c','d'],
doSomething = function(localKey){
console.log('i:', i);
console.log('localKey:', localKey);
@davidnormo
davidnormo / index.js
Created Jul 15, 2015
es6-tagged-template-strings.js
View index.js
let asAttrs = (strings, value) => {
let attrs = [];
for (let prop in value) {
let val = value[prop];
if (typeof val === 'boolean'){
attrs.push(`${prop}` + (val ? '' : '=false'));
} else {
attrs.push(`${prop}="${val}"`);
}
}
View JSX_Explored.md

JSX Explored

It is very common to see JSX and React together and you'd (almost) be forgiven for thinking they were part of the same library. That is, until you came to use React and found that you had to compile any JSX before being able to run your code.

JSX is completely separate to React. Take a look: https://facebook.github.io/jsx. JSX is an ECMAscript syntax extension specification. It is intended as a declarative, Domain Specific Language (DSL) that can be compiled to Javascript.

In essence, the React JSX transpiler takes this:

<MyComponent />;
@davidnormo
davidnormo / npm-global-export-import.md
Last active Mar 31, 2016
npm global export import
View npm-global-export-import.md

The following command will give you a string of all the npm packages and their versions that are currenctly globally installed.
Note: that this ignores packages installed from directories and picks only those installed via the npm registry.

$ npm ls -g --depth 0 | sed -e '1d' -e 's/└── //g' -e 's/├── //g' -e '/^.*->.*$/d' -e '/^$/d' | tr '\n' ' '

If you copy this string, you can then append it to the end of npm install -g to install all of the packages.

@davidnormo
davidnormo / removingJsCode.md
Last active May 11, 2016
Removing Javascript Code
View removingJsCode.md

Tips for removing javascript code

  1. Removing files should be relatively safe. If you miss any references your build system should fail, hopefully with the problem files if the tool is any good.

  2. Removing scoped code can be done if all references to them are removed from within the scope. E.g. references to a local variable within a method or references to a function within a module.

  3. Removing public functions, that are exported by a module or added to the global scope, cannot be done deterministically due to the dynamic nature of javascript. Try the following:

    • grep code base looking for method uses (Warning: may not catch all cases e.g. myObj['method']() or myObj[getMethodName()]() etc)

    • grep code looking for the import of the containing module, then further grep to find method references: grep -ril path/to/my/module www/src | xargs grep -ril myMethodName

View _media-queries.scss
// Media Queries in Sass 3.2
//
// These mixins make media queries a breeze with Sass.
// The media queries from mobile up until desktop all
// trigger at different points along the way
//
// And important point to remember is that and width
// over the portrait width is considered to be part of the
// landscape width. This allows us to capture widths of devices
// that might not fit the dimensions exactly. This means the break
View .tmux.conf
## Better colors
set -g default-terminal "screen-256color"
## Fix the clipboard access (`brew install reattach-to-user-namespace`)
set-option -g default-command "reattach-to-user-namespace -l bash"
# Use vim keybindings in copy mode
setw -g mode-keys vi
## Change prefix
@davidnormo
davidnormo / configToOpts
Created Jun 24, 2017
json config file to cmd opts string
View configToOpts
#!/usr/local/bin/node
const fs = require('fs');
const configPath = process.argv[2];
fs.readFile(configPath, (err, data) => {
if (err) {
console.error(err);
process.exit(1);
You can’t perform that action at this time.