Skip to content

Instantly share code, notes, and snippets.

@davidnormo
davidnormo / JSX_Explored.md
Last active August 29, 2015 14:26
JSX Explored

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 / index.js
Created July 15, 2015 12:38
es6-tagged-template-strings.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}"`);
}
}
@davidnormo
davidnormo / closures.js
Created July 28, 2014 15:26
Javascript Closures
/**
* 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 / main.js
Last active May 17, 2022 16:56
jsPDF as email attachment
var pdf = new jsPDF();
pdf.text(0, 0, 'Hello World!');
var pdfBase64 = pdf.output('datauristring');
window.plugin.email.open({
to: ['to@email.com'],
subject: 'New PDF!',
body: 'Hi there, here is that new PDF you wanted!',
isHTML: false,
attachments: [pdfBase64]
@davidnormo
davidnormo / prayer pre-commit hook
Last active August 29, 2015 14:01
A pre-commit hook to remember to pray over your work
#!/bin/sh
#accept stdin input
exec < /dev/tty
#prompt user
read -p "Have you prayed? " -n 1 -r
#complete on new line
echo
// 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
@davidnormo
davidnormo / pixelToTwips.js
Created April 6, 2014 20:49
CSS Pixel to Twips Conversion
/**
* Pixels to Twips conversion
* @param {Int} pixels
* @return {Int}
* /
var pixelsToTwips = function(pixels){
return pixels * 15;
};
/**