Skip to content

Instantly share code, notes, and snippets.

View hendrikswan's full-sized avatar

hendrik swanepoel hendrikswan

View GitHub Profile
@hendrikswan
hendrikswan / private.xml
Created July 23, 2015 07:40
karabiner config for using OSX shortcuts in Virtualbox windows guest
<?xml version="1.0"?>
<root>
<item>
<name>Virtualbox</name>
<identifier>private.test</identifier>
<only>VIRTUALMACHINE</only>
<autogen>__KeyToKey__ KeyCode::Z, VK_COMMAND, KeyCode::Z, VK_CONTROL</autogen>
<autogen>__KeyToKey__ KeyCode::S, VK_COMMAND, KeyCode::S, VK_CONTROL</autogen>
<autogen>__KeyToKey__ KeyCode::X, VK_COMMAND, KeyCode::X, VK_CONTROL</autogen>
<autogen>__KeyToKey__ KeyCode::C, VK_COMMAND, KeyCode::C, VK_CONTROL</autogen>
@hendrikswan
hendrikswan / example.html
Created November 14, 2011 09:21
static-tabs
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Demo of static tabs</title>
<link type="text/css" href="css/ui-lightness/jquery-ui-1.8.10.custom.css" rel="stylesheet" />
<script type="text/javascript" src="js/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.8.10.custom.min.js"></script>
<script type="text/javascript" src="js/jquery-staticTabs.js"></script>
<script type="text/javascript">
{
"name": "react-stack",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
@hendrikswan
hendrikswan / promise-tied-to-event.js
Created June 14, 2017 18:11
code samples for medium post
function syncMouseEvent(event) {
api.syncEvent({
x: event.clientX,
y: event.clientY
})
.then((result) => {
console.log('successfully synced a mouse event');
})
.catch((reason) => {
console.error('got an error while trying to sync an event')
var promise = Promise.resolve(new Date());
promise.then((date) => console.log(date));
setTimeout(() => promise.then((date) => console.log(date)), 2000);
// OUTPUT
// 2017–06–14T17:55:43.322Z
// 2017–06–14T17:55:43.322Z
const pendingItems = new Rx.Subject();
pendingItems.subscribe((item) => {
api.syncEvent(item)
.then((result) => {
console.log('successfully synced a mouse event');
})
.catch((reason) => {
console.error('got an error while trying to sync an event')
});
const pendingItems = new Rx.Subject();
pendingItems.subscribe((item) => {
api.syncEvent(item)
.then((result) => {
console.log('successfully synced a mouse event');
})
.catch((reason) => {
console.error('got an error while trying to sync an event, going to try again');
pendingItems.next(item);
const pendingItems = new Rx.Subject();
const maxRetries = 3;
const queue = (item) => {
let workingItem = item;
if (!workingItem.sync) {
workingItem = {
sync: { counter: 0 },
item,
pendingItems
.map(item => Rx.Observable.of(item).delay(item.sync.counter > 0 ? delayBetweenRetries : 0))
.mergeAll()
.subscribe((itemWithMetaData) => {
api.syncEvent(itemWithMetaData.item)
.then((result) => {
console.log('successfully synced a mouse event');
})
.catch((reason) => {
console.error('got an error while trying to sync an event, going to try again');
const sync = createSync({
maxRetries: 3,
delayBetweenRetries: 2000,
syncAction: api.syncEvent,
});
// success
sync.syncedItems.subscribe(x => console.log(x.item));
// failure