Skip to content

Instantly share code, notes, and snippets.

tl;dr: The problems inherent in jQuery dependency should not be resolved by not depending on jQuery or some other $-providing library. Rather, library authors should write library code that expects a $ will be injected that meets the library's needs.

The problem:

In the front-end JS world, there is a movement to be dependency-free, and specifically to be jQuery dependency free. This problem seems to be the result of a pre-package management mindset. But those days are long gone, or, they should be.

The result of this mindset, however, tends to not be pretty: library authors write their own, often minimally tested, DOM manipulation and utility belt routines. If you come to depend on multiple or many such libraries, your code, via their code, then comes to contain dozens of diverse implementations of similarly or identically-purposed functions.

users table:

[
  {
     id: 123,
     things: [1, 2, 3]
  }
]
@dminkovsky
dminkovsky / Program
Created July 2, 2014 17:02
64-bit random numbers in Node
var bignum = require('bignum');
var crypto = require('crypto');
var randomBignum = function() { return bignum.fromBuffer(crypto.pseudoRandomBytes(8)); }
var avg = randomBignum();
var avg_len = avg.bitLength();
var lengths = {};
for (var i = 0; i < 1e6; i++) {
// Index:
r.table("heroes").indexCreate("idEquipment", function(doc) {
return doc("equipment").map(function(equipment) {
return [doc("id"), equipment]
})
}, {multi: true}).run(conn, callback)
// Query
r.table("heroes").getAll([1, "boots"], {index: "idEquipment"}).run(conn, callback)
r.db('test').table('crap').get("dd3badb0-9c30-4ef5-978a-c034461d58ca").update({
unit_data: r.literal(r.row('unit_data').without('state'))
})
r.db('crap').table('junk')
.get(2)
.update({
'revisions': r.row('revisions').append(r.row('revisions').nth(-1).do(function(row) {
return row.merge({
v: row('v').add(1)
})
}))
})
r.table('junk').update({
myArray: []
})
// Doesn't this re-write doc.myArray with the result of r.row('myArray').append()?
// If so, and if doc.myArray is long, would this be slow? Or consume lots of RAM, at least.
r.table('junk').update({
myArray: r.row('myArray').append('something')
@dminkovsky
dminkovsky / Query 1
Created August 25, 2014 15:21
Rethink Issue data
[
{
"description": "Evaluating map.",
"duration(ms)": 62.225767,
"sub_tasks": [
{
"description": "Evaluating make_array.",
"duration(ms)": 0.042675,
"sub_tasks": [
{
var Promise = require('bluebird');
var r = require('rethinkdb');
var conn;
// Manage a 1-connection "pool";
function getConnection() {
if (conn) { return Promise.resolve(conn); }
return r.connect({ db: 'lm' })
.then(function(c) { return conn = c; })
.catch(function(err) { console.log(err.stack || err); })
# No rethinks running
[root@coreos-1 ~]# dig rethinkdb-29015.skydns.local @127.0.0.1 [4/528]
; <<>> DiG 9.9.4-P2-RedHat-9.9.4-15.P2.fc20 <<>> rethinkdb-29015.skydns.local @127.0.0.1
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 9478
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 0