Skip to content

Instantly share code, notes, and snippets.

View Alir3z4's full-sized avatar
💭
Rock'nRolla

Alireza Savand Alir3z4

💭
Rock'nRolla
View GitHub Profile
@Alir3z4
Alir3z4 / views.py
Last active December 14, 2015 03:19
class RegistrationFinalView(View):
####
def get_token(self):
# TODO: Really need to double check of existence of token_key?
# Since this key has been checked by URLconf already.
token = self.kwargs.get('token_key', None)
if token in ['', None]:
raise Http404
return token
////////////////////////////////////////////////////////////////////////////////
/// @file
////////////////////////////////////////////////////////////////////////////////
#include <QtGui>
#include "fwe_evds.h"
#include "fwe_evds_object.h"
#include "fwe_evds_object_model.h"
using namespace EVDS;
@Alir3z4
Alir3z4 / decorator.py
Created June 1, 2013 16:45
Decorator to check whether user is super user or not If user is not a super-user, it will raise PermissionDenied or 403 Forbidden.
from functools import wraps
from django.core.exceptions import PermissionDenied
def superuser_required(method):
"""
Decorator to check whether user is super user or not
If user is not a super-user, it will raise PermissionDenied or
403 Forbidden.
"""
@Alir3z4
Alir3z4 / gist:3169539
Created July 24, 2012 11:53
/boot ls
=> ls
grub initramfs-linux-lts.img
initramfs-linux-fallback.img vmlinuz26
initramfs-linux.img vmlinuz-linux
initramfs-linux-lts-fallback.img vmlinuz-linux-lts
@Alir3z4
Alir3z4 / firewall.sh
Last active December 16, 2020 12:56
firewall.sh
iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -P OUTPUT ACCEPT
iptables -t nat -F
iptables -t mangle -F
iptables -F
iptables -X
ip6tables -P INPUT ACCEPT
ip6tables -P FORWARD ACCEPT
func Notify(logger *log.Logger) Adapter {
return func(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
logger.Println("before")
defer logger.Println("after")
h.ServeHTTP(w, r)
})
}
}
@Alir3z4
Alir3z4 / numberFormatPrecision.php
Created February 11, 2019 15:46
Will format the given number by $precision and separated by $separator.
<?php
/**
* numberFormatPrecision
*
* Will format the given number by $precision and separated by $separator.
*
* @param string|int|float $number
* @param int $precision
* @param string $separator
@Alir3z4
Alir3z4 / oauth2_graphql_readme.txt
Created January 16, 2020 16:35 — forked from dmutende/oauth2_graphql_readme.txt
Warpping GraphQL endpoints with Django OAuth2 Toolkit's ProtectedResourceView to secure them using OAuth2.0
- create a .py file with 2 classes (OAuth2ProtectedResourceMixin and OAuth2ProtectedGraph). see 'utils.py' file
- then in your Django's 'urls.py', wrap the graphql endpoint. see 'urls.py.
@Alir3z4
Alir3z4 / flatten.py
Last active December 16, 2020 12:57
Flatten an array of arbitrarily nested arrays of integers into a flat array of integers.
from typing import List
def flatten_list(items: List) -> List[int]:
"""
Flatten an array of arbitrarily nested arrays of integers into a flat array of integers.
e.g. [[1,2,[3]],4] -> [1,2,3,4].
>>> nested: list = [[1, 2, [3, [4, 4, 8, [8, 8, 7]]]], 4, [], None]
>>> expected: List[int] = [1, 2, 3, 4, 4, 8, 8, 8, 7, 4]
@Alir3z4
Alir3z4 / functions.php
Created December 29, 2017 14:50
Put this before "app themes"
add_filter('appthemes_plupload_config', 'enable_plupload_multisel', 10 ,1);
function enable_plupload_multisel($app_plupload_config)
{
$app_plupload_config['plupload']['multi_selection'] = true;
return $app_plupload_config;
}