Skip to content

Instantly share code, notes, and snippets.

@laverdet
laverdet / rimraf.js
Created August 8, 2011 02:12
rimraf with futures
var path = require('path'),
fs = require('fs'),
Future = require('fibers/future');
// Create future-returning fs functions
var fs2 = {};
for (var ii in fs) {
fs2[ii] = Future.wrap(fs[ii]);
}
@laverdet
laverdet / newAndRun.diff
Created March 31, 2012 02:42
new Fiber + run() in same C++ function
diff --git a/src/fibers.cc b/src/fibers.cc
index 49a20f7..c446f9d 100644
--- a/src/fibers.cc
+++ b/src/fibers.cc
@@ -143,6 +143,42 @@ class Fiber {
}
/**
+ * Build a new fiber and immediately run it.
+ */
diff --git a/binding.gyp b/binding.gyp
index 379026f..0413e95 100644
--- a/binding.gyp
+++ b/binding.gyp
@@ -6,6 +6,7 @@
# Replace gyp platform with node platform, blech
['platform == "mac"', {'variables': {'platform': 'darwin'}}],
['platform == "win"', {'variables': {'platform': 'win32'}}],
+ ['platform == "solaris"', {'variables': {'platform': 'sunos'}}],
],
#include <iostream>
#include <v8.h>
using namespace std;
using namespace v8;
// simple print utility; mostly lifted from shell.cc
Handle<Value> Print(const Arguments& args) {
bool first = true;
for (int i = 0; i < args.Length(); i++) {
diff --git a/src/coroutine.cc b/src/coroutine.cc
index f2a0d3d..3c9a8ad 100644
--- a/src/coroutine.cc
+++ b/src/coroutine.cc
@@ -20,8 +20,6 @@
using namespace std;
const size_t v8_tls_keys = 3;
-static pthread_key_t floor_thread_key = 0;
-static pthread_key_t ceil_thread_key = 0;
@laverdet
laverdet / patch.diff
Created December 12, 2014 03:27
node-fibers issue #158
diff --git a/src/coroutine.cc b/src/coroutine.cc
index f2a0d3d..64bf201 100644
--- a/src/coroutine.cc
+++ b/src/coroutine.cc
@@ -20,9 +20,10 @@
using namespace std;
const size_t v8_tls_keys = 3;
-static pthread_key_t floor_thread_key = 0;
-static pthread_key_t ceil_thread_key = 0;
@laverdet
laverdet / repl
Created April 30, 2015 06:18
fibers repl
#!/usr/bin/env node
"use strict";
var fs = require('fs');
var Future = require('fibers/future');
// Start the repl
var vm = require('vm');
var domain = require('domain');
var repl = require('repl').start('node> ', null, fiberEval, true, true);
function fiberEval(code, context, file, cb) {
@laverdet
laverdet / README.md
Last active September 7, 2021 05:02
Screeps git sync script

To use first you need to create two branches, master and sim using the in-game editor. Then just run node sync.js from your local machine. When you're on your local master branch it will push to master in game, any other branch (including detached states) will push to sim. Note that it will push unstaged changes, so be careful when switching to branches with modified code.

There is support included for compressing your JS files on the server side via UglifyJS. Some users reported some speedups by compressing their code, however I did not notice any significant gains. Furthermore, UglifyJS does not yet support ES6 features, so it's disabled by default.

@laverdet
laverdet / body.js
Created July 20, 2015 05:42
Screeps Body class
// Descriptor of a creep body
function Body(body) {
this.body = body;
this._isCreep = typeof body[0] === 'object';
this._cost = undefined;
this._weight = undefined;
}
_.assign(Body.prototype, {
@laverdet
laverdet / sorted.js
Last active August 29, 2015 14:25
How to merge sorted arrays
function mergeSorted(a, b) {
var array = new Array(a.length + b.length);
var ii = a.length + b.length - 1;
var jj = a.length - 1, kk = b.length - 1;
while (jj >= 0 || kk >= 0) {
array[ii--] = (jj < 0 || a[jj] < b[kk]) ? b[kk--] : a[jj--];
}
return array;
}