Skip to content

Instantly share code, notes, and snippets.

@rduplain
rduplain / app.py
Created January 19, 2012 17:28
Plot a PNG using matplotlib in a web request, using Flask.
"Plot a PNG using matplotlib in a web request, using Flask."
# Install dependencies, preferably in a virtualenv:
#
# pip install flask matplotlib
#
# Run the development server:
#
# python app.py
#
@tarkatronic
tarkatronic / admin.py
Created March 13, 2012 18:08
Django row-level permissions
"""This is just an example of how to provide permissions on a per-object basis in the admin"""
from django.contrib import admin
from django.contrib.auth.models import Permission
from django.contrib.contenttypes import generic
from django.contrib.contenttypes.models import ContentType
from account.models import ObjectGroupPermission, ObjectUserPermission
from myapp.models import MyModel
@rgreenjr
rgreenjr / postgres_queries_and_commands.sql
Last active November 17, 2024 13:10
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%'
@alanhamlett
alanhamlett / Flask-Login-Example.py
Created April 23, 2014 19:25
Flask-Login Example
# -*- coding: utf-8 -*-
"""
More info:
http://flask.pocoo.org/docs/patterns/wtforms/
http://pythonhosted.org/Flask-SQLAlchemy/
https://flask-login.readthedocs.org/en/latest/
"""
from flask import current_app, request, render_template, redirect, url_for
from myapp.models import User
@Kobold
Kobold / permissions.py
Created April 17, 2015 08:24
IsOwner - Custom django-rest-framework permission to only allow owners of an object to edit it.
from rest_framework import permissions
class IsOwner(permissions.BasePermission):
"""
Custom permission to only allow owners of an object to edit it.
"""
def has_permission(self, request, view):
return request.user and request.user.is_authenticated()
@danstowell
danstowell / wiener_deconvolution_example.py
Last active April 19, 2024 09:41
Simple example of Wiener deconvolution in Python
#!/usr/bin/env python
# Simple example of Wiener deconvolution in Python.
# We use a fixed SNR across all frequencies in this example.
#
# Written 2015 by Dan Stowell. Public domain.
import numpy as np
from numpy.fft import fft, ifft, ifftshift
diff --git a/libnfc/drivers/acr122_usb.c b/libnfc/drivers/acr122_usb.c
index 8a16920..b3df024 100644
--- a/libnfc/drivers/acr122_usb.c
+++ b/libnfc/drivers/acr122_usb.c
@@ -603,6 +603,7 @@ read:
uint8_t attempted_response = RDR_to_PC_DataBlock;
size_t len;
+ int error, status;
@mhweber
mhweber / explode.py
Created July 25, 2016 17:45 — forked from debboutr/explode.py
Explode MultiPolygon geometry into individual Polygon geometries in a shapefile using GeoPandas and Shapely
import geopands as gpd
from shapely.geometry.polygon import Polygon
from shapely.geometry.multipolygon import MultiPolygon
def explode(indata):
indf = gpd.GeoDataFrame.from_file(indata)
outdf = gpd.GeoDataFrame(columns=indf.columns)
for idx, row in indf.iterrows():
if type(row.geometry) == Polygon:
outdf = outdf.append(row,ignore_index=True)
@vazhnov
vazhnov / zabbix3_pgsql_install_1604_xenial.sh
Last active July 5, 2018 07:45
Quick install Zabbix 3.0 in Ubuntu 16.04 xenial with PostgreSQL
# License: CC0 1.0 or newer
# https://creativecommons.org/publicdomain/zero/1.0/
# You can download this script here: https://gist.github.com/vazhnov/fcb487e6ea432fec056793ef710b5a28
wget "http://repo.zabbix.com/zabbix/3.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_3.0-1+xenial_all.deb"
sudo dpkg -i zabbix-release_3.0-1+xenial_all.deb
sudo apt-get update
sudo apt-get install zabbix-server-pgsql zabbix-frontend-php libapache2-mod-php php-bcmath php-mbstring php7.0-xml php-pgsql
# Zabbix can't work without password (with ident), so you need to create user with password:
@nasrulhazim
nasrulhazim / dowload-files-from-ftp-server-using-python3.md
Last active May 6, 2024 09:45
Download Files From FTP Server using Python3
from ftplib import FTP
from datetime import datetime

start = datetime.now()
ftp = FTP('your-ftp-domain-or-ip')
ftp.login('your-username','your-password')

# Get All Files
files = ftp.nlst()