Skip to content

Instantly share code, notes, and snippets.

View pjeweb's full-sized avatar

Paul Golmann pjeweb

View GitHub Profile
@pjeweb
pjeweb / addCssToDocument.js
Created March 6, 2013 20:48
Dynamically add css to document
function addCssToDocument(css) {
var styleElement = document.createElement('style');
document.getElementsByTagName('head')[0].appendChild(styleElement);
var isIe = styleElement.styleSheet;
if (isIe)
styleElement.styleSheet.cssText = css;
else
styleElement.appendChild(document.createTextNode(css));
}
@pjeweb
pjeweb / example-jquery.js
Created February 11, 2012 18:49
Simple PubSub snippet for both browser and nodejs (just remove outer wrap-function).
/* Use PubSub on e.g. jQuery */
PubSub.apply($);
function addText(text) {
$('body').append('<p>' + text + '</p>');
}
function logChange(text) {
console.log('new text: ' + text);
}
@pjeweb
pjeweb / gist:1424089
Created December 2, 2011 17:30
Calculate Azimut
var calcAzimut = function (p1, p2) {
'use strict';
var toDeg = function (x) {
return x * 180 / Math.PI;
},
dy = p2.latitude - p1.latitude,
dx = p2.longitude - p1.longitude;
return (
(dx > 0) ? toDeg((Math.PI * 0.5) - Math.atan(dy / dx)) :
// Released under MIT license: http://www.opensource.org/licenses/mit-license.php
// good javascript
(function ($) {
'use strict';
$(function () {
$('[placeholder]')
.focus(function () {
var input = $(this);
if (input.val() === input.attr('placeholder')) {