Skip to content

Instantly share code, notes, and snippets.

@gjtorikian
gjtorikian / comparisson
Created Feb 12, 2012
API Markdown styles
View comparisson
## 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 Aug 29, 2012
Wraps a chunk of text in Javascript, to support CORS and CLoud9 IDE external plugins
View wrap-in-js.sh
#!/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 Sep 1, 2012
Testing Ag via Node script
View ag_spawn.js
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 Sep 7, 2012
JavaScript Object Extend
View js_obj_extend.js
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) {
View ruby_out.json
{
"range": [
49981,
49995
],
"value": "$(\"head\")[0]",
"type": "Line"
},
{
"range": [
View javascript_ast.json
{ 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 ] },
View code.js
//#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 Sep 20, 2012
ruby blob of jsduck
View blob.rb
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 Oct 15, 2012
Using async module's queue to avoid EMFILE with fs.readFile
View readFile_queue.js
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 Oct 18, 2012
Setting up a sample dock
View dock.js
dock.addDockable({
expanded : -1,
width : 300,
sections : [
{
width : 260,
height: 350,
buttons : [
{
caption: "My Dock Button",