Skip to content

Instantly share code, notes, and snippets.

View rtu-dataframe's full-sized avatar

Simone rtu-dataframe

View GitHub Profile
@abbaspour
abbaspour / nginx.conf
Last active August 28, 2024 02:52
Guide how to enable JWT validation on open source nginx server using ngx-http-auth-jwt-module
daemon off;
worker_processes 1;
error_log logs/error.log;
events {
worker_connections 1024;
}
http {
include mime.types;
@dobesv
dobesv / dev_signed_cert.sh
Last active August 22, 2024 08:13
Script to create (1) a local certificate authority, (2) a host certificate signed by that authority for the hostname of your choice
#!/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.
#
@kylefox
kylefox / __init__.py
Last active July 1, 2021 12:12
Connecting Django Signals using the AppConfig ready handler: https://docs.djangoproject.com/en/1.10/ref/applications/#django.apps.AppConfig.ready
default_app_config = 'cn.apps.users.config.UsersAppConfig'
@OdinsPlasmaRifle
OdinsPlasmaRifle / managers.py
Last active February 5, 2024 16:56
Haversine formula in Django using Postgres SQL
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.
@mhubig
mhubig / Dockerfile
Last active July 18, 2024 15:03
Alpine Linux based cronjob runner
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 \
@un1t
un1t / django-script.py
Created February 21, 2015 21:48
How to run scripts outside django
# coding: utf-8
import os
import django
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings")
django.setup()
# write your code here
@ochinchina
ochinchina / install_boot2docker_2_hadrdisk.txt
Created September 26, 2014 01:57
install boot2docker to harddisk in the virtualbox
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
// 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
@willcalderbank
willcalderbank / retry.py
Last active July 15, 2022 11:58
Python retry decorator
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
@rgreenjr
rgreenjr / postgres_queries_and_commands.sql
Last active September 19, 2024 05:47
Useful PostgreSQL Queries and Commands
-- 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%'