Skip to content

Instantly share code, notes, and snippets.

View rivertam's full-sized avatar
🎑
who can keep track

Ben Berman rivertam

🎑
who can keep track
View GitHub Profile
@rivertam
rivertam / alignment_debug.txt
Created July 29, 2019 10:05
Alignment debug output of the stack overflow question
print-type-size type: `Big`: 24 bytes, alignment: 8 bytes
print-type-size discriminant: 1 bytes
print-type-size variant `Sixteen`: 16 bytes
print-type-size field `.0`: 16 bytes
print-type-size variant `Float`: 15 bytes
print-type-size padding: 7 bytes
print-type-size field `.0`: 8 bytes, alignment: 8 bytes
print-type-size variant `Twelve`: 12 bytes
print-type-size field `.0`: 12 bytes
print-type-size variant `Eight`: 8 bytes
const benchmark = require('benchmark');
const suite = new benchmark.Suite();
suite.add('var loop', () => {
var hi, i, list;
list = [];
for (i = 0; i < 50; ++i) {
hi = { str: 'hi', i };
@rivertam
rivertam / Catbrand.js
Created March 14, 2018 13:51
Getting count of brands
categorySchema.find({})
.exec()
.then(categories => {
// When you return a promise from a .then callback, the promise that gets returned from the original .then
// resolves when the inner promise that you return resolves
return Promise.all(categories.map(cat=> {
return brandSchema.find({category: cat._id}).count()
}));
})
.then(counts => {
@rivertam
rivertam / klass.h
Created December 20, 2017 19:02
Nice constructor style
class Klass {
Klass(const Param & p1, const Param & p2)
:
m1(p1),
m2(p2)
{}
Param m1;
Param m2;
}
@rivertam
rivertam / reduce.rb
Created October 31, 2017 21:12
What is reduce?
arr = ["cup", "cake", "birthday", "Jesus"]
# this will print "cup\ncake\nbirthday\nJesus", as you can imagine
for word in arr
puts word
end
def add_em_up()
acc = 5
for word in arr
@rivertam
rivertam / hola.log
Created June 24, 2017 02:45
Neovim profiling
FUNCTION airline#extensions#neomake#get_errors()
Called 340 times
Total time: 0.006676
Self time: 0.002922
count total (s) self (s)
340 0.005072 0.001318 let counts = neomake#statusline#LoclistCounts()
340 0.000847 let errors = get(counts, 'E', 0)
340 0.000525 return errors ? s:error_symbol.errors : ''
@rivertam
rivertam / checkhealth.out
Created June 23, 2017 23:39
:CheckHealth
health#deoplete#check
========================================================================
## deoplete.nvim
- SUCCESS: has("nvim") was successful
- SUCCESS: has("python3") was successful
- INFO: If you're still having problems, try the following commands:
$ export NVIM_PYTHON_LOG_FILE=/tmp/log
$ export NVIM_PYTHON_LOG_LEVEL=DEBUG
$ nvim
@rivertam
rivertam / pls-projects.md
Created June 8, 2017 06:59
Projects I want to do eventually some day maybe
  • Actually reasonable Mongo driver (with pluggable schema validators)
  • Reasonable Mongo schema validator
  • Nestable routes for zeit/micro
  • Nice test suite ergonomics
    • Ava actually does a much better job than Mocha or Jest here
    • Want context variables (like in Ava)
    • Want chainable middleware context and describe (each can mutate context variables and have their own lifecycle hooks (beforeEach, before, etc.)
  • Babel plugin to transform arrow function class properties to be implemented using prototype and bind rather than making the function in the constructor
  • Doing a bind is cheaper than creating the whole function every time!
@rivertam
rivertam / mongoose-sucks.md
Created May 17, 2017 18:36
Issues I have with Mongoose
  • It adds defaults to models if the schema has them, but does not remove invalid fields from .toJSON when pulling them out of Mongo
    • But it does remove it for the model object
    • .inspect reflects the .toJSONversion, so debugging is basically impossible
  • Can't use object spread with a model to get a new version of it
  • There's no way to have .update update the model in-place
  • I mean I don't want it to be the default, but having the option would be nice
@rivertam
rivertam / newsletter.html
Created November 14, 2016 16:48
Newsletter w/ A Plus LiveIntent
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/><!--[if !mso]><!-->
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/><!--<![endif]-->
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>A Plus Weekly Newsletter</title><!--[if gte mso 9]>
<style type="text/css">
.img {