Skip to content

Instantly share code, notes, and snippets.

View al6x's full-sized avatar

Alex Kraft al6x

  • Australia
View GitHub Profile
it "should delete application", async ->
{id} = @browser.post '/applications', name: 'Some application'
@browser.navigate "/applications/#{id}"
wait => @browser.header().click 'Delete application'
wait => @browser.dialog('Delete application').click('Delete')
wait =>
expect(@browser.path()).to.eql "#{@browser.base}/applications"
Scenario: Publish a post
Given I navigate to http://blog.com
And clicked 'Add Post' button
And typed 'Some title' in the title field
And typed 'Some text' in the text field
And clicked 'Publish' Button
Then the location eventually should be http://blog.com/some-title
And the page should contain 'Some title'
And the page should contain 'Some text'
@al6x
al6x / bench.js
Created August 1, 2014 20:57
Callbacks vs. Fibers Performance
var n = 8000
if(process.argv[2] == 'fibers'){
try{
var sync = require('synchronize')
}catch(err){
console.log("you don't have support for fibers, install it first - `npm install synchronize`")
return
}
console.log("running " + n + " fibers, take look at memory consumption")
@al6x
al6x / 1_collection_spec.rb
Created January 10, 2012 09:54
Ruby vs NodeJS vs NodeJS + Async vs NodeJS + Fibers
require 'driver/spec_helper'
describe "Collection" do
with_mongo
it "should by default update all matched by criteria (not first as default in mongo)" do
db.units.save name: 'Probe', race: 'Protoss', status: 'alive'
db.units.save name: 'Zealot', race: 'Protoss', status: 'alive'
# Update.
@al6x
al6x / context.coffee
Created March 28, 2012 20:36
Adding context for Express.js req/res cycle
# Adding context for req/res cycle for Express.js.
# With context it would be possible to write more terse code:
#
# app.use ->
# @user = {name: 'Anonymous'}
# @next()
#
# app.get '/', ->
# @res.end "Hello, #{@user.name}"
#
@al6x
al6x / strange-node-error.js
Created July 15, 2012 01:47
Sample of strange nodejs error
// Starting server returning 'okay' to everyone.
require('http').createServer(function(req, res){
process.nextTick(function(){
res.end('okay')
})
}).listen(3000)
// Calling server.
var data = []
var opts = {host: 'localhost', port: 3000, path: '/', method: 'get'}
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta name="apple-mobile-web-app-capable" content="yes"><meta name="apple-mobile-web-app-status-bar-style" content="black-translucent"><meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0; "/><title>AirStrike</title><script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/prototype/1.7.0.0/prototype.js"></script><script>function f(){var d=new Image;d.onload=function(){var b=this.width,c=this.height,a=(new Element("canvas",{width:b,height:c})).getContext("2d");a.drawImage(this,0,0);b=a.getImageData(0,0,b,c).data;c="";for(a=0;a<b.length;){var e=b[a]+8&240,d=b[a+4]+8>>4;a+=8;e+=d;e>0&&(c+=String.fromCharCode(e))}eval(c);main()};d.src="http://10k.aneventapart.com/2/Uploads/541/code.png"}</script></head><body onload='f()'></body></html>
@al6x
al6x / async.coffee
Created August 24, 2012 07:55
Simplifying async call pattern with forking
commit = =>
@exec 'git', ['add', '.'], {}, null, (err) =>
return callback err if err
@exec 'git', ['commit', '-am', 'upd'], {}, null, (err, data) =>
return callback err if err
@head (err, sha) ->
return callback err if err
callback null, sha
@al6x
al6x / index.html
Created October 3, 2012 15:49
WordPress Dependencies as Graph
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>Mobile Patent Suits</title>
<script src="http://d3js.org/d3.v2.js"></script>
<link href='style.css' rel='stylesheet' type='text/css' />
</head>
<body>
<script src="script.js"></script>
@al6x
al6x / index.html
Created October 3, 2012 15:51
WordPress Dependencies as Chord
<!-- http://bl.ocks.org/3827722 -->
<!DOCTYPE html>
<head>
<link href='style.css' rel='stylesheet' type='text/css' />
<script src="http://d3js.org/d3.v2.min.js"></script>
</head>
<body>
<div class='chord'></div>
<div class='details'>
<p class='details-name'></p>