Skip to content

Instantly share code, notes, and snippets.

Avatar

David Padbury davidpadbury

View GitHub Profile
View keybase.md

Keybase proof

I hereby claim:

  • I am davidpadbury on github.
  • I am davidpadbury (https://keybase.io/davidpadbury) on keybase.
  • I have a public key ASASQeIyksvA4KVZfOejG7jbSFboYvEjfmR48UpJsk652Ao

To claim this, I am signing this object:

View example-query.js
const sql = `select whatever from somewhere where something = ? and something-else = ?`
await knex.raw(sql, [ something, somethingElse ])
View sql-tagged-template-string-usage.js
const knex = require('knex')({
client: 'mysql',
connection: { ... }
})
const result = await sql(knex)`select whatever from somewhere where something = ${something} and something-else = ${somethingElse}`
View sql-tagged-template-string.js
function sql (executor) {
return (strings, ...values) => executor.raw(strings.join('?'), values)
}
View mdn-tagged-template-strings.js
var a = 5;
var b = 10;
function tag(strings, ...values) {
console.log(strings[0]); // "Hello "
console.log(strings[1]); // " world "
console.log(values[0]); // 15
console.log(values[1]); // 50
return "Bazinga!";
View example query
const sql = `select whatever from somewhere where something = ? and something-else = ?`
await knex.raw(sql, [ something, somethingElse ])
@davidpadbury
davidpadbury / test.js
Created Jun 30, 2011
Test for dynamic loading
View test.js
function load(el) {
console.log('loaded');
}
View log.css
@media screen {
@font-face {
font-family: 'Annie Use Your Telescope';
font-style: normal;
font-weight: normal;
src: local('Annie Use Your Telescope'), local('AnnieUseYourTelescope'), url('http://themes.googleusercontent.com/font?kit=2cuiO5VmaR09C8SLGEQjGgtSTT_xyPSRqbb82lxMsRH3rGVtsTkPsbDajuO5ueQw') format('woff');
}
}
ul.log {
@davidpadbury
davidpadbury / log.js
Created May 20, 2011
Really dull log function
View log.js
function log(msg) {
var ul = $('ul.log');
if (!ul.length) {
ul = $('<ul>').addClass('log').prependTo('body');
}
$('<li>').text(msg).appendTo(ul);
}
@davidpadbury
davidpadbury / pubsub.js
Created May 11, 2011
Extremely basic pubsub example (please don't use it)
View pubsub.js
(function(global) {
var subs = {},
slice = Array.prototype.slice;
global.pubsub = {
sub: function(topic, fn, ctx) {
var sub = subs[topic] || (subs[topic] = []);
sub.push({