Skip to content

Instantly share code, notes, and snippets.

View pbojinov's full-sized avatar

Petar Bojinov pbojinov

View GitHub Profile
(function() {
var CSSCriticalPath = function(w, d) {
var css = {};
var pushCSS = function(r) {
// The last selector wins, so over-write
// merging existing css will happen here...
css[r.selectorText] = r.cssText;
};
var parseTree = function() {
<!DOCTYPE html>
<html>
<head>
<title>Box Shadow</title>
<style>
.box {
height: 150px;
width: 300px;
margin: 20px;
@pbojinov
pbojinov / uuid.js
Last active December 22, 2015 06:19
Generate UUID in javascript, rfc4122 version 4 compliant solution
//http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/2117523#2117523
function uuid() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
return v.toString(16);
});
}
var id = uuid();
@pbojinov
pbojinov / clean.json.response.js
Last active January 20, 2019 18:14
Removing improperly formatted JSON library in progress.
/**
* 1. utf-8 BOM bytes get translated to \ufeff. Unicode character "Zero width no-break space", can't see them...
*
* Example: Node crashes when trying to parse JSON with BOM as first character
*
* {"Location":{"City":"AMSTERDAM","Country":"NETHERLANDS","CountryCode":"NL","I
* ^
* SyntaxError: Unexpected token
* at Object.parse (native)
*/

Getting Started with NPM (as a developer)

If you haven't already set your NPM author info, now you should:

npm set init.author.name "Your Name"
npm set init.author.email "you@example.com"
npm set init.author.url "http://yourblog.com"

npm adduser

@pbojinov
pbojinov / prevent-page-zoom.html
Created September 12, 2013 00:19
Prevent page zoom, specifically for mobile websites once you have a responsive layout
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0"/>
<title>No Zoom for You</title>
</head>
<body>
</body>
</html>
@pbojinov
pbojinov / trim.string.js
Last active December 5, 2018 16:09
Shorten string to specified max length and and append ... at the end. It will not cut in the middle of a word but at the minimum amount of words under the limit.
function trim(message, maxLength) {
var m = message;
var maxLen = maxLength;
//string is too long, lets trim it and append ...
if (m.length > maxLen) {
var lastSpace = m.lastIndexOf(' ');
//there is no space in the word
if (lastSpace === -1) {
m = m.slice(0, maxLen-3);

jQuery Conference Austin

10 Sept 2013

The State of jQuery - Dave Methvin

@pbojinov
pbojinov / mongolab.connect.js
Created September 27, 2013 00:36
MongoDB Connection From Node.js To MongoLab
//http://tamsler.blogspot.com/2012/06/mongodb-connection-from-nodejs-to.html
var mongo = require('mongodb');
var Server = mongo.Server;
var Db = mongo.Db;
var server = new Server('ds1234.mongolab.com', 12345, {auto_reconnect : true});
var db = new Db('db-name', server);
db.open(function(err, client) {
@pbojinov
pbojinov / ie.css.stylesheet.js
Last active December 24, 2015 11:09
style.innerHTML fix for IE
var style = document.createElement('style'),
styleContent = 'body{background-color: red;}';
//IE 8 and below
if (style.styleSheet) {
style.styleSheet.cssText = styleContent;
}
else {
style.innerHTML = styleContent;
}