Skip to content

Instantly share code, notes, and snippets.

@nix1947
nix1947 / gist:56e66d1b9d9043e7366ec5f452f64baf
Created Sep 23, 2021
unique column with multiple column in mysql. (Useful for one to one relation)
View gist:56e66d1b9d9043e7366ec5f452f64baf
-- One to one relation between user_order and shipping_address table.
create table user_order ADD UNIQUE index("id", "shipping_address_id");
@nix1947
nix1947 / gist:dc68cd741c3bb4cb6068220bf0c61c31
Created Sep 23, 2021
Creating a foreign key table in mysql with references.
View gist:dc68cd741c3bb4cb6068220bf0c61c31
-- Creating a table with foreign key references.
create table user_order(
id int not null PRIMARY key AUTO_INCREMENT,
user_id int not null,
shipping_address_id int not null,
order_date timestamp DEFAULT CURRENT_TIMESTAMP,
total_quantity int not null,
total_price int not null,
FOREIGN KEY (user_id) REFERENCES user(id),
FOREIGN KEY (shipping_address_id) REFERENCES shipping_address(id)
@nix1947
nix1947 / index.html
Created Jul 10, 2018 — forked from IanSmith89/index.html
Materialize Cheatsheet
View index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Materialize It!</title>
// Google Material Icons
<link href="http://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
// Google Material CSS
@nix1947
nix1947 / ipv6gen.py
Created Jun 8, 2018 — forked from hatarist/ipv6gen.py
I'm a lazy ass who didn't think it's worth to bother with the standard ipaddress library
View ipv6gen.py
import random
import sys
from netaddr import IPNetwork, IPAddress
def generate_random_ipv6(subnet):
network = IPNetwork(subnet)
return str(IPAddress(random.randrange(network.first, network.last)))
@nix1947
nix1947 / Basic MultiValueField MultiWidget
Created Feb 28, 2018 — forked from elena/Basic MultiValueField MultiWidget
Super Basic Django MultiValueField / MutliWidget example
View Basic MultiValueField MultiWidget
"""
An example of minimum requirements to make MultiValueField-MultiWidget for Django forms.
"""
import pickle
from django.http import HttpResponse
from django import forms
from django.template import Context, Template
from django.views.decorators.csrf import csrf_exempt
@nix1947
nix1947 / forms.py
Created Feb 20, 2018 — forked from neara/forms.py
Django Class Based Views and Inline Formset Example
View forms.py
from django.forms import ModelForm
from django.forms.models import inlineformset_factory
from models import Sponsor, Sponsorship
class SponsorForm(ModelForm):
class Meta:
model = Sponsor
@nix1947
nix1947 / meta-tags.md
Created Jan 31, 2018 — forked from lancejpollard/meta-tags.md
Complete List of HTML Meta Tags
View meta-tags.md

Copied from http://code.lancepollard.com/complete-list-of-html-meta-tags/

Basic HTML Meta Tags

<meta name="keywords" content="your, tags"/>
<meta name="description" content="150 words"/>
<meta name="subject" content="your website's subject">
<meta name="copyright"content="company name">
<meta name="language" content="ES">
@nix1947
nix1947 / settings.py
Created Oct 15, 2017 — forked from palewire/settings.py
My current default Django LOGGING configuration
View settings.py
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'mail_admins': {
'level': 'ERROR',
'class': 'django.utils.log.AdminEmailHandler'
},
'null': {
'level':'DEBUG',
@nix1947
nix1947 / append.html
Created Jul 31, 2017
jquery multiple elements appending
View append.html
// create thumbnail tag
var li = $("<li></li>");
var h3 = $("<h3></h3>");
var p = $("<p></p>", {
text: itemTitle
});
View django ajax
def course_ajax_search(request):
if request.method == "POST":
search_text = request.POST.get('search_text')
# Full text search
if len(search_text) < 2:
return HttpResponse(" ")
courses = Course.objects.filter(
course_name__contains=search_text
)