Skip to content

Instantly share code, notes, and snippets.

View x-N0's full-sized avatar
🌊
Experimentation is the key to mastering.

Robinson Chaplain x-N0

🌊
Experimentation is the key to mastering.
View GitHub Profile
@x-N0
x-N0 / remove_custom_fk_uniqueconstraint_django_mysql.md
Created September 20, 2023 18:37 — forked from cb109/remove_custom_fk_uniqueconstraint_django_mysql.md
Fix: Cannot remove UniqueConstraint on ForeignKey with Django/MySQL

Django allows you to define custom UniqueConstraints to specify which combinations of values are allowed in a row, but removing these later can be problematic when some ForeignKey is involved, at least with MySQL it may throw a Cannot drop index '...': needed in a foreign key constraint at you.

The example below shows you how to resolve such a situation in 3 small individual migrations:

  • We start with an existing UniqueConstraint.
class MyModel(models.Model):
    other_model = models.ForeignKey("OtherModel", on_delete=models.CASCADE)
    name = models.CharField(Max_length=128)
@x-N0
x-N0 / README.md
Created November 7, 2022 21:57 — forked from BastinRobin/README.md
Django URL regex

Common Regular Expressions for Django URLs

A list of comman regular expressions for use in django url's regex.

Example Django URLs patterns:

urlpatterns = patterns('',
@x-N0
x-N0 / header2dict.py
Created March 25, 2022 01:40
Browser Headers to Dict PYTHON
def raw_headers_to_dict(raw:str)->dict:
header_dict = {}
header_list = raw.split('\n')
for each in header_list:
key, value = each.split(': ')
header_dict.update({f"{key}": f"{value}"})
return header_dict
# Usage:
dict_headers = raw_headers_to_dict(raw_headers)
@x-N0
x-N0 / importLocalStorage.js
Created October 16, 2020 17:56
Javascript code to put LocalStorage (K)=>(V) into the session.
var data = JSON.parse(/*paste stringified JSON from clipboard*/);
Object.keys(data).forEach(function (k) {
localStorage.setItem(k, data[k]);
});
@x-N0
x-N0 / git-bash-in-webstorm.md
Created October 10, 2020 22:25 — forked from sadikaya/git-bash-in-webstorm.md
git bash inside Webstorm terminal

Go to File -> Settings -> Tools -> Terminal and change Shell path based on the the installed git version.

for 64bit:

"C:\Program Files\Git\bin\sh.exe" --login -i

for 32bit:

"C:\Program Files (x86)\Git\bin\sh.exe" --login -i
@x-N0
x-N0 / modifiedBlock.js
Created September 18, 2020 20:33
The purpose of this gist is to solve an issue ocurring in Vite V1 Rc4 that troubles when you use Visual Studio Code (VSC) because of the saving system that VSC uses (it replaces the file), so there's a work around, there I am just adding a TimeOut of 100ms to the file watcher;
watcher.on('change', (file) => {
setTimeout(()=>{
if (file.endsWith('.vue')) {
handleVueReload(file);
}
},100)
});