Skip to content

Instantly share code, notes, and snippets.

View swernerx's full-sized avatar

Sebastian Werner swernerx

View GitHub Profile
// ----------------------------------------------------------
// 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) {}
@jed
jed / LICENSE.txt
Created May 20, 2011 13:27 — forked from 140bytes/LICENSE.txt
generate random UUIDs
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Jed Schmidt <http://jed.is>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
function flatten_array(arr) {
var i;
for (i=0; i<arr.length; ) {
if (Object.prototype.toString.call(arr[i]) == "[object Array]") {
// prepend `splice()` arguments to `tmp` array, to enable `apply()` call
arr.splice.apply(arr,[i,1].concat(arr[i]));
continue;
}
i++;
/*
* Minimal classList shim for IE 9
* By Devon Govett
* MIT LICENSE
*/
if (!("classList" in document.documentElement) && Object.defineProperty && typeof HTMLElement !== 'undefined') {
Object.defineProperty(HTMLElement.prototype, 'classList', {
get: function() {

#Understanding MVC And MVP (For JavaScript & Backbone Developers)

Before exploring any JavaScript frameworks that assist in structuring applications, it can be useful to gain a basic understanding of architectural design patterns. Design patterns are proven solutions to common development problems and can suggest structural paradigms to help guide us in adding some organization to our application.

I think patterns are exciting as they're effectively a grass roots effort that build upon the collective experience of skilled developers who have previously faced similar problems as we do now. Although developers 10 or 20 years ago may not have been using the same programming languages for implementing patterns, there are many lessons we can learn from their efforts.

In this section, we're going to review two popular patterns - MVC and MVP. The context of our exploration will be how these patterns are related to the popular JavaScript framework Backbone.js, which will be explored in greater detail later on.

# MAC manipulators
alias random_mac='sudo ifconfig en0 ether `openssl rand -hex 6 | sed "s/\(..\)/\1:/g; s/.$//"`'
alias restore_mac='sudo ifconfig en0 ether YOUR_ORIGINAL_MAC_ADDRESS_GOES_HERE'
@brettz9
brettz9 / navigator.language.js
Last active January 3, 2019 17:19
navigator.language
// Defined: http://www.whatwg.org/specs/web-apps/current-work/multipage/timers.html#navigatorlanguage
// with allowable values at http://www.ietf.org/rfc/bcp/bcp47.txt
// Note that the HTML spec suggests that anonymizing services return "en-US" by default for
// user privacy (so your app may wish to provide a means of changing the locale)
navigator.language = navigator.language ||
// IE 10 in IE8 mode on Windows 7 uses upper-case in
// navigator.userLanguage country codes but per
// http://msdn.microsoft.com/en-us/library/ie/ms533052.aspx (via
// http://msdn.microsoft.com/en-us/library/ie/ms534713.aspx), they
// appear to be in lower case, so we bring them into harmony with navigator.language.
@WebReflection
WebReflection / typeOf.js
Last active February 15, 2016 16:12
An incrementally improved approach to a common JavaScript function/utility widely adopted all over. Returns the lowercase type or [[Class]] of a generic variable.
var typeOf = (function(Object, RegExp){
// WTFPL License - http://en.wikipedia.org/wiki/WTFPL
// thanks to @jdalton and @ljharb
var toString = Object.prototype.toString,
cache = (Object.create || Object)(null);
return function typeOf(Unknown) {
var asString = typeof Unknown;
return asString == 'object' ? (
Unknown === null ? 'null' : (
cache[asString = toString.call(Unknown)] || (
@maxhoffmann
maxhoffmann / gist:7373563
Last active December 27, 2015 18:59
run local php server and open browser
# local PHP Server
server() {
url="localhost:${2:-8000}"
if [ -z "$1" ]; then
php -S $url & # run server in background
else
php -S $url -t $1 &
fi
sleep 0.3s # wait for server to start
@brianloveswords
brianloveswords / git-obliterate
Last active January 24, 2024 12:28
git-obliterate: for removing sensitive files you may have committed from the entire history of the project.
#!/bin/bash
file=$1
test -z $file && echo "file required." 1>&2 && exit 1
git filter-branch -f --index-filter "git rm -r --cached $file --ignore-unmatch" --prune-empty --tag-name-filter cat -- --all
git ignore $file
git add .gitignore
git commit -m "Add $file to .gitignore"