Skip to content

Instantly share code, notes, and snippets.

@kara-ryli
kara-ryli / cify-lambda-capture.cpp
Created October 17, 2020 16:27
I'm still learning the nuances of C and C++; it's a big change from JavaScript. Here's a problem that has such a simple implementation in JS that I never considered the complexity of doing it in C++.
// This file represents a simplification of a scope problem I have interacting
// with a C SDK. Essentially:
//
// * I to pass a callback to a C function
// * The callback should call a member function of a non-static class instance
//
// I would like to achieve this without risking memory leaks and crashes, while
// also not introducing a huge amount of complexity or rearchitecting the app.
#include <iostream>
@kara-ryli
kara-ryli / node-find.sh
Created June 17, 2017 01:54
Find files that reference a node module
# can add this to ~/.bash_profile
node-find() {
grep -r --exclude-dir node_modules --include "*.js" "require([\"']$1[\"'/]" . | cut -d ':' -f1 | sort | uniq
}
{
"extends": [
"eslint:recommended"
],
"rules": {
"valid-jsdoc": [
"warn",
{
"prefer": {
"return": "returns",
@kara-ryli
kara-ryli / stahp.js
Last active July 22, 2016 21:19
Bookmarklet to silence annoying web site.
Array.from(document.querySelectorAll('object,video,audio,iframe,embed')).forEach(el => el.remove());
@kara-ryli
kara-ryli / al-curse-of-strahd.js
Last active May 17, 2016 12:22
JavaScript port of Curse of Strahd backgrounds for MPMB's Character Record Sheet
/*global BackgroundList,BackgroundFeatureList*/
/*jshint sub:true*/
/* See http://web.archive.org/web/20160426193612/http://dndadventurersleague.org/wp-content/uploads/2016/04/Curse-of-Strahd-Backgrounds-v1.1.pdf */
BackgroundList["black fist double agent"] = {
regExpSearch : /black\W*fist/i,
name : "Black Fist Double Agent",
source : ["HB", 1],
skills : ["Deception", "Insight"],
gold : 15,
equipleft : [
@kara-ryli
kara-ryli / events.js
Created October 16, 2015 20:54
Dead-simple event handling polyfills. Based largely on http://youmightnotneedjquery.com/
/**
* Dead-simple event handling polyfills. Based largely on
* http://youmightnotneedjquery.com/
*/
/**
* IE-safe removeEventListener polyfill. Not exported to avoid bugs
* caused by wrapping the event handler in IE8.
*
* @param {Window|Document|HTMLElement} el Element to listen on
@kara-ryli
kara-ryli / v8-opt.js
Created February 6, 2015 23:02
A tip I picked up from Fluent 2014
// V8 initializes memory space for _x and _y
// in advance
function Klass1() {
this._x = null;
this._y = null;
}
var k1 = new Klass1()._x = 'hi';
function Klass2() {}
// dynamically defined property converts to a
@kara-ryli
kara-ryli / forms-and-pets.md
Last active February 9, 2016 21:48
Complete List of Druid forms and Ranger Pets
@kara-ryli
kara-ryli / jshintrc-plus-grunt.js
Last active August 29, 2015 13:57
grunt-contrib-jshint requires *either* a jshintrc file or other options. I reject that dichotomy.
'use strict';
module.exports = function (grunt) {
var jshintrc = grunt.file.readJSON('.jshintrc');
// super simple shallow copy/merge
function merge(o1, o2) {
var retVal = {}, i;
for (i in o1) {
@kara-ryli
kara-ryli / paginator.liquid
Created October 14, 2013 03:24
Generate PURE-style paginators in a Jekyll blog (e.g. GitHub Pages)
{% comment %}
Generate PURE Paginators in a Jekyll blog:
http://purecss.io/menus/#paginators
http://jekyllrb.com/docs/pagination/
The `page_spread` determines how wide the paginator is; it's the
number of links on either side of the center link, so you'll end
up with a list of the following sizes: