Skip to content

Instantly share code, notes, and snippets.

View 1337's full-sized avatar
🧠
🤯

Brіаn 1337

🧠
🤯
View GitHub Profile
@1337
1337 / dt.js
Last active October 11, 2015 21:28
Bring you to the definition.
/*
when you click on <a class="dt">Hello</a> and a
<dt>Hello</dt> is on the same page, the page scrolls
to that location.
*/
$(document).ready(function () {
$('a.dt', document).each(function () {
var that = $(this), rel = that.attr('href') ||
that.text().replace(/\s+/g, ' ');
if (!rel) {
@1337
1337 / gos.js
Last active October 4, 2015 13:48
get any one script
var getAnyOneScript = function (scripts) {
// TODO: http://stackoverflow.com/questions/2027849/how-to-trigger-script-onerror-in-internet-explorer/2032014#2032014
scripts = scripts instanceof Array ? scripts : [scripts];
var script = document.createElement('script');
script.setAttribute('type', 'text/javascript');
script.setAttribute('src', scripts[0]);
script.onerror = function () {
scripts.shift();
getAnyOneScript(scripts);
@1337
1337 / gist:2314040
Last active October 2, 2015 20:28
Far fewer things to hate about JavaScript
/* http://javascript.crockford.com/code.html
JavaScript code should not be embedded in HTML files unless
the code is specific to a single session.
*/
// All variables should be declared before used.
var sampleVar; // Avoid lines longer than 80 characters.
var stupidFunction = function (param1, param2, param3, // There should be no space between the name of a function and the (, except If a function literal is anonymous
@1337
1337 / pep8.py
Created April 5, 2012 19:52
So many things to hate about PEP 8
#!/usr/bin/env python
# PEP 20 supersedes PEP 8 http://www.python.org/dev/peps/pep-0008/#a-foolish-consistency-is-the-hobgoblin-of-little-minds
# Follow PEP 20 if readability is affected by PEP 8
# max length 79 chars, not 80 (http://www.python.org/dev/peps/pep-0008/#maximum-line-length)
"""One-line summary of purpose. # double quoted docstrings; max length 72 chars (http://www.python.org/dev/peps/pep-0008/#maximum-line-length)
# 2nd line must be blank http://www.python.org/dev/peps/pep-0257/#multi-line-docstrings
More things # aligns with the quotes
More things
"""