Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / 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 / arch-install-script
Created February 6, 2016 09:28
Arch installation script
#################################################################
############################## DRAFT ############################
#################################################################
# arch linux - stage_install
# update system clock
$ timedatectl set-ntp true
# PARTITIONING (EFI)
-s -- never prompt the user
@paitonic
paitonic / websocket-example.py
Created March 27, 2015 20:14
Websockets using Tornado
import tornado.websocket
import json
class WebSocketHandler(tornado.websocket.WebSocketHandler):
clients = []
def open(self):
WebSocketHandler.clients.append(self)
print "WebSocket opened"
def on_message(self, message):
@paitonic
paitonic / radio-t-timestamps.py
Last active August 29, 2015 14:16
Script parses Radio T chat log and outputs each subject starting time
# -*- coding: utf-8 -*-
import lxml.html
import math
from datetime import datetime
radiot_nick = 'jc-radio-t'
podcast = 'http://chat.radio-t.com/logs/radio-t-{number}.html'.format(number=422)
# parsing