View base64.py
import base64 | |
encoded = base64.b64encode('b604de2f-bfe4-4449-9f31-3d6695918327') | |
assert (encoded == 'YjYwNGRlMmYtYmZlNC00NDQ5LTlmMzEtM2Q2Njk1OTE4MzI3') | |
decoded = base64.b64decode(encoded) | |
assert (decoded == 'b604de2f-bfe4-4449-9f31-3d6695918327') |
View datetime.py
from datetime import timedelta, datetime | |
# current time | |
now = datetime.now() | |
print now | |
# a year from now | |
next_year = (datetime.today()+ timedelta(days=365)) | |
print next_year |
View string_formatting.py
# The sophosticated way | |
formatted_string = "My {0} has {1} whiskers and {2} paws".format('cat', 30, 4) | |
print formatted_string |
View ga.javascript.error.js
//http://davidwalsh.name/track-errors-google-analytics?utm_source=javascriptweekly&utm_medium=email | |
// Track basic JavaScript errors | |
window.addEventListener('error', function(e) { | |
_gaq.push([ | |
'_trackEvent', | |
'JavaScript Error', | |
e.message, | |
e.filename + ': ' + e.lineno, | |
true |
View dynamic-font-size.css
html { | |
font-size: 62.5%; | |
} | |
body { | |
font-size: 1em; | |
} | |
@media (max-width: 300px) { | |
html { |
View framebusters.html
<style> html{display:none;} </style> | |
<script> | |
if(self == top) { | |
document.documentElement.style.display = 'block'; | |
} | |
else { | |
top.location = self.location; | |
} | |
</script> |
View array.deferred.js
var doStuff = doAsyncThings(); | |
$.when.apply(null, doStuff).done(function() { | |
console.log('done with async stuff'); | |
}); | |
function doAsyncThings() { | |
var deferreds = []; | |
deferreds.push(function() { |
View index.html
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>box shadow</title> | |
<style> | |
.item { | |
background: orange; | |
border: solid 1px blue; | |
box-shadow: inset 0 0 0 1px red, inset 0 0 0 2px green; /* nesting inset shadow*/ |
View enableHotCorners.scpt
-- By Richard Kulesus, 2009. Released without license! | |
-- Use this for whatever! | |
-- I seriously despise code authors who copyright tiny bits of obvious code | |
-- like it's some great treasure. This is small and simple, and if it saves | |
-- the next guy some time and trouble coding applescript I'll feel good! | |
-- | |
-- Quickly change all the hot-corners to do what you want. | |
-- Particularly useful for presentations and full-screen games. | |
-- Customize the activity of each hot-corner with "all windows/application windows/dashboard/disable screen saver/none/notification center/show desktop/sleep display/start screen saver" | |
-- The MODIFIERS are the keys which can be used to supplement hot-corner activation. |
View disableHotCorners.scpt
-- By Richard Kulesus, 2009. Released without license! | |
-- Use this for whatever! | |
-- I seriously despise code authors who copyright tiny bits of obvious code | |
-- like it's some great treasure. This is small and simple, and if it saves | |
-- the next guy some time and trouble coding applescript I'll feel good! | |
-- | |
-- Quickly change all the hot-corners to do what you want. | |
-- Particularly useful for presentations and full-screen games. | |
-- Customize the activity of each hot-corner with "all windows/application windows/dashboard/disable screen saver/none/show desktop/show spaces/sleep display/start screen saver" | |
-- The MODIFIERS are the keys which can be used to supplement hot-corner activation. |
OlderNewer