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
let dim = [...svg.children].filter(el => el.getBBox).reduce((acc, el) => {
let { x, y, width, height } = el.getBBox();
if (!acc.min.x || x < acc.min.x) acc.min.x = x;
if (!acc.max.x || x + width > acc.max.x) acc.max.x = x + width;
if (!acc.min.y || y < acc.min.y) acc.min.y = y;
if (!acc.max.y || y + height > acc.max.y) acc.max.y = y + height;
return acc;
}, { min: {}, max: {} }),
viewBox = `${dim.min.x} ${dim.min.y} ${dim.max.x - dim.min.x} ${dim.max.y - dim.min.y}`;
svg.setAttribute("viewBox", viewBox);
Qure
.wait(1000)
.then(function() {
// executed after 1 second
console.log(1);
})
.wait(1000)
.then(function() {
// executed after 1 second after previous log
@hbi99
hbi99 / test.html
Last active March 9, 2017 07:19
Sandboxed Javascript
<html>
<head>
<title>3rd party script executed in sandbox mode</title>
<script type="text/javascript">
var code = 'console.log(this);'+
'console.log(window);'+
'console.log(document);'+
'console.log(console);'+
'setTimeout(function() {console.log(1);}, 10);'+
@hbi99
hbi99 / web.config
Created March 14, 2016 11:06
Multisite web.config for Azure
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="WordPress Rule 1 Identical" stopProcessing="true">
<match url="^index\.php$" ignoreCase="false" />
<action type="None" />
</rule>
// start the timer
var start = Date.now();
// get the snapshot with a callback function
Defiant.getSnapshot(data, function(snapshot) {
console.log('Created snapshot in '+ (Date.now() - start) +' ms');
// searching on snapshot created with web worker
var found = JSON.search(snapshot, '//item');
console.log(found);
<!-- Defiant template -->
<script type="defiant/xsl-template">
<xsl:template name="tree">
<h1>Tree</h1>
<xsl:call-template name="tree-walker"/>
</xsl:template>
<xsl:template name="tree-walker">
<!-- Defiant template -->
<script type="defiant/xsl-template">
<xsl:template name="books_template">
<h1>Books</h1>
<xsl:for-each select="//book">
<xsl:sort order="ascending" data-type="number" select="price"/>
<h2><xsl:value-of select="title"/></h2>
Author: <strong><xsl:value-of select="author"/></strong><br/>
Price: <xsl:value-of select="price"/>
<!-- Defiant template -->
<script type="defiant/xsl-template">
<xsl:template name="books_template">
<xsl:for-each select="//movie">
<xsl:value-of select="title"/><br/>
</xsl:for-each>
</xsl:template>
</script>
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 {
// ...large JSON structure...
};
// Regular search
found = JSON.search(data, '//item');
var snapshot = Defiant.getSnapshot(data);
// Snapshot search - this is more than 100 times faster than 'regular search'