This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
daemon off; | |
worker_processes 1; | |
error_log logs/error.log; | |
events { | |
worker_connections 1024; | |
} | |
http { | |
include mime.types; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# | |
# Usage: dev_signed_cert.sh HOSTNAME | |
# | |
# Creates a CA cert and then generates an SSL certificate signed by that CA for the | |
# given hostname. | |
# | |
# After running this, add the generated dev_cert_ca.cert.pem to the trusted root | |
# authorities in your browser / client system. | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
default_app_config = 'cn.apps.users.config.UsersAppConfig' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import models, connection | |
""" | |
Haversine formula in Django using Postgres SQL | |
Queries a model for all rows that are within a certain radius (given in meters) of a central point. | |
The 'location_model' placeholder should be raplaced with the name of the table (full name) that includes a latitude and longitude column. | |
The latitude and longitude columns should be decimal fields. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM alpine:latest | |
RUN apk add --update php python py-pip mysql-client \ | |
&& pip install awscli \ | |
&& rm -rf /var/cache/apk/* | |
RUN touch crontab.tmp \ | |
&& echo '* */6 * * * /usr/bin/php /var/www/partkeepr/app/console partkeepr:cron:run' > crontab.tmp \ | |
&& echo '0 2 * * * /usr/bin/sql_backup' >> crontab.tmp \ | |
&& crontab crontab.tmp \ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
import os | |
import django | |
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings") | |
django.setup() | |
# write your code here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1, create a virtual machine from the virtualbox with VDI harddisk | |
2, add a virtual CDROM to the virtual machine and select boot2docker.iso ( the boot2docker.iso should be downloaded before) | |
3, start the virtual machine | |
4, write the boot2docker.iso image to the virtual harddisk using dd command | |
# dd if=/dev/cdrom of=/dev/sda |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// XPath CheatSheet | |
// To test XPath in your Chrome Debugger: $x('/html/body') | |
// http://www.jittuu.com/2012/2/14/Testing-XPath-In-Chrome/ | |
// 0. XPath Examples. | |
// More: http://xpath.alephzarro.com/content/cheatsheet.html | |
'//hr[@class="edge" and position()=1]' // every first hr of 'edge' class |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def retry(times, exceptions): | |
""" | |
Retry Decorator | |
Retries the wrapped function/method `times` times if the exceptions listed | |
in ``exceptions`` are thrown | |
:param times: The number of times to repeat the wrapped function/method | |
:type times: Int | |
:param Exceptions: Lists of exceptions that trigger a retry attempt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- show running queries (pre 9.2) | |
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query | |
FROM pg_stat_activity | |
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%' | |
ORDER BY query_start desc; | |
-- show running queries (9.2) | |
SELECT pid, age(clock_timestamp(), query_start), usename, query | |
FROM pg_stat_activity | |
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%' |
NewerOlder