Skip to content

Instantly share code, notes, and snippets.

@gjtorikian
gjtorikian / comparisson
Created February 12, 2012 17:27
API Markdown styles
## readFileSync(filename, [encoding])
* `filename` String, Required. The name of the file to read
* `encoding` String, Optional. The encoding to use
* Returns: String or Buffer. The contents of the filename. If `encoding` is specified, then this function returns a string. Otherwise it returns a `buffer`.
* * *
## fs.readFileSync(filename, [encoding='utf8']) -> String | Buffer
- filename (String): The name of the file to read
- encoding (String): The encoding to use
@gjtorikian
gjtorikian / wrap-in-js.sh
Created August 29, 2012 22:43
Wraps a chunk of text in Javascript, to support CORS and CLoud9 IDE external plugins
#!/bin/bash -e
# original here: https://github.com/lennartcl/cloud9-hello-plugin/blob/master/wrap-in-js.sh
if [ $# == 0 ]; then
echo No files specified
exit 1
fi
for F in $*; do
echo -n '// Wrapped in JavaScript, to avoid cross-origin restrictions, created using wrap-in-js.sh
@gjtorikian
gjtorikian / ag_spawn.js
Created September 1, 2012 03:24
Testing Ag via Node script
var spawn = require('child_process').spawn;
var cmd = spawn(
"/Users/gjtorikian/Developer/cloud9/plugins-server/cloud9.ide.search/darwin_x64/ag",
["-l", "--search-binary", "--nobreak", "--ackmate", "."]);
cmd.stdout.setEncoding('utf8');
cmd.stdout.on('data', function (data) {
console.log('stdout: ' + data);
});
@gjtorikian
gjtorikian / js_obj_extend.js
Created September 7, 2012 23:45
JavaScript Object Extend
function extend(o, plus) {
var r = {},
i;
for (i in o) {
if (o.hasOwnProperty(i)) {
r[i] = o[i];
}
}
if (plus) {
for (i in plus) {
@gjtorikian
gjtorikian / ruby_out.json
Created September 18, 2012 18:39
ruby ast output
{
"range": [
49981,
49995
],
"value": "$(\"head\")[0]",
"type": "Line"
},
{
"range": [
@gjtorikian
gjtorikian / javascript_ast.json
Created September 18, 2012 18:40
javascript ast output
{ type: 'Line', value: '$("head")[0]', range: [ 49981, 49995 ] },
{ type: 'Line',
value: 'elScript.defer = true;',
range: [ 50061, 50085 ] },
{ type: 'Block',
value: '*\n * @private\n ',
range: [ 50757, 50784 ] },
{ type: 'Line',
value: '#ifdef __PARSER_AML',
range: [ 52591, 52612 ] },
@gjtorikian
gjtorikian / code.js
Created September 18, 2012 18:50
apf code
//#ifdef __DEBUG
if (apf.started)
apf.console.info("including js file: " + sourceFile);
//#endif
var sSrc = doBase ? apf.getAbsolutePath(apf.basePath || "", sourceFile) : sourceFile;
var head = document.getElementsByTagName("head")[0],//$("head")[0]
elScript = document.createElement("script");
//elScript.defer = true;
if (type)
@gjtorikian
gjtorikian / blob.rb
Created September 20, 2012 20:01
ruby blob of jsduck
if exp && ext_define?(exp)
make_class(to_value(exp["arguments"][0]), exp)
# foo = Ext.extend("Parent", {})
elsif exp && assignment?(exp) && ext_extend?(exp["right"])
make_class(to_s(exp["left"]), exp["right"])
# Foo = ...
elsif exp && assignment?(exp) && class_name?(to_s(exp["left"]))
@gjtorikian
gjtorikian / readFile_queue.js
Created October 15, 2012 10:21
Using async module's queue to avoid EMFILE with fs.readFile
var fs = require("fs"),
async = require("async");
var q = async.queue(function (task, callback) {
if (task.type == "file")
fs.readFile(task.path, "utf8", callback);
}, 250);
dirFiles.forEach(function(path) {
q.push({type: "file", path: path}, function (err, fileString) {
@gjtorikian
gjtorikian / dock.js
Created October 18, 2012 23:22
Setting up a sample dock
dock.addDockable({
expanded : -1,
width : 300,
sections : [
{
width : 260,
height: 350,
buttons : [
{
caption: "My Dock Button",