Skip to content

Instantly share code, notes, and snippets.

Haki Benita hakib

Block or report user

Report or block hakib

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@bennadel
bennadel / Application.cfc
Last active May 8, 2019
Cool Things I Learned From Reading The CommonMark Spec For Markdown
View Application.cfc
component
output = false
hint = "I provide the application settings and event handlers."
{
// Define the application.
this.name = hash( getCurrentTemplatePath() );
this.applicationTimeout = createTimeSpan( 0, 0, 10, 0 );
this.sessionManagement = false;
@hakib
hakib / admin.py
Last active Oct 3, 2019
How to Turn Django Admin Into a Lightweight Dashboard
View admin.py
# https://hakibenita.com/how-to-turn-django-admin-into-a-lightweight-dashboard
from django.contrib import admin
from django.db.models import Count, Sum, Min, Max, DateTimeField
from django.db.models.functions import Trunc
from . import models
def get_next_in_date_hierarchy(request, date_hierarchy):
@MarkusH
MarkusH / changes.patch
Created Apr 14, 2015
Postgresql function based indexes in Django (based on 825bb0ab08cec353edcd2b9aea651bfe9392ef97)
View changes.patch
diff --git a/django/db/backends/postgresql_psycopg2/schema.py b/django/db/backends/postgresql_psycopg2/schema.py
index 8340059..692866e 100644
--- a/django/db/backends/postgresql_psycopg2/schema.py
+++ b/django/db/backends/postgresql_psycopg2/schema.py
@@ -1,6 +1,21 @@
import psycopg2
from django.db.backends.base.schema import BaseDatabaseSchemaEditor
+from django.db.models.expressions import Func
+from django.db.models.sql.compiler import SQLCompiler
@vero4karu
vero4karu / tests.py
Last active Aug 22, 2019
Mock/replace timezone.now() with a custom date in Django unittes
View tests.py
#! /usr/bin/env python
# -*- coding: utf-8 -*-
import datetime
from mock import patch
from django.test import TestCase
from django.utils import timezone
class DatesTestCase(TestCase):
@ebuildy
ebuildy / gist:5d4ad0998848eaefdad8
Last active Nov 7, 2018
Setup sentry logger on a fresh Ubuntu server
View gist:5d4ad0998848eaefdad8
sudo apt-get update
sudo apt-get install python-virtualenv
sudo apt-get install python-dev
sudo apt-get install postgresql
sudo apt-get install postgresql-server-dev-9.3
sudo apt-get install redis-server
sudo -u postgres createuser -s sentry
sudo -u postgres psql -c "alter user sentry with password 'sentry';"
@brucecoddington
brucecoddington / resources.js
Last active Oct 21, 2017
Wrapping $resource with api and data services.
View resources.js
angular.module('app.resources', ['ngResource'])
.factory('api', function ($resource) {
var api = {
defaultConfig : {id: '@id'},
extraMethods: {
'update' : {
method: 'PUT'
}
@jmcnamara
jmcnamara / bench_excel_writers.py
Last active Sep 18, 2019
Benchmark of several Python Excel writing modules
View bench_excel_writers.py
##############################################################################
#
# Simple Python program to benchmark several Python Excel writing modules.
#
# python bench_excel_writers.py [num_rows] [num_cols]
#
#
import sys
from time import clock
@mlouro
mlouro / gulpfile.js
Last active Aug 10, 2019
gulpfile.js with browserify, jshint, libsass, browserSync for livereload, image optimization and system notifications on errors
View gulpfile.js
'use strict';
var gulp = require('gulp');
var gutil = require('gulp-util');
var del = require('del');
var uglify = require('gulp-uglify');
var gulpif = require('gulp-if');
var exec = require('child_process').exec;
var notify = require('gulp-notify');
@anacrolix
anacrolix / striter.py
Created Sep 26, 2012
A Python IO class wrapping an iterable of strings.
View striter.py
import io
class StringIteratorIO(io.TextIOBase):
def __init__(self, iter):
self._iter = iter
self._left = ''
def readable(self):
return True
@c4urself
c4urself / url_patterns.py
Created Jun 16, 2011
URL Patterns with Optional Arguments
View url_patterns.py
(r'^articles/(?P<year>\d{4}/?$, 'main.views.year'),
# When a use case comes up that a month needs to be involved as
# well, you add an argument in your regex:
(r'^articles/(?P<year>\d{4}/(?P<month>\d{2})/?$, 'main.views.year_month'),
# That works fine, unless of course you want to show something
# different for just the year, in which case the following case can be
# used, making separate views based on the arguments as djangoproject
You can’t perform that action at this time.