Skip to content

Instantly share code, notes, and snippets.

View pbojinov's full-sized avatar

Petar Bojinov pbojinov

View GitHub Profile
@pbojinov
pbojinov / cors.js
Created July 22, 2013 02:34
Simple CORS (XHR) example. Note IE8< uses XDomainRequest
var xhr = new XMLHttpRequest();
xhr.open('GET', 'http://corstest.pbojinov.c9.io/?feed=rss2');
xhr.onreadystatechange = function () {
if (this.status == 200 && this.readyState == 4) {
console.log('response: ' + this.responseText);
}
};
xhr.send();
@pbojinov
pbojinov / reset.css
Created July 23, 2013 00:04
Eric Meye's Reset CSS 2.0
/** * Eric Meyer's Reset CSS v2.0 (http://meyerweb.com/eric/tools/css/reset/) * http://cssreset.com */html, body, div, span, applet, object, iframe,h1, h2, h3, h4, h5, h6, p, blockquote, pre,a, abbr, acronym, address, big, cite, code,del, dfn, em, img, ins, kbd, q, s, samp,small, strike, strong, sub, sup, tt, var,b, u, i, center,dl, dt, dd, ol, ul, li,fieldset, form, label, legend,table, caption, tbody, tfoot, thead, tr, th, td,article, aside, canvas, details, embed, figure, figcaption, footer, header, hgroup, menu, nav, output, ruby, section, summary,time, mark, audio, video { margin: 0; padding: 0; border: 0; font-size: 100%; font: inherit; vertical-align: baseline;}/* HTML5 display-role reset for older browsers */article, aside, details, figcaption, figure, footer, header, hgroup, menu, nav, section { display: block;}body { line-height: 1;}ol, ul { list-style: none;}blockquote, q { quotes: none;}blockquote:before, blockquote:after,q:before, q:after { content: ''; content: none;}table { border-collapse: co
@pbojinov
pbojinov / .bash_profile
Last active December 20, 2015 09:39
my osx .bash_profile
#aliases
alias ..="cd .."
alias home="cd /Users/petar"
alias profile="cd /Users/petar; subl .bash_profile"
#internal ip
alias ip="ifconfig"
alias ip0="ipconfig getifaddr en0" #usually wifi
#external ip
@pbojinov
pbojinov / hyphen.dash.js
Last active December 20, 2015 13:09
hypen, dashes ascii codes
var hyphen = "-".charCodeAt(0); //45
var dash = "–".charCodeAt(0); //8211
console.log(hyphen, dash);
// Example:
JavaScript.load("/javascripts/something.js");
// With callback (that’s the good thing):
JavaScript.load("http://www.someawesomedomain.com/api.js", function() {
API.use(); // or whatever api.js provides ...
});
var myRevealingModule = function () {
var privateCounter = 0;
function privateFunction() {
privateCounter++;
}
function publicFunction() {
publicIncrement();
@pbojinov
pbojinov / regex.js
Created August 14, 2013 20:14
basic javascript regex: global, case insensitive
/**
* Replace single instance, case sensitive
*/
var sentence = "Hello my name is petar petar"
var findTilda = /petar/;
sentence = sentence.replace(findTilda, '&');
alert(sentence); //Hello my name is & petar
/**
* Replace all instances, case sensitive
@pbojinov
pbojinov / array.merge.js
Last active December 21, 2015 02:29
merge two arrays using concat() or push.
/**
* Concat
*/
var mergeTo = [4,5,6],
mergeFrom = [7,8,9];
mergeTo = Array.prototype.concat(mergeTo, mergeFrom);
mergeTo; // is: [4, 5, 6, 7, 8, 9]
/**
@pbojinov
pbojinov / git-post-commit-picture.sh
Last active April 8, 2018 02:33 — forked from allolex/gist:4564357
imagesnap git post-commit photo rewrite
#!/bin/bash
function make_image_dir () {
TARGET_DIR=$1
if [ ! -d "${TARGET_DIR}" ]; then
mkdir "${TARGET_DIR}"
fi
}
function ignore_image_dir () {
TARGET_DIR=$1
GIT_IGNORE=$2
@pbojinov
pbojinov / node.express.cors.js
Created August 18, 2013 19:37
CORS middleware for Node.js Express
var allowCrossDomain = function(req, res, next) {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Headers', 'X-Requested-With, Content-Type, Authorization, Accept');
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS,TRACE');
res.header('Access-Control-Allow-Credentials', true);
/**
* CORS OPTIONS request, simply return 200
* ---
* Browser will try to see request is possible before actually doing it