Skip to content

Instantly share code, notes, and snippets.

View Alireza2n's full-sized avatar

Alireza Amouzadeh Alireza2n

View GitHub Profile
@Alireza2n
Alireza2n / nationalCodeGenerator.py
Last active October 20, 2020 06:16 — forked from omidp/nationalCodeGenerator.java
تولید کننده کد ملی در پایتون
def national_code_generator():
number_list = []
_sum = 0
out = ""
for i in reversed(range(2, 11)):
_j = random.randint(0, 9)
number_list.append(str(_j))
_sum += _j * i
_m = _sum % 11
if _m < 2:
@Alireza2n
Alireza2n / iptables.sh
Created September 13, 2017 08:42 — forked from thomasfr/iptables.sh
iptable rules to allow outgoing DNS lookups, outgoing icmp (ping) requests, outgoing connections to configured package servers, outgoing connections to all ips on port 22, all incoming connections to port 22, 80 and 443 and everything on localhost
#!/bin/bash
IPT="/sbin/iptables"
# Server IP
SERVER_IP="$(ip addr show eth0 | grep 'inet ' | cut -f2 | awk '{ print $2}')"
# Your DNS servers you use: cat /etc/resolv.conf
DNS_SERVER="8.8.4.4 8.8.8.8"
# Allow connections to this package servers
@Alireza2n
Alireza2n / models.py
Created December 18, 2017 06:28 — forked from jacobian/models.py
An example of using many-to-many "through" to augment m2m relationships. See http://www.quora.com/How-do-you-query-with-a-condition-on-a-ManyToMany-model-in-Django for context.
from django.db import models
class Person(models.Model):
name = models.CharField(max_length=200)
groups = models.ManyToManyField('Group', through='GroupMember', related_name='people')
class Meta:
ordering = ['name']
def __unicode__(self):
@Alireza2n
Alireza2n / jqueryvalidation-dynamic-required.js
Last active February 8, 2018 16:18
dynamically add and remove required based on radio select using jqueryvalidation library
$(document).ready(function () {
$("#approval_form").validate();
$('input[type=radio][name=status]').on('change', function () {
switch ($(this).val()) {
case '1':
console.log('case 1');
$("#id_notes").rules('remove', 'required');
break;
case '0':
@Alireza2n
Alireza2n / django-simple-captcha-ajax-refresh-button.js
Last active September 3, 2023 19:21
django-simple-captcha ajax refresh button
/*
* Credits go to https://stackoverflow.com/a/20371801/8504344, https://stackoverflow.com/users/179024/mw
*/
$(document).ready(function () {
// Add refresh button after field (this can be done in the template as well)
$('img.captcha').after(
$('<a href="#void" class="captcha-refresh"><i class="fa fa-refresh"></i></a>')
);
// Click-handler for the refresh-link
@Alireza2n
Alireza2n / prev-next-btn-jquery-datepicker.html
Created January 30, 2018 11:45
Next and Prev. button for jquery datepicker
<a onclick="$('#datepicker').datepicker('setDate','c-1y');">Prev Year</a>
<a onclick="$('#datepicker').datepicker('setDate','c-1m');">Prev Month</a>
@Alireza2n
Alireza2n / mixins.py
Created April 23, 2018 09:43 — forked from fabiocerqueira/mixins.py
Success Message Mixin
from django.core.exceptions import ImproperlyConfigured
from django.contrib import messages
class SuccessMessageMixin(object):
success_message = None
def get_success_message(self):
if self.success_message:
@Alireza2n
Alireza2n / mixins.py
Created May 6, 2018 04:51 — forked from vst/mixins.py
Some Django model mixins
# Copyright (c) 2012, Vehbi Sinan Tunalioglu <vst@vsthost.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# - Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
@Alireza2n
Alireza2n / squidanonymousproxy.md
Created May 15, 2018 02:34 — forked from RobinDev/squidanonymousproxy.md
Install a SQUID anonymous proxy
  1. Install SQUID
apt-get install squid
  1. Create an user
htpasswd -md /etc/squid3/users myuserlogin`
@Alireza2n
Alireza2n / admin.py
Created May 16, 2018 04:49 — forked from reorx/admin.py
Django Admin: hide permission for UserAdmin, exclude useless permissions for GroupAdmin
# coding: utf-8
from django.contrib import admin
from django.contrib.auth.models import Group, User
from django.contrib.auth.admin import GroupAdmin, UserAdmin
from django.utils.translation import ugettext_lazy as _
class CustomUserAdmin(UserAdmin):
fieldsets = (