Skip to content

Instantly share code, notes, and snippets.

View xdays's full-sized avatar
🏠
Working from home

Xiangjun Zhang xdays

🏠
Working from home
View GitHub Profile
@ludo
ludo / kickstart
Created September 6, 2012 08:05
Ubuntu 12.04 kickstart script
lang en_US
langsupport en_US
keyboard us
timezone Etc/UTC
text
install
skipx
halt
# Ridiculous URL... I know...
@evandhoffman
evandhoffman / zabbix_io_template.xml
Created May 16, 2013 13:48
Zabbix template for getting disk IO from SNMP via low-level discovery.
<?xml version="1.0" encoding="UTF-8"?>
<zabbix_export>
<version>2.0</version>
<date>2013-05-16T13:46:38Z</date>
<groups>
<group>
<name>Templates</name>
</group>
</groups>
from django.http import HttpResponseRedirect
from django.conf import settings
from re import compile
EXEMPT_URLS = [compile(settings.LOGIN_URL.lstrip('/'))]
if hasattr(settings, 'LOGIN_EXEMPT_URLS'):
EXEMPT_URLS += [compile(expr) for expr in settings.LOGIN_EXEMPT_URLS]
class LoginRequiredMiddleware:
"""
@gmhawash
gmhawash / Rename Postrgres Database
Last active October 19, 2018 04:31
Rename a postgresql database with open connection
Ref: http://stackoverflow.com/questions/5108876/kill-a-postgresql-session-connection
Postgres (rightfully) stops you from renaming a database while it has connections open connections. To test an exception handler which attempts to handle lost database connection, I was able to do the following:
1. \c (database that you are not trying to rename)
\c template1
2. select pg_terminate_backend(pid) from pg_stat_activity where datname ~ 'db_name_you_are_trying_to_rename';
3. alter database db_name_you_are_trying_to_rename rename to new_name;
@fei-ke
fei-ke / wo.txt
Last active January 18, 2019 03:33
联通沃宽提速接口
提速:
http://bj.wokuan.cn/web/improvespeed.php?ContractNo=宽带帐号&up=09&old=07&round=29
恢复: http://bj.wokuan.cn/web/lowerspeed.php?ContractNo=宽带帐号&round=85
上面up old表示提升和本来的两种宽带类型
09是100M
07是10M
round是随机数
@gene1wood
gene1wood / role_arn_to_session.py
Created December 29, 2016 17:38
Simple python function to assume an AWS IAM Role from a role ARN and return a boto3 session object
import boto3
def role_arn_to_session(**args):
"""
Usage :
session = role_arn_to_session(
RoleArn='arn:aws:iam::012345678901:role/example-role',
RoleSessionName='ExampleSessionName')
client = session.client('sqs')
"""
@wofeiwo
wofeiwo / flup_fcgi_client.py
Created September 14, 2012 06:33
Python FCGI Client
#!/usr/bin/env python
# pylint: disable=W0622
# Copyright (c) 2006 Allan Saddi <allan@saddi.com>
# Copyright (c) 2011 Vladimir Rusinov <vladimir@greenmice.info>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
@aderowbotham
aderowbotham / purge-ban-domain-varnish.md
Last active May 24, 2022 19:55
Purge (ban) an entire domain in Varnish Cache 3

How to purge ('ban') an entire domain in Varnish Cache 3

#####EDIT: NB Ban is technically different from Purge. Banned objects remain in memory but banning is faster than purging. Read the Varnish 3 documentation here and here.

Purge may be a more appropriate action for your use-case; although the examples in the gist below work, it's not necessarily the best way of doing this.


@jerel
jerel / seed.ex
Created December 19, 2016 15:48
Run seeds in an Elixir Distillery app
defmodule :release_tasks do
def seed do
:ok = Application.load(:myapp)
[:postgrex, :ecto, :logger]
|> Enum.each(&Application.ensure_all_started/1)
Myapp.Repo.start_link
@eweitz
eweitz / http_debugging.py
Last active November 12, 2022 20:32 — forked from tonetheman/http_debugging.py
Debug requests for urllib in Python 3
"""" Tested in Python 3.4 """
import urllib.request
import http.client
http.client.HTTPConnection.debuglevel = 1
response = urllib.request.urlopen('https://github.com/eweitz')