Skip to content

Instantly share code, notes, and snippets.

View gkatsev's full-sized avatar

Gary Katsevman gkatsev

View GitHub Profile
@gkatsev
gkatsev / percent-eval.user.js
Created June 30, 2012 21:14
Evaluate division for percent in goodreads' update box.
// ==UserScript==
// @name Percent-eval
// @namespace http://gkatsev.com/percenteval
// @description Evaluate division for percent in goodreads' update box
// @include *://*goodreads.*/*
// @version 1
// ==/UserScript==
window.addEventListener('DOMContentLoaded'
, function(){
var inputs = document.querySelectorAll('#user_status_percent')
//original
return (
{ vector: vector
, norm: norm
, zipWith: zipWith
, add: add
, subtract: subtract
, dot: dot })
//new
@gkatsev
gkatsev / extend.js
Created July 23, 2012 04:50
A simple and naive extend implementation
function extend(obj, extend){
var p;
for (p in extend) {
obj[p] = extend[p];
}
return obj;
}
var obj = {
a : 1
@gkatsev
gkatsev / http
Created July 26, 2012 18:32
run a simple http server in the current directory
#!/bin/bash
python -m SimpleHTTPServer $1
# run like so: http 8080
JS: The Hip Parts.
Chapters = [
Comma-First is Comma Right
, !function Expressions!
, <!--Comments with Style-->
, Blow it Out Your Semi-Colon
]
(function (n) {
var f = '',
s = n < 0 ? '-' : f,
p = [],
l = 0,
m = 4294967296,
o = m * 1024,
a = Math.floor;
o *= o;
n = a(s ? -n : n);
@gkatsev
gkatsev / httpcors
Created September 27, 2012 20:28
simple python http server with CORS enabled
#!/usr/bin/env python
import SimpleHTTPServer
class CORSHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
def send_head(self):
"""Common code for GET and HEAD commands.
This sends the response code and MIME headers.
Return value is either a file object (which has to be copied
String.prototype.splitSome = function(del, n){
var a = this.split(del)
, b = a.slice(n).join(del)
a.length = n
a[a.length] = b
return a
};
"one,two,three,four,five".splitSome(',', 3)
@gkatsev
gkatsev / strictMode.md
Last active December 12, 2015 00:39
An overview and features of strict mode

Strict Mode

Overview

Strict mode is an opt-in mode for JavaScript that fixes, disables, and changes some of the most problematic features in the language.

Strict mode is invoked with "use strict"; statement at the top of the current scope. So, it works both in functions and in files. It is better to only ever specifiy strict mode inside of functions because this simplifies concatenating

@gkatsev
gkatsev / variadic.js
Last active December 13, 2015 23:08
Create a variadic function that uses function's arguments as variables.
(function(x, y, z) {
"use strict";
x = y = 0;
z = arguments.length;
for (; y < z; y++) {
x += arguments[y];
}