Skip to content

Instantly share code, notes, and snippets.

@djcsdy
djcsdy / decimalize.js
Created December 3, 2012 03:15
Convert hex values on a web page to decimal
function fix (node) { while (node) { if (node.nodeType == 3) { node.nodeValue = node.nodeValue.replace(/\$((?:[0-9a-fA-F]{2}){1,2})/g, function (match, value) { return parseInt(value, 16); }); } else { fix(node.firstChild); } node = node.nextSibling; } } fix(document)
@djcsdy
djcsdy / folders.cpp
Created November 17, 2012 10:10
Useful Windows Known Folders
// If targeting Windows 2000 and later.
LPTSTR pszPath = (LPTSTR) malloc(MAX_PATH);
// If targeting Windows Vista and later, we don't have to allocate our own string.
PWSTR* ppszPath;
// Local Application Data (e.g. C:\Users\djc\AppData\Local
// If targeting Windows 2000 and later
SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, pszPath);
// If targeting Windows Vista and later
@djcsdy
djcsdy / gist:3812588
Created October 1, 2012 15:44
Bounding box of a moving polygon
https://twitter.com/danielcassidy/status/252792108522545152/photo/1/large
P_A = P at A
P_B = P at B
1. For each edge E in P_A:
2. Compute a quad containing the edge E and, opposite, its corresponding edge in P_B.
3. Compute the union of all quads.
Leaving the exact algorithm for 3 undefined since I have a geometry library that can do
@djcsdy
djcsdy / Application.java
Created September 17, 2012 19:38
This qualifies as IoC. You don’t need no stinkin’ framework.
// This class acts as both the injector and the list of components.
//
// It contains a bit of boilerplate so although it’s easy to write it’s not great fun.
//
// It does have the advantage of being very straightforward to understand, and
// everything is static and checked at compile-time.
class Injector {
public static void main(String[] args) {
Repository repository = new RepositoryImpl();
PostBox postBox = new PostBoxImpl();
class Idiocy {
function doSomethingHatstand(o:Object) {
// do something preposterous
}
function doSomethingLampshade(o:Object) {
// do something asinine
}
public function doSomething(o:Object) {
---------------
Dear Foo Communications Support,
I have a minor problem with your otherwise fine service. I worked around it
by doing [X].
It would be nice if you could do [Y] because then the problem will be solved
for all your customers.
@djcsdy
djcsdy / haxedoc.xml
Created September 1, 2012 20:28
Cut-down haxedoc.xml illustrating a bug in haxedoc.
<haxe>
<typedef path="kong.Services" params="" file="./kong/Services.hx"><a>
<showRegistrationBox set="method">
<f a=""><e path="Void"/></f>
<haxe_doc>Displays the user registration UI.
*
* This is useful if the player is a guest but you want to authenticate them for a multiplayer game,
* or to upsell an item.</haxe_doc>
</showRegistrationBox>
<isGuest set="method">
@djcsdy
djcsdy / broken-page.png
Created August 30, 2012 17:22
Bug report images
broken-page.png
@djcsdy
djcsdy / gist:3514122
Created August 29, 2012 15:13
Games made for Ludum Dare 24 at CB2
package;
import flash.MovieClip;
class Bubble {
// Set this to true when the bubble is 'created'.
// Set it to false when the bubble is popped.
public var active:Bool;
var movieClip:MovieClip;