Skip to content

Instantly share code, notes, and snippets.

View elijahmanor's full-sized avatar
😀

Elijah Manor elijahmanor

😀
View GitHub Profile
@remy
remy / gist:350433
Created March 31, 2010 14:58
Storage polyfill
if (typeof window.localStorage == 'undefined' || typeof window.sessionStorage == 'undefined') (function () {
var Storage = function (type) {
function createCookie(name, value, days) {
var date, expires;
if (days) {
date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
expires = "; expires="+date.toGMTString();
// ----------------------------------------------------------
// A short snippet for detecting versions of IE in JavaScript
// without resorting to user-agent sniffing
// ----------------------------------------------------------
// If you're not in IE (or IE version is less than 5) then:
// ie === undefined
// If you're in IE (>=5) then you can determine which version:
// ie === 7; // IE7
// Thus, to detect IE:
// if (ie) {}
// SMELLY: HTML in your JavaScript
$('#showMessage').click(function() {
$('<div>' +
'<h1>' + $('#messageTitle').val() + '</h1>' +
'<p>' + $('#messageText').val() + '</p>' +
'</div>')
.appendTo('#messageContainer')
});
// MINTY FRESH: Use templates instead
function xdomainajax() {
var win;
if (document.location == "otcsandbox.com") {
var content = "<html><body><scr"+"ipt>document.domain='otcsandbox.com';</scr"+"ipt><scr"+"ipt src='http://wheretogetjqueryfrom.com/jquery.js'></scr"+"ipt></body></html>";
var iframe = document.createElement("iframe");
document.body.appendChild(iframe);
win = iframe.contentDocument ? iframe : iframe.contentWindow ? iframe.contentWindow : iframe;
var doc = iframe.contentDocument ? iframe.contentDocument ? iframe.contentWindow ? iframe.contentWindow.document ? win.document;
doc.open();
@coolaj86
coolaj86 / how-to-publish-to-npm.md
Last active April 2, 2024 20:18
How to publish packages to NPM

Getting Started with NPM (as a developer)

As easy as 1, 2, 3!

Updated:

  • Aug, 08, 2022 update config docs for npm 8+
  • Jul 27, 2021 add private scopes
  • Jul 22, 2021 add dist tags
  • Jun 20, 2021 update for --access=public
  • Sep 07, 2020 update docs for npm version
@eliperelman
eliperelman / lazy_parse_int.js
Created February 3, 2012 16:58 — forked from nathansmith/parseint.js
Makes parseInt have default radix of 10.
// JSLint:
/*global window, parseInt*/
// Conditionally check value, in case
// future implementations of parseInt
// provide native base-10 by default.
(function () {
var _parseInt = window.parseInt;
if (_parseInt('09') === 0) {
@ifandelse
ifandelse / ConnectivityFsm.js
Created March 14, 2012 05:30
FSM to manage offline/online
var ConnectivityFsm = ( function( $, machina, amplify ) {
return function( heartbeatDef ) {
var settings = $.extend( true, {
type: "GET",
dataType: "json",
timeout: 5000
}, heartbeatDef );
function deferredRequest( resource, data ) {
return $.Deferred(function( dfd ) {
amplify.request({
resourceId: resource,
data: data,
success: dfd.resolve,
error: dfd.reject
});
}).promise();
}
@jcreamer898
jcreamer898 / README.md
Created July 13, 2012 21:18
Using amplifyjs as with RequireJS 2.0

Using AmplifyJS with RequireJS 2.0

With the lastest version of Require, a new config object was introduced, the shim.

http://requirejs.org/docs/api.html#config-shim

That allows Amplify to now be used within AMD projects.

Have Fun!

@getify
getify / test.js
Created August 16, 2012 21:25
object JSON serialization that's circular-ref safe
// all this `toJSON()` does is filter out any circular refs. all other values/refs,
// it passes through untouched, so it should be totally safe. see the test examples.
// only extend the prototype if `toJSON` isn't yet defined
if (!Object.prototype.toJSON) {
Object.prototype.toJSON = function() {
function findCircularRef(obj) {
for (var i=0; i<refs.length; i++) {
if (refs[i] === obj) return true;
}