Skip to content

Instantly share code, notes, and snippets.

@Dykam
Dykam / README
Last active August 29, 2015 14:06
Event and Threading model proposal
A small non-complete example design and implementation of Observables/Tasks integrated into events.
It is inspired by a mix of classic Observables and .NET's Tasks/SynchronizationContext.
@Dykam
Dykam / interfaces.java
Last active August 29, 2015 14:06
Message Object Format
interface TextMessage {}
interface RawTextMessage extends TextMessage { String getValue(); }
interface Style extends TextMessage { TextStyle getStyle(); TextMessage getMessage(); }
interface Action extends TextMessage { TextAction getAction(); TextEvent getEvent(); TextMessage getMessage(); }
/* Combines multiple texts */
interface Combined extends TextMessage { List<TextMessage> getMessages(); }
@Dykam
Dykam / Java 6 or 7.java
Last active August 29, 2015 14:06
Event & Threading model proposal (Usege example)
// When using Java 6 or 7
Observable<Vector> positions =
server.events.playerMove().map(new Fn<PlayerMoveEvent, Vector>() {
public Vector call(PlayerMoveEvent event) {
return event.getPlayer().getPosition();
}
})
.async() // continue on threadpool
.map(new Fn<Vector, Vector>() {
public Vector call(Vector vector) {
public static final <T> T bestMatch(String search, Collection<T> options, double threshold) {
T bestObj = null;
double bestScore = 0.0D;
for (T obj : options) {
double score = LiquidMetal.score(obj.toString(), search);
if (score > bestScore) {
bestObj = obj;
bestScore = score;
} else if (score == bestScore) {
bestObj = null;
@Dykam
Dykam / pom.xml
Created December 9, 2013 23:58
Template for debug maven module. Put it in a subfolder of the main maven module, supply the params, and execute mvn install on it.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId><!--groupId--></groupId>
<artifactId><!--artifactId-->Debug</artifactId>
<version><!--version--></version>
<packaging>pom</packaging>
<div class="InfoWindow">
<div><span>description</span></div>
<fieldset class="Directions">
<legend>Route</legend>
<div class="Container">
<label>Van</label><input type="text" class="Dest" />
<label>naar</label><span class="Wrapped">address</span><input type="submit" value="Route zoeken" class="Search" />
</div>
</fieldset>
</div>
@Dykam
Dykam / README.md
Created February 28, 2012 19:12 — forked from Zegnat/README.md
Fixing your skip links. [JS]

Fixing your skip links.

Read Damon Muma on this. He proposes the following jQuery solution (inspired by Thompson, fixed by me):

// Apply focus properly when accessing internal links with keyboard in WebKit browsers.
$("a[href^='#']").not("a[href='#']").click(function() {
   $("#"+$(this).attr("href").slice(1)+"").focus();
});
@Dykam
Dykam / Source.js
Created January 3, 2012 00:03
Script to remove all apps from https://www.facebook.com/settings?tab=applications Compressed url form below, ready for pasting.
// ==ClosureCompiler==
// @output_file_name default.js
// @compilation_level ADVANCED_OPTIMIZATIONS
// ==/ClosureCompiler==
(function () {
var el = document.createElement('div'),
b = document.getElementsByTagName('body')[0];
otherlib = false, msg = '';
el.style.position = 'fixed';
@Dykam
Dykam / Fibonacci
Created September 25, 2011 12:40
Messing around with CoffeeScript
fib = (n) ->
next = 1
current: 0
movenext: ->
if n-- is 0
@movenext = -> false
return false
[@current, next] = [next, @current + next]
true
@Dykam
Dykam / gist:1193595
Created September 4, 2011 22:06
[SpoutCraft] Proposal for centralized input

#The problem Currently plugins are supposed to listen to input using the InputManager. There are three issues to this.

  • Binding conflicts. Plugins might use the same key. This is mostly an issue with the tab and ctrl keys.
  • Rebinding confusion. Each plugin, if it is configurable, defines its own way of redefining keybindings. This is confusing.
  • By default all presses are mapped, including when for example chat is open.

#The solution Let plugins define keybindings by means of a simple string as key. Conflicts between plugins are solved because the plugin is part of the key. Client side the user can set the keybinding to an actual key, which is defaulted to a configurable default. The client side part is done by SpoutCraft, possibly by modifying the keybindings screen to add plugin keybindings. Here's the code the plugin has to use: