Skip to content

Instantly share code, notes, and snippets.

var costMagnitudeRoll = ~~(Math.random() * 100);
if (costMagnitudeRoll < 70) {
cost = Math.random() * 30;
}
else if (costMagnitudeRoll < 90) {
cost = Math.random() * 70 + 30;
}
else if (costMagnitudeRoll < 99) {
cost = Math.random() * 400 + 100;
@jimkang
jimkang / Remove Twitter Conversations.js
Last active August 29, 2015 13:56
Remove Twitter Conversations bookmarklet.
<a href="javascript:var convos = document.querySelectorAll('.conversation-module'); for (var i = 0; i < convos.length; ++i) { var convo = convos[i]; convo.parentNode.removeChild(convo); }">Remove conversations</a>
@jimkang
jimkang / Default (OSX).sublime-keymap
Last active August 29, 2015 13:56
Sublime group focus/moving keybindings. Goes in ~/Library/Application Support/Packages/User.
[
{ "keys": ["super+shift+,"], "command": "focus_group", "args": { "group": 0 } },
{ "keys": ["super+shift+."], "command": "focus_group", "args": { "group": 1 } },
{ "keys": ["super+shift+/"], "command": "focus_group", "args": { "group": 2 } },
{ "keys": ["alt+super+,"], "command": "move_to_group", "args": { "group": 0 } },
{ "keys": ["alt+super+."], "command": "move_to_group", "args": { "group": 1 } },
{ "keys": ["alt+super+/"], "command": "move_to_group", "args": { "group": 2 } },
{ "keys": ["super+1"], "command": "focus_group", "args": { "group": 0 } },
@jimkang
jimkang / Preferences.sublime-settings
Last active August 29, 2015 13:56
Sublime user prefs. Goes in ~/Library/Application Support/Packages/User
{
"color_scheme": "Packages/User/Color Schemes/idleFingers.tmTheme",
"font_face": "Lucida Console",
"font_size": 12,
"tab_size": 2,
"translate_tabs_to_spaces": false,
"rulers": [80]
}
@jimkang
jimkang / example.js
Last active August 29, 2015 13:56
Wraps a function such that the execution of calls to that function are spaced out by the wait time specified. It's like throttling, except that instead of ignoring calls that happen too close together, it queues them for later.
var spacedOutSearchProducts = space(searchProducts, 1000);
spacedOutSearchProducts('one');
spacedOutSearchProducts('two');
spacedOutSearchProducts('three');
spacedOutSearchProducts('four');
// Now searchProducts will be called four times, one second apart.
@jimkang
jimkang / gist:9678825
Created March 21, 2014 03:18
Build error
Building native extensions. This could take a while...
ERROR: Error installing wgif:
ERROR: Failed to build gem native extension.
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby extconf.rb
checking for Ruby version >= 1.8.5... yes
checking for xcrun... yes
checking for Magick-config... yes
checking for ImageMagick version >= 6.4.9... yes
checking for HDRI disabled version of ImageMagick... yes
@jimkang
jimkang / README.md
Created March 28, 2014 19:17 — forked from mbostock/.block

This demonstrates finding the closest point to the mouse by searching a quadtree. As you descend into the quadtree, you track the closest point yet found and avoid searching cells that cannot contain closer points. Importantly, you must descend preferentially into closer cells so as to restrict the search more quickly.

Patrick Surry implemented a similar solution months earlier!

@jimkang
jimkang / combinevisitfunctions.js
Created April 14, 2014 18:01
Generates a D3 quadtree visit function that performs a series of operations on each visited node.
function combineVisitFunctions() {
var fns = arguments;
return function combinedVisit(node, x1, y1, x2, y2) {
for (var i = 0; i < fns.length; ++i) {
fns[i](node, x1, y1, x2, y2);
}
};
}
@jimkang
jimkang / index.html
Last active August 29, 2015 14:01 — forked from mbostock/.block
A bounded force-directed graph layout with "gravity" at the bottom of the bounds and collision detection/reaction among the nodes.
<!DOCTYPE html>
<html>
<head>
<title>Ball drop with force-directed layout and collision detection</title>
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<style type="text/css">
circle {
stroke-width: 1.5px;
}
@jimkang
jimkang / index.html
Last active August 29, 2015 14:01
Radial and linear gradients, animated.
<svg width="800" height="600">
<defs>
<radialGradient id="sphere-gradient">
<stop offset="0" stop-color="hsl(30, 100%, 80%)"/>
<stop offset="0.75" stop-color="hsl(20, 100%, 60%)">
<animate attributeName="offset" values="0.75;0.9;0.75" keySplines="0.1 0.8 0.2 1; 0.1 0.8 0.2 1; 0.1 0.8 0.2 1" dur="4s" repeatCount="indefinite" />
</stop>
<stop offset="1" stop-color="hsl(10, 100%, 50%)">
<animate attributeName="stop-color" values="hsl(10, 100%, 50%);hsl(40, 100%, 70%);hsl(10, 100%, 50%)" keySplines="0.1 0.8 0.2 1; 0.1 0.8 0.2 1; 0.1 0.8 0.2 1" dur="4s" repeatCount="indefinite" />
</stop>