Skip to content

Instantly share code, notes, and snippets.

@kosamari
kosamari / check_file_extention.js
Last active August 29, 2015 14:04
script for file extention verification
/*
script for file extention verification
*/
var path = 'path/to/file';
var imageExt = ['jpeg','jpg','png','gif','tiff']; //specify allowed file extentions
var fileExt = path.split('.');
var checkExist = imageExt.indexOf(fileExt[fileExt.length-1]); // -1 if the file extention does not exist in imageExt
if (checkExist === -1){
console.log('File type not supported, please use '+ imageExt);
@kosamari
kosamari / phantomjs-node_console_output.js
Last active August 29, 2015 14:04
code to out put console message in phantomjs page into node.js console.
/*
code to out put console message in phantomjs page into node.js console.
*/
page.set('onConsoleMessage', function (message) {
console.log('Phantom Console: ' + message);
});
@kosamari
kosamari / phantom-node_callback.js
Last active August 29, 2015 14:04
allows to call function from inside of page.evaluate in phantomjs-node
/*
allows to call function from inside of page.evaluate in phantomjs-node
*/
page.set('onCallback', function (arg) {
//callback actions
});
//To use callback, use following command in your page.evaluate
window.callPhantom(arg);
@kosamari
kosamari / index.html
Last active August 29, 2015 14:07
D3 arc clock
<!DOCTYPE html>
<html>
<head>
<script src="http://d3js.org/d3.v3.min.js"></script>
<style type="text/css">
path.overlay {
fill: orange;
}
path.base{
fill: #f3f3f3;
@kosamari
kosamari / index.html
Created October 13, 2014 23:47
D3 Line clock
<!DOCTYPE html>
<html>
<head>
<script src="http://d3js.org/d3.v3.min.js"></script>
<style type="text/css">
rect.overlay {
fill: #2279bd;
}
rect.base{
fill: #f3f3f3;
@kosamari
kosamari / _.R.js
Last active December 7, 2018 11:12
Underscore mixin to enable core R functions
_.mixin({
sum : function(data){
return _.reduce(data, function(memo, num){ return memo + num; }, 0);
},
mean : function(data){
return this.sum(data)/data.length
},
median : function(data){
return this.percentile(data,50);
},
@kosamari
kosamari / city.json
Created October 28, 2014 19:58
D3 Map with Data
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
/*
What is the optimal way to print values of 2 arrays alternately? (every 5 sec)
* Items in both arrays could change at any given moment
* update to each array needs to be applied imminently
* if array is empty, it will not print any value (and move to the other array)
So if you start with following arrays
var arr0 = ['1','2','3']
var arr1 = ['a','b','c']
It would start printing
@kosamari
kosamari / index.html
Last active March 27, 2016 03:23
D3.js Hanabi
<!DOCTYPE html>
<html>
<head>
<script src="http://d3js.org/d3.v3.min.js"></script>
<meta charset="utf-8">
<style>
body {
background: #222;
color:#fff;
font-family: "Helvetica Neue", Helvetica, sans-serif;
@kosamari
kosamari / index.html
Created November 20, 2014 23:11
Brooklyn JS Anniversary
<!DOCTYPE html>
<html>
<head>
<script src="http://d3js.org/d3.v3.min.js"></script>
<meta charset="utf-8">
<style>
body {
background: #222;
color:#fff;
font-family: "Helvetica Neue", Helvetica, sans-serif;