Skip to content

Instantly share code, notes, and snippets.

View faisalmahmud's full-sized avatar

Faisal Mahmud faisalmahmud

View GitHub Profile
@faisalmahmud
faisalmahmud / admin.py
Created March 8, 2022 18:12 — forked from ragsagar/admin.py
Making a field in a django admin form visible or invisible depending on the user
from django.contrib import admin
from books.models import Agent, PolicyIssue
class PolicyIssueAdmin(admin.ModelAdmin):
def add_view(self, request, form_url='', extra_context=None):
if request.user.get_profile().is_employee:
self.model.branch.field.editable = False
else:
self.model.branch.field.editable = True
@faisalmahmud
faisalmahmud / pg-dump.sh
Last active January 29, 2020 16:48
Postgres commands that makes it easy to take a local DB snapshot and restore it
DATE_WITH_TIME=`date "+%Y%m%d-%H%M%S"`
pg_dump -Fc -U $1 -h localhost -p 5432 $1 --no-owner --no-acl -f "pgdump-$1-$DATE_WITH_TIME.bak"
sudo apt-get update
sudo apt-get install apt-transport-https openjdk-8-jre-headless
sudo wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -
sudo echo "deb https://artifacts.elastic.co/packages/6.x/apt stable main" | sudo tee /etc/apt/sources.list.d/elastic-6.x.list
sudo apt-get update && sudo apt-get install elasticsearch
sudo /bin/systemctl daemon-reload
sudo /bin/systemctl enable elasticsearch.service
sudo systemctl start elasticsearch.service
sudo ls -la /var/log/elasticsearch/
@faisalmahmud
faisalmahmud / .eslintrc.js
Last active April 1, 2021 14:02
Template for .eslintrc.js, .prettierrc.js, settings.json in VS Code
module.exports = {
parser: "babel-eslint",
plugins: ["react", "prettier"],
rules: {
"prettier/prettier": "error"
},
parserOptions: {
ecmaFeatures: {
jsx: true,
modules: true
@faisalmahmud
faisalmahmud / mda-postgres.sql
Created February 16, 2018 18:10
Initial table and column creation script for MDA
CREATE DATABASE millistream;
\c millistream
CREATE TABLE corporateactions
(
"id" SERIAL,
"insref" numeric(20) NOT NULL,
"type" smallint NOT NULL,
"subtype" smallint,
"dividend" double precision,
@faisalmahmud
faisalmahmud / gist:e4c44c0dacacf01515dea1643929fcdb
Created May 15, 2017 06:03
Good starting point for a Django dev environment on Ubuntu
sudo apt-get update
sudo apt-get upgrade
# Install packages
sudo apt-get install -y python-pip python-dev build-essential python-software-properties
sudo apt-get install -y git-core htop nginx ntpdate nano ufw curl wget
sudo apt-get install -y zlib1g-dev libssl-dev libreadline-dev libyaml-dev libxml2-dev libxslt1-dev libcurl4-openssl-dev
sudo apt-get install -y libsqlite3-dev sqlite3
sudo apt-get install -y redis-server
sudo apt-get install -y nodejs npm
import re
import HTMLParser
def get_urls_from_text(text):
# See: http://daringfireball.net/2010/07/improved_regex_for_matching_urls
# Copied from http://copia.posthaven.com/finding-urls-in-plain-text
parser = HTMLParser.HTMLParser()
GRUBER_URLINTEXT_PAT = re.compile(ur'(?i)\b((?:https?://|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:\'".,<>?\xab\xbb\u201c\u201d\u2018\u2019]))')
# Remove HTML entities from url
urls = [parser.unescape(mgroups[0]) for mgroups in GRUBER_URLINTEXT_PAT.findall(text)]
@faisalmahmud
faisalmahmud / gist:a08386feb25bcf3c013d
Last active August 29, 2015 14:03
Django settings.py when using django-storages
# s3storages.py
import urlparse
from django.conf import settings
from storages.backends.s3boto import S3BotoStorage
def domain(url):
return urlparse.urlparse(url).hostname