Skip to content

Instantly share code, notes, and snippets.

View pbojinov's full-sized avatar

Petar Bojinov pbojinov

View GitHub Profile
@pbojinov
pbojinov / base64.py
Created March 26, 2014 07:39
base64 encode/decode
import base64
encoded = base64.b64encode('b604de2f-bfe4-4449-9f31-3d6695918327')
assert (encoded == 'YjYwNGRlMmYtYmZlNC00NDQ5LTlmMzEtM2Q2Njk1OTE4MzI3')
decoded = base64.b64decode(encoded)
assert (decoded == 'b604de2f-bfe4-4449-9f31-3d6695918327')
@pbojinov
pbojinov / datetime.py
Created March 26, 2014 07:41
using python datetime for current time and time next year
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
@pbojinov
pbojinov / string_formatting.py
Created March 27, 2014 05:48
string formatting in python
# The sophosticated way
formatted_string = "My {0} has {1} whiskers and {2} paws".format('cat', 30, 4)
print formatted_string
@pbojinov
pbojinov / ga.javascript.error.js
Created April 15, 2014 21:11
Track JavaScript Errors with Google Analytics
//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
@pbojinov
pbojinov / dynamic-font-size.css
Created April 24, 2014 18:25
dynamic font size
html {
font-size: 62.5%;
}
body {
font-size: 1em;
}
@media (max-width: 300px) {
html {
<style> html{display:none;} </style>
<script>
if(self == top) {
document.documentElement.style.display = 'block';
}
else {
top.location = self.location;
}
</script>
@pbojinov
pbojinov / array.deferred.js
Last active August 29, 2015 14:01
array of deferred
var doStuff = doAsyncThings();
$.when.apply(null, doStuff).done(function() {
console.log('done with async stuff');
});
function doAsyncThings() {
var deferreds = [];
deferreds.push(function() {
@pbojinov
pbojinov / index.html
Last active August 29, 2015 14:01
double inner box shadow
<!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*/
@pbojinov
pbojinov / disableHotCorners.scpt
Created May 28, 2014 06:19
applescript to disable hot corners
-- 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.
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