Skip to content

Instantly share code, notes, and snippets.

View cheeseonamonkey's full-sized avatar
😅
Sweating, and smiling

Alexander H cheeseonamonkey

😅
Sweating, and smiling
View GitHub Profile
@JamieMason
JamieMason / lazySingleton.js
Created March 1, 2011 08:27
JavaScript Singleton with lazy instantiation.
var ConstructorName = (function()
{
var singletonInstance = null;
function ConstructorName()
{
// presumably expensive instantiation/init code
}
@hiromi2424
hiromi2424 / json_debug.php
Created April 21, 2011 10:39
simple json formatter(possible to use formatted)
// almost same output can be seen at:
// http://jsonformatter.curiousconcept.com/
class JsonDebug {
function format($json, $output = false) {
$depth = 0;
$length = strlen($json);
$result = '';
for ($n = 0; $n < $length; $n++) {
$c = $json{$n};
@pinglamb
pinglamb / pretty_print.css
Created November 5, 2011 18:22
JSON Pretty Print JS
body { font-family: monospace; font-size: 1.1em; }
ul { margin: 0 0 0 .2em; list-style: none; }
li { padding: 0; margin: 0;}
li:after { content: ','; }
li:last-child:after { content: ''; }
span.object { font-weight: bold; }
span.string, span.string a { color: green; }
@MrChuffmanSnippets
MrChuffmanSnippets / index.html
Created March 15, 2012 10:05
HTML5: Blank Template
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title></title>
<link href="style.css" rel="stylesheet" />
</head>
<body>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
@liammjwise
liammjwise / CSS Needed
Created April 19, 2012 18:07
Simple Navigation Bar Template
#navcontainer { width: 200px; }
#navcontainer ul
{
margin-left: 0;
padding-left: 0;
list-style-type: none;
font-family: Arial, Helvetica, sans-serif;
}
#navcontainer a
@netpoetica
netpoetica / Singleton.js
Created August 20, 2012 01:36
A Singleton in JavaScript that truly ensures one instance, can be lazy-loaded (you can instantiate it whenever you need it), and has private and public scope.
/* **
*
* Singleton.js - a true Singleton in JavaScript
*
* A Singleton in JavaScript that truly ensures one instance, can be lazy loaded / you
* can instantiate it whenever you need it and has private and public scope.
*
* @author Keith Rosenberg, netPoetica
*
* */
@cardil
cardil / ExamplePartOfActivity.java
Last active January 31, 2022 10:49
MultiSelectListPreference for devices running Android in the API earlier than level 11. Support ChangeListener receiving list of selected values. Supports automatically setting of summary. Examples attached.
private static OnPreferenceChangeListener autoOnChangeListener = new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference rawPreference, Object newValue) {
List<CharSequence> selected = Arrays.asList((CharSequence[]) newValue);
if (selected.contains("1")) {
// do some work
}
return true;
}
@coiscir
coiscir / Singletons.md
Last active September 20, 2022 23:18
JavaScript Singletons

From http://stackoverflow.com/a/15196301/:

p.s. i'll be glad to hear you solution to my other question stackoverflow.com/questions/15274927/…. ( maybe you have a better solution). Royi Namir 2013-03-08 07:03:32Z

The answers do include good examples of both eagerly-loaded/instant (e.g., jantimon, SLaks) and lazy-loaded singletons (e.g., Kolink).

Though, for a few variations on lazy-loaded: :)

It is possible to return the instance (single-instance-constructor.js) each time, but this will probably be confusing unless [it's not actually new](http://jsfiddle.net/cois

@X4
X4 / autocomplete.zsh
Last active March 17, 2023 17:21
some zsh modules
#
# Sets completion options.
#
# Load and initialize the completion system ignoring insecure directories.
zmodload zsh/complist
autoload -Uz compinit && compinit -i
autoload -U colors ; colors
zle -C complete-menu menu-select _generic
# Hard-code DNS resolver to Google's servers
#
# *Setup*
# # download this file while DNS is working
# curl https://gist.github.com/turadg/7876784/raw --output ~/google-resolv.conf
# # replace your old DNS resolver
# sudo cp /etc/resolv.conf /etc/resolv.conf.auto && sudo mv ~/google-resolv.conf /etc/resolv.conf
# # make it uneditable so Vagrant doesn't clobber it
# sudo chattr +i /etc/resolv.conf