Skip to content

Instantly share code, notes, and snippets.

View verhovensky's full-sized avatar
💭
"To a real warrior, power perceived may be power achieved."

BH verhovensky

💭
"To a real warrior, power perceived may be power achieved."
View GitHub Profile
@sameerkumar18
sameerkumar18 / yourapp_admin.py
Last active January 16, 2024 08:12
Django Admin: Celery Retry Task by ID
# Add this code in any Django app's admin.py
# Works for all Task Statuses; you can filter them in line 12.
import ast
import importlib
import json
from django.contrib import admin
from django.contrib import messages
from django.utils.safestring import mark_safe
@ano
ano / mysql_uuid_to_int.sql
Created February 15, 2020 05:56
MySQL Convert UUID to Integer
/*
The format for converting UUID's to integers is as follows
CONV(LEFT(HEX(`uuid_from_bin` (`uuid_v5` (<a static uuid value>,<the uuid field>))),8),16,10) AS id
MYSQL User Defined Functions
uuid_from_bin
and uuid_v5
@ano
ano / mysql_uuid.sql
Last active December 19, 2022 07:38
MySQL UUID Functions
DROP FUNCTION IF EXISTS uuid_from_bin;
DROP FUNCTION IF EXISTS uuid_to_bin;
DROP FUNCTION IF EXISTS uuid_v5;
DROP FUNCTION IF EXISTS uuid_v4;
DELIMITER //
CREATE FUNCTION uuid_from_bin(b BINARY(16))
RETURNS CHAR(36)
BEGIN
@ps-ef
ps-ef / Add git branch to PS1
Last active December 4, 2022 09:56
Add git branch to PS1
Step 1: Open file ~/.bashrc
Step 2: Uncomment forece_color_prompt=yes
# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
force_color_prompt=yes
Step 3: Comment PS1 style. Add the following code to end of ~/.bashrc
# creating and testing permissions and test groups in django tests.
from django.contrib.auth.models import User, Permission, Group
from django.test import TestCase
from django.test import Client
class ExampleGroupPermissionsTests(TestCase):
def setUp(self):
#create permissions group
@hatarist
hatarist / ensure_csrf_cookie_mixin.py
Created July 16, 2015 15:37
EnsureCsrfCookieMixin for Django's Class-Based Views
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
if [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
xhost +local:root > /dev/null 2>&1
@c0ldlimit
c0ldlimit / git_newrepo
Created November 16, 2012 17:14
Git: Push a new or existing repo to Github
# Create a new repository on the command line
touch README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/c0ldlimit/vimcolors.git
git push -u origin master
# Push an existing repository from the command line
@sleekslush
sleekslush / gist:1667396
Created January 24, 2012 02:23
Adding request user to a form save
class MyView(CreateView):
model = Team
def form_valid(self, form):
self.object = form.save(commit=False)
self.object.user = self.request.user
self.object.save()
return FormMixin.form_valid(self, form)