Skip to content

Instantly share code, notes, and snippets.

@kara-ryli
kara-ryli / date-ago.js
Created March 30, 2011 20:33
YUI module for calculating the time ago in words in English. Updated from the Prototype version and optimized for compressor.
YUI.add('date-ago', function (Y) {
function round(value) {
return Math.round(value);
}
function distanceOfTimeInWords(from_time, to_time, include_s) {
var include_seconds, distance_in_minutes, distance_in_seconds;
include_seconds = include_s || false;
distance_in_minutes = round(Math.abs(to_time - from_time) / 60000);
@kara-ryli
kara-ryli / 1.number-to-ord.js
Created April 5, 2012 20:00
Converts an integer into a its proper ordinal ("1st", "2nd", "3rd", "4th")
/*global YUI*/
/**
* Converts an integer into a its proper ordinal ("1st", "2nd", "3rd", "4th")
* @module number-to-ord
*/
YUI.add("number-to-ord", function (Y) {
"use strict";
/**
* Converts an integer into a its proper ordinal ("1st", "2nd", "3rd", "4th")
*
@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 / MyAppDelegate.m
Created October 20, 2011 22:21
Create a device-specific identifier in Objective-C
@implementation MyAppDelegate
/**
* Generates a Universally Unique Identifier based on the time and
* hardware details of a device. CFUUIDCreate is the recommended
* way by Apple to generate an ID now that UIDevice-uniqueIdentifier
* is deprecated.
*
* Props: http://www.cocoabuilder.com/archive/cocoa/217665-how-to-create-guid.html#217668
*/
@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 / toggle-hex-rgb.rb
Created January 12, 2012 22:47
TextMate Command to toggle hex and RGB color values
#!/usr/bin/env ruby
input = STDIN.read
match = /^\s*rgba?\(\s*(\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})(?:,[\d\.]+)?\s*\)(\s*;?)/.match(input)
if !match.nil? # RGB -> Hex
res = "#"
short_safe = true
matches = [match[1], match[2], match[3]].map do |m|
h = m.to_i.to_s(16)
if h.length == 1
@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 / forms-and-pets.md
Last active February 9, 2016 21:48
Complete List of Druid forms and Ranger Pets