Skip to content

Instantly share code, notes, and snippets.

@gengue
gengue / settings.py
Created April 15, 2016 17:46
Django - migrate database across databases engines (master to slave)
...
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
},
'slave': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'motul_db',
'USER': 'root',
import hashlib
import itertools
import concurrent.futures
main_hash = "21216cf6a42bd682172bbe02c51344e1"
salt = "zt6rx8ryrhzcvywduuocdilnymqvqi3z"
chars = ['q','w','e','r','t','y','u','i','o','p','a','s','d','f','g','h','j',
'k','l','z','x','c','v','b','n','m','0', '1','2','3','4','5','6','7',
'8','9','0','_', '$']
@gengue
gengue / 0_reuse_code.js
Created February 25, 2016 15:37
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@gengue
gengue / backends.py
Last active February 25, 2016 15:38
django email or username authentication
# -*- coding: utf-8 -*-
from __future__ import absolute_import, unicode_literals
from django.conf import settings
from users.models import User
class EmailOrUsernameModelBackend(object):
def authenticate(self, username=None, password=None):
if '@' in username:
kwargs = {'email': username}
@gengue
gengue / gist:1d2b6d75619dcb140077
Created September 23, 2015 14:43 — forked from tonymtz/gist:d75101d9bdf764c890ef
Uninstall nodejs from OSX Yosemite
# First:
lsbom -f -l -s -pf /var/db/receipts/org.nodejs.pkg.bom | while read f; do sudo rm /usr/local/${f}; done
sudo rm -rf /usr/local/lib/node /usr/local/lib/node_modules /var/db/receipts/org.nodejs.*
# To recap, the best way (I've found) to completely uninstall node + npm is to do the following:
#go to /usr/local/lib and delete any node and node_modules
cd /usr/local/lib
sudo rm -rf node*
@gengue
gengue / angular_events.js
Created August 20, 2015 03:15
Angular events tutorial
//Source http://stackoverflow.com/questions/14502006/working-with-scope-emit-and-on
/*
First of all, parent-child scope relation does matter. You have two possibilities to emit some event:
$broadcast -- dispatches the event downwards to all child scopes,
$emit -- dispatches the event upwards through the scope hierarchy.
I don't know anything about your controllers (scopes) relation, but there are several options:
If scope of firstCtrl is parent of the secondCtrl scope, your code should work by replacing $emit by $broadcast in firstCtrl:
*/
@gengue
gengue / style.css
Created August 19, 2015 00:15
center and crop image with css
img {
object-fit: cover;
}
@gengue
gengue / jquery.location_picker.js
Last active April 4, 2022 09:45
Django admin Google maps Location picker (api v3)
google.load("maps", "3");
$(document).unload(function(){
GUnload();
});
$(document).ready(function(){
$("input.location_picker").each(function (i) {
var map = document.createElement('div');
map.className = "location_picker_map";
@gengue
gengue / gist:985d53ef848bad362a78
Last active August 29, 2015 14:25 — forked from thiamteck/gist:877276
JQuery Datepicker with Month and Year only
$(document).ready(function(){
$(".monthPicker").datepicker({
dateFormat: 'mm-yy',
changeMonth: true,
changeYear: true,
showButtonPanel: true,
onClose: function(dateText, inst) {
var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
class InstanceMixin(object):
def add_arguments(self):
return {'empresa':self.request.empresa}
def get_form_kwargs(self):
"""
Returns the keyword arguments for instanciating the form.
"""
kwargs = super(InstanceMixin, self).get_form_kwargs()