Skip to content

Instantly share code, notes, and snippets.

View callmephilip's full-sized avatar

Philip Nuzhnyi callmephilip

View GitHub Profile
@callmephilip
callmephilip / gist:3430537
Created August 22, 2012 23:30
[Django] requiring a view to accept particular method(s)
from django.views.decorators.http import require_http_methods
@require_http_methods(["GET", "POST"])
def my_view(request):
# I can assume now that only GET or POST requests make it this far
# ...
pass
@callmephilip
callmephilip / gist:3430847
Created August 23, 2012 00:30
[CSS] box with an inset shadow
{
background: white;
border-radius: 5px;
padding: 20px;
-moz-box-shadow: inset 0 0 5px #999;
-webkit-box-shadow: inset 0 0 6px #757575;
box-shadow: inner 0 0 5px #999;
}
@callmephilip
callmephilip / gist:3443827
Created August 24, 2012 00:09
[Python Fabric] passing arguments to a task
def new_user(username, admin='no', comment="No comment provided"):
log_action("New User (%s): %s" % (username, comment))
pass
$ fab new_user:myusername
$ fab new_user:username=myusername
$ fab new_user:myusername,yes
$ fab new_user:myusername,admin=yes
$ fab new_user:myusername,admin=no,comment='Gary\, new developer (starts Monday)'
@callmephilip
callmephilip / gist:3445229
Created August 24, 2012 03:47
[Python] generate UUID
import uuid
uuid.uuid1().hex
@callmephilip
callmephilip / gist:3445408
Created August 24, 2012 04:26
[Python Django] view decorator with parameters
from functools import wraps
from django.utils.decorators import available_attrs
def my_decorator(parameter_name):
def decorator(view_func):
@wraps(view_func, assigned=available_attrs(view_func))
def _wrapped_view(request, *args, **kwargs):
return view_func(request, *args, **kwargs)
return _wrapped_view
@callmephilip
callmephilip / gist:3490036
Created August 27, 2012 16:22
[JavaScript] Get viewport size
var viewportwidth;
var viewportheight;
// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
if (typeof window.innerWidth != 'undefined')
{
viewportwidth = window.innerWidth,
viewportheight = window.innerHeight
}
@callmephilip
callmephilip / gist:3517765
Created August 29, 2012 19:39
[JavaScript] Dispatching mouse move event
// look here for more details : https://developer.mozilla.org/en-US/docs/DOM/event.initMouseEvent
var mouseMoveEvent = document.createEvent("MouseEvents");
mouseMoveEvent.initMouseEvent(
"mousemove", //event type : click, mousedown, mouseup, mouseover, mousemove, mouseout.
true, //canBubble
false, //cancelable
window, //event's AbstractView : should be window
1, // detail : Event's mouse click count
@callmephilip
callmephilip / gist:3519403
Created August 29, 2012 21:52
[JavaScript] Dispatching keyboard event
// gecko and webkit
// details here https://developer.mozilla.org/en-US/docs/DOM/event.initKeyEvent
var keyboardEvent = document.createEvent("KeyboardEvent");
var initMethod = typeof keyboardEvent.initKeyboardEvent !== 'undefined' ? "initKeyboardEvent" : "initKeyEvent";
keyboardEvent[initMethod](
"keydown", // event type : keydown, keyup, keypress
true, // bubbles
@callmephilip
callmephilip / gist:3520021
Created August 29, 2012 23:00
[CSS] border + some white shadow
{
-webkit-box-shadow: white 0 1px 0 0;
-moz-box-shadow: #fff 0 1px 0 0;
-ms-box-shadow: #fff 0 1px 0 0;
-o-box-shadow: #fff 0 1px 0 0;
box-shadow: white 0 1px 0 0;
border-bottom: 1px solid #EBEAE5;
}
@callmephilip
callmephilip / gist:3626669
Created September 4, 2012 21:21
[JavaScript] Lock site in portrait mode in mobile Safari
// Kudos to Grumdrig
// http://stackoverflow.com/questions/1207008/how-do-i-lock-the-orientation-to-portrait-mode-in-a-iphone-web-application
$(document).ready(function () {
function reorient(e) {
var portrait = (window.orientation % 180 == 0);
$("body > div").css("-webkit-transform", !portrait ? "rotate(-90deg)" : "");
}
window.onorientationchange = reorient;
window.setTimeout(reorient, 0);