Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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
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 / 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',
@gengue
gengue / lyric.sh
Last active July 16, 2016 01:13
Get song lyrics from terminal.
#!/bin/bash
if [ "$#" -eq 0 ]; then
artist_name=`osascript -e'tell application "iTunes"' -e'get artist of current track' -e'end tell'`
song_title=`osascript -e'tell application "iTunes"' -e'get name of current track' -e'end tell'`
else
artist_name=$1
song_title=$2
fi
@gengue
gengue / focus.directive.js
Last active September 12, 2017 20:28
Focus directive angularjs
angular.module('app.layouts').directive('focusMe',
function($timeout, $parse) {
return {
link: function(scope, element, attrs) {
var model = $parse(attrs.focusMe);
scope.$watch(model, function(value) {
if(value === true) {
$timeout(function() {
element[0].focus();
@gengue
gengue / download.sh
Last active July 27, 2016 23:32
Download entire website
wget --no-clobber --convert-links --random-wait -r -p -E -e robots=off -U mozilla http://site/path/
#
wget -r --no-parent http://www.mysite.com/Pictures/
@gengue
gengue / rename.sh
Created November 15, 2016 22:35
Rename all files in a directory (BASH)
for file in *_p.png
do
mv "$file" "${file/_p.png/_prueba.png}"
done
@gengue
gengue / base.by
Last active February 11, 2017 17:31
Unescape special chars in Django VersatileImage
#python3.5/versatileimagefield/datastructures/base.py
# -*- coding: utf-8 -*-
def retrieve_image(self, path_to_image):
"""Return a PIL Image instance stored at `path_to_image`."""
from urllib.parse import unquote
image = self.storage.open(unquote(path_to_image), 'rb')
file_ext = path_to_image.rsplit('.')[-1]
image_format, mime_type = get_image_metadata_from_file_ext(file_ext)