This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import base64 | |
encoded = base64.b64encode('b604de2f-bfe4-4449-9f31-3d6695918327') | |
assert (encoded == 'YjYwNGRlMmYtYmZlNC00NDQ5LTlmMzEtM2Q2Njk1OTE4MzI3') | |
decoded = base64.b64decode(encoded) | |
assert (decoded == 'b604de2f-bfe4-4449-9f31-3d6695918327') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The sophosticated way | |
formatted_string = "My {0} has {1} whiskers and {2} paws".format('cat', 30, 4) | |
print formatted_string |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
html { | |
font-size: 62.5%; | |
} | |
body { | |
font-size: 1em; | |
} | |
@media (max-width: 300px) { | |
html { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<style> html{display:none;} </style> | |
<script> | |
if(self == top) { | |
document.documentElement.style.display = 'block'; | |
} | |
else { | |
top.location = self.location; | |
} | |
</script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var doStuff = doAsyncThings(); | |
$.when.apply(null, doStuff).done(function() { | |
console.log('done with async stuff'); | |
}); | |
function doAsyncThings() { | |
var deferreds = []; | |
deferreds.push(function() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Understanding PATCH | |
As its name implies, a REST-based API involves passing around the representation of the state of a resource. This is most commonly applied to HTTP, which is very straightforward: to read the current state of a resource, perform a GET operation on the resource’s URI. To update a resource, pass the new representation of the resource to its URI in a PUT operation. The PUT method is defined as a complete replacement of the resource at a given URI, meaning you must always provide the full representation that you want to set. But what if you only want to update a few fields in the resource? That’s done with the PATCH method. | |
The exact semantics of how the body of a PATCH request is applied to the requested resource are determined by the media type of the request. The way GitHub (and many other JSON APIs) handles PATCH requests is that you provide the JSON representation of the resource to update, omitting any fields that should be left unchanged. So for example, to update only the description |
OlderNewer