Skip to content

Instantly share code, notes, and snippets.

@kosamari
kosamari / check_file_extention.js
Last active Aug 29, 2015
script for file extention verification
View check_file_extention.js
/*
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 Aug 29, 2015
code to out put console message in phantomjs page into node.js console.
View phantomjs-node_console_output.js
/*
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 Aug 29, 2015
allows to call function from inside of page.evaluate in phantomjs-node
View phantom-node_callback.js
/*
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 Aug 29, 2015
D3 arc clock
View index.html
<!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;
View index.html
<!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 Dec 7, 2018
Underscore mixin to enable core R functions
View _.R.js
_.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 Oct 28, 2014
D3 Map with Data
View city.json
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View TowArrayPrint.js
/*
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 Mar 27, 2016
D3.js Hanabi
View index.html
<!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 Nov 20, 2014
Brooklyn JS Anniversary
View index.html
<!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;
You can’t perform that action at this time.