Skip to content

Instantly share code, notes, and snippets.

View hbi99's full-sized avatar
🚲
Check out http://defiantjs.com/jupyter/

Hakan Bilgin hbi99

🚲
Check out http://defiantjs.com/jupyter/
View GitHub Profile
var EventEmitter = require('events').EventEmitter,
path = require('path'),
fs = require('fs');
module.exports = {
createMonitor: createMonitor
};
function equalStats(a, b) {
@hbi99
hbi99 / index.htm
Last active December 11, 2015 02:18
The function modifyVars is rewritten for optimum performance. A couple of files demonstrating the improved performance.
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="UTF-8" />
<link rel="stylesheet/less" type="text/css" href="test.less">
<script type="text/javascript" src="less.js"></script>
<script type="text/javascript">
window.onload = function() {
@hbi99
hbi99 / gist:8038191
Last active December 31, 2015 20:09
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Defiant.js</title>
<script type="text/javascript" src="/res/js/defiant.js"></script>
</head>
<body>
<!-- output element -->
var str = '<data><author>Isaac Asimov</author><genre>Science Fiction</genre></data>',
doc = Defiant.xmlFromString(str),
node = Defiant.node.selectSingleNode(doc, '//author');
console.log( node.nodeValue );
// 'Isaac Asimov'
var str = '<data><movie>Star Wars</movie><movie>Indiana Jones</movie></data>',
doc = Defiant.xmlFromString(str),
node = Defiant.node.selectSingleNode(doc, '//movie');
console.log( Defiant.node.prettyPrint( node ) );
// '<movie>Star Wars</movie>'
console.log( Defiant.node.prettyPrint( doc ) );
/*
var str = '<data><brand>Sony</brand><brand>Apple</brand>'+
'<brand>Panasonic</brand></data>',
doc = Defiant.xmlFromString(str),
node = Defiant.node.selectSingleNode(doc, '//brand');
console.log( Defiant.node.prettyPrint( node ) );
// '<brand>Sony</brand>'
var str = '<data><company name="Apple"/>'+
'<user email="steve@apple.com"/>'+
'<movie name="The Godfather"/></data>',
doc = Defiant.xmlFromString(str),
node = Defiant.node.selectNodes(doc, '//*[@name]');
for (var i=0; i<node.length; i++) {
console.log( Defiant.node.prettyPrint( node[i] ) );
}
var str = '<data><user id="1" name="Hakan Bilgin">'+
'<mail>hbi@bredband.net</mail></user></data>',
doc = Defiant.xmlFromString(str),
obj = Defiant.node.toJSON(doc.documentElement);
console.log( JSON.stringify(obj, null, '\t') );
/*
{
"user": {
var obj = {
"car": [
{"@id": 10, "@color": "silver", "name": "Volvo"},
{"@id": 11, "@color": "red", "name": "Saab"},
{"@id": 12, "@color": "red", "name": "Peugeot"},
{"@id": 13, "@color": "yellow", "name": "Porsche"}
],
"bike": [
{"@id": 20, "@color": "black", "name": "Cannondale"},
var data = {
"product": [
{"active": 1, "name": "MacBook Air", "price_us": 999},
{"active": 0, "name": "Mac mini", "price_us": 599},
{"active": 1, "name": "MacBook Pro", "price_us": 1299}
]
},
SEK_USD = 6.57,
res = JSON.search( data, '//product[active=1]' );