Skip to content

Instantly share code, notes, and snippets.

View tyaslab's full-sized avatar
🌴
On vacation

Yusuf Ali tyaslab

🌴
On vacation
View GitHub Profile
@tyaslab
tyaslab / jquery.plugin.js
Created June 13, 2013 05:04
jQuery Plugin Kickstarter
/*
* BLANK jQuery Plugin
*/
(function($) {
// replace pluginName to yours
$.fn.pluginName = function(opts) {
// extends default options to that of user-defined
var options = $.extend({}, $.fn.pluginName.defaults, opts);
// selector
@tyaslab
tyaslab / settings.py
Created June 15, 2013 02:11
more flexible django settings.py
import os
from django.conf import settings
PWD = os.path.dirname(os.path.dirname(__file__))
### ...
DATABASES = {
### ...
'NAME': os.path.join(PWD, 'databasename.db'), # Or path to database file if using sqlite3.
### ...
@tyaslab
tyaslab / gist:5848008
Created June 24, 2013 06:00
Install Python Imaging Library
1. sudo apt-get install python-dev zlib1g-dev libjpeg62-dev libpng12-dev libfreetype6-dev
2. Download PIL Installer from http://www.pythonware.com/products/pil/
3. Extract, cd,
4. sudo python setup.py install
5. Just wait.
@mixin set-space($kind, $indicator, $selector) {
.#{$kind}-#{$indicator}-#{$selector} {
@if ($indicator == 'all') {
#{$kind}: ($selector / 16) + rem !important;;
} @else {
#{$kind}-#{$indicator}: ($selector / 16) + rem !important;
}
}
}
@tyaslab
tyaslab / main.py
Created March 20, 2015 00:04
Lightweight Django
#!/usr/bin/env python
import sys
from django.conf import settings
settings.configure(
DEBUG=True,
SECRET_KEY='th15-15-4-53c123t-k3y',
ROOT_URLCONF=__name__,
MIDDLEWARE_CLASSES=(
@tyaslab
tyaslab / select2-directive.js
Last active May 17, 2016 11:39
angular select2 directive
<!DOCTYPE html>
<html data-ng-app="app">
<head>
<title>Test Select2</title>
<link rel="stylesheet" href="{{ STATIC_URL }}front/bower_components/select2/select2.css">
</head>
<body>
<div data-ng-controller="MyController">
{[{ apaAtuh }]}
@tyaslab
tyaslab / close-topbar
Created March 29, 2015 16:44
Angular Close Topbar after changing route
app.run(['$rootScope', '$location', function($rootScope, $location) {
$rootScope.$watch(function() {
return $location.path();
}, function(a) {
$(document).foundation();
$rootScope.flash_messages = [];
// FIX TOP BAR EXPANSION
$('.top-bar').removeClass('expanded').css({
height: ''
});
@tyaslab
tyaslab / django_arithmetic_aggregate
Created March 30, 2015 03:59
Django < 1.8 arithmetic aggregate more than one field
MyModel.objects.aggregate(subtotal=Sum('qty', field='qty * price'))
'qty' ==> fill whatever you want
'qty * price' ==> the real aggregate
annotate is applicable too!
PS:
@tyaslab
tyaslab / simple-django-polymorphic.py
Last active August 29, 2015 14:18
Simple Django Polymorphic
# http://stackoverflow.com/questions/5360995/polymorphism-in-django-models
# http://stackoverflow.com/questions/929029/how-do-i-access-the-child-classes-of-an-object-in-django-without-knowing-the-nam/929982#929982
from django.db import models
from django.contrib.contenttypes.models import ContentType
from django.db.models.query import QuerySet
class SubclassingQuerySet(QuerySet):
def __getitem__(self, k):
@tyaslab
tyaslab / django-and-time-zone
Created April 8, 2015 03:25
Django and Time Zone
fm1 = FakeModel.objects.create(name='Fake Name', event_date='2014-01-01 00:00:00')
then, in database, the event_date is '2013-12-31 17:00:00'
Django treats the date as current time zone, while SQL backend saves it as GMT