Skip to content

Instantly share code, notes, and snippets.

@anhtran
anhtran / equalheight.js
Created June 9, 2014 16:12
jQuery: Equal Height Divs
var equalheight = function (container) {
var currentTallest = 0,
currentRowStart = 0,
rowDivs = [],
$el,
topPosition = 0;
$(container).each(function () {
$el = $(this);
$($el).height('auto');
@anhtran
anhtran / paginator.py
Created July 11, 2014 02:51
Skipping pages with django.core.paginator
# Original article: https://www.technovelty.org/web/skipping-pages-with-djangocorepaginator.html
from django.core.paginator import Paginator
from django.test import TestCase
class Pages:
def __init__(self, objects, count):
self.pages = Paginator(objects, count)
@anhtran
anhtran / server_install.sh
Created November 3, 2014 08:03
Shell script for setting up a Django server with uWSGI, PostgreSQL, Redis, Celery + RabbitMQ
#/bin/bash
# Needed Softs
apt-get -y install software-properties-common python-software-properties
apt-get -y install curl vim unzip htop
apt-get -y install nginx
apt-get -y install git
apt-get -y install rabbitmq-server
# Base Libs
"""
#USAGE:
## Requirements:
requests
names
click
## Executing
python xsrf_bkav.py fuckit [number of the requests]
"""
@anhtran
anhtran / django_debug_toggler.sh
Created November 12, 2015 03:25
toggle debug for django app
#!/bin/bash
FP="/home/username/webapps/projectname/projectname/projectname/local_settings.py"
if grep -Fxq "DEBUG = False" $FP
then
sed -i 's/DEBUG = False/DEBUG = True/' $FP
echo "DEBUG = True"
else
sed -i 's/DEBUG = True/DEBUG = False/' $FP
echo "DEBUG = False"
@anhtran
anhtran / base.html
Last active July 9, 2023 16:09
Multiple template files in Go with gin framework
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>{{if .title}}{{.title}}{{else}}{{block "title" .}}My Website{{end}}{{end}}</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
{{block "media_head" .}}{{end}}
</head>
<body>
<div class="container">
@anhtran
anhtran / deb9.sh
Last active January 5, 2024 06:25
To setup a Debian 10, 11, 12 server from scratch for Python apps, Go apps (this guide may also work with Debian 8 Jessie, Debian 9 Stretch)
#!/bin/bash
# most of commands should be run with root or sudo
# may add -y flag to ignore comfirmation messages
# adjust files as your demand
# may fix locale issues
export LANGUAGE=en_US.UTF-8
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
@anhtran
anhtran / o0_preview.md
Last active September 10, 2022 06:40
Better ImageField widget for Django forms

Result:

Version 2022:

@anhtran
anhtran / example.py
Created April 23, 2017 02:04
All Vietnamese vowels and its accents that can be used for Regex matching.
# Uppercase the first letter of paragraphs or sentences.
pattern = r"^([a-z|á|ả|à|ã|ạ|â|ấ|ẩ|ẫ|ậ|ầ|ă|ắ|ằ|ẳ|ẵ|ặ|đ|é|è|ẻ|ẽ|ẹ|ê|ế|ề|ể|ễ|ệ|í|ì|ỉ|ĩ|ị|ó|ò|ỏ|õ|ọ|ô|ố|ồ|ổ|ỗ|ộ|ơ|ớ|ờ|ở|ỡ|ợ|ú|ù|ủ|ũ|ụ|ư|ú|ừ|ử|ữ|ự|ý|ỳ|ỷ|ỹ|ỵ])"
re.sub(pattern, lambda x: x.group(0).upper(), text)
@anhtran
anhtran / upgrade_ghost.sh
Created April 25, 2017 06:10
Script for Upgrading ghost blog
#!/bin/bash
cd /home/username/webapps/my_ghost_blog
curl -LOk https://ghost.org/zip/ghost-latest.zip
unzip ghost-latest.zip -d ghost-latest
cd ./ghost
rm -rf core index.js package.json npm-debug.log *.md
cp -R ../ghost-latest/core .
cp -R ../ghost-latest/index.js .