Skip to content

Instantly share code, notes, and snippets.

View a1Gupta's full-sized avatar

Ashish Gupta a1Gupta

View GitHub Profile
@tadeo
tadeo / choices_enum.py
Last active August 15, 2018 23:51 — forked from treyhunner/choice_enum.py
Enum for use with Django ChoiceField
from enum import Enum, EnumMeta
class ChoicesEnumMeta(EnumMeta):
def __iter__(self):
return ((choice.name, choice.value) for choice in super().__iter__())
class ChoicesEnum(Enum, metaclass=ChoicesEnumMeta):
def __str__(self):
@treyhunner
treyhunner / choice_enum.py
Created April 9, 2018 23:49
Enum for use with Django ChoiceField
from enum import Enum, EnumMeta
class ChoiceEnumMeta(EnumMeta):
def __iter__(self):
return ((tag, tag.value) for tag in super().__iter__())
class ChoiceEnum(Enum, metaclass=ChoiceEnumMeta):
"""

FWIW: I (@rondy) am not the creator of the content shared here, which is an excerpt from Edmond Lau's book. I simply copied and pasted it from another location and saved it as a personal note, before it gained popularity on news.ycombinator.com. Unfortunately, I cannot recall the exact origin of the original source, nor was I able to find the author's name, so I am can't provide the appropriate credits.


Effective Engineer - Notes

What's an Effective Engineer?

anonymous
anonymous / urlscreenshot.js
Created October 27, 2016 08:36
import phantom from 'phantom'
import { PassThrough } from 'stream'
import createError from 'http-errors'
import reemit from 're-emitter'
/* eslint-disable max-len */
const mobileUA = 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_0 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7'
const desktopUA = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.116 Safari/537.36'
const getShotSize = (width, height) => ({
-- This presents an example of rendering templates in the database.
-- DO NOT DO THIS! It's a terrible idea, and just example for my talk
-- which you can see at https://speakerdeck.com/andrewgodwin/dubious-database-design
CREATE EXTENSION plpythonu;
-- Table to store template HTML by name
CREATE TABLE templates (
"name" text PRIMARY KEY,
"template" text
@SaneMethod
SaneMethod / django-python-social-auth-monkey.py
Created July 21, 2015 21:03
Email validation pipeline monkey patch for python-social-auth and Django.
# Monkey patching - an occasionally necessary evil.
from social import utils
from social.exceptions import InvalidEmail
from django.core import signing
from django.core.signing import BadSignature
from django.contrib.sessions.models import Session
from django.conf import settings
@ghinda
ghinda / object-to-form-data.js
Last active May 21, 2024 20:48
JavaScript Object to FormData, with support for nested objects, arrays and File objects. Includes Angular.js usage.
// takes a {} object and returns a FormData object
var objectToFormData = function(obj, form, namespace) {
var fd = form || new FormData();
var formKey;
for(var property in obj) {
if(obj.hasOwnProperty(property)) {
if(namespace) {
@pindia
pindia / gist:9b7787a607a5a676c6d8
Last active February 27, 2017 23:09
Django session cookie migration
# Read more at http://www.pindi.us/blog/migrating-cross-domain-cookies-django
from django.conf import settings
from importlib import import_module
class UpdateSessionCookieMiddleware(object):
"""
Migrates session data from an old (hardcoded) session cookie name and domain to the name and
domain currently defined in the Django settings.
@jpadilla
jpadilla / validators.py
Created January 27, 2014 23:46
DomainNameValidator adapted from Django's EmailValidator.
import re
from django.utils.encoding import force_text
from django.core.exceptions import ValidationError
class DomainNameValidator(object):
"""
Domain name validator adapted from Django's EmailValidator.
"""
@RobBlackwell
RobBlackwell / Python Copy Blob
Created November 19, 2013 15:54
Python code to copy blobs between Windows Azure Storage accounts
#!/usr/bin/env python
import sys
import datetime
import time
from datetime import timedelta
sys.path.append('/home/reb/local/azure-sdk-for-python/')
from azure.storage import *