Skip to content

Instantly share code, notes, and snippets.

@paitonic
paitonic / perf.js
Last active April 5, 2016 12:28
measure function execution
function perf(self, func) {
// everything is argument except for 'self' and 'func'
var args = Array.prototype.slice.call(arguments, 2, arguments.length);
var t1 = performance.now();
func.apply(self, args);
var t2 = performance.now();
var t = t2 - t1;
return t.toFixed(2) + 'ms' + ', ' + (t / 1000).toFixed(2) + 's';
@paitonic
paitonic / cors-test.js
Created October 21, 2016 15:47
Test CORS
// http://www.test-cors.org/
var createCORSRequest = function(method, url) {
var xhr = new XMLHttpRequest();
if ("withCredentials" in xhr) {
// Most browsers.
xhr.open(method, url, true);
} else {
// CORS not supported.
xhr = null;
@paitonic
paitonic / expressjs-api-test-with-jasmine-and-request.md
Last active July 29, 2024 15:38
ExpressJS - API Tests with Jasmine and request

ExpressJS - API Tests with Jasmine and request

What am I trying to solve

I was trying to solve an issue with starting the ExpressJS server before each single test and closing it after each test completes, just to make sure each test is running under the same conditions.

Here is the error I ran into while trying to run the tests

$ ./node_modules/jasmine/bin/jasmine.js
Started
started
@paitonic
paitonic / git-cheat-sheet
Last active December 22, 2016 22:29
git cheat sheet
# create tag on current branch
$ git tag 1.0.0
# list tags
$ git tag
# delete remote branch
$ git push origin --delete <branch_name>
# untrack file
@paitonic
paitonic / flattenObject.js
Created February 7, 2018 19:15
flattenObject
function isObject(value) {
return (value && value.constructor && value.constructor === Object) === true;
}
function isArray(value) {
return value instanceof Array;
}
function isPrimitive(value) {
return !isObject(value) && !isArray(value);
@paitonic
paitonic / gist:e7477430ecb42a1baf9a2729d5453092
Created February 20, 2018 07:08
ace editor annotations
editor.getSession().setAnnotations([{
row: 1,
column: 0,
text: "Error Message",
type: "error"
}]);
@paitonic
paitonic / index.html
Created March 24, 2019 07:13
svg-charts.js
<html>
<head>
<title>SVG Charts</title>
</head>
<body>
<div id="svg-bar"></div>
<div id="svg-area"></div>
<div id="svg-line"></div>
<script src="svg-charts.js"></script>
@paitonic
paitonic / react-jest-enzyme.md
Created June 29, 2019 18:55
Setup Jest and Enzyme for React
# javascript
root = true
[*]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true
@paitonic
paitonic / chunk.js
Created August 24, 2019 04:49
chunk
function chunk(array, size) {
function partition(array, start, result=[]) {
if (array.length === 0) {
return result;
}
return partition(array.slice(start+size, array.length), start+size, [...result, array.slice(0, size)])
}
return partition(array, 0);