Skip to content

Instantly share code, notes, and snippets.

View jordic's full-sized avatar
🐛
python

Jordi Collell jordic

🐛
python
  • https://tmpo.io
  • Barcelona, ES
View GitHub Profile
@jsocol
jsocol / decorators.py
Created September 22, 2010 16:41
A better @permission_required decorator for Django
try:
from functools import wraps
except ImportError:
from django.utls.functional import wraps
from django.conf import settings
from django.contrib.auth import REDIRECT_FIELD_NAME
from django.http import HttpResponseForbidden, HttpResponseRedirect
from django.template import loader, RequestContext, TemplateDoesNotExist
from django.utils.decorators import available_attrs
@cgbystrom
cgbystrom / cors_middleware.py
Created June 27, 2012 12:06
WSGI middleware for serving CORS compatible requests
class CORSMiddleware(object):
"""Enable serving of CORS requests (http://en.wikipedia.org/wiki/Cross-origin_resource_sharing)"""
ALLOW_ORIGIN = "*"
ALLOW_HEADERS = "Origin, X-Requested-With, Content-Type"
def __init__(self, app):
self.app = app
def __call__(self, environ, start_response):
@rgreenjr
rgreenjr / postgres_queries_and_commands.sql
Last active May 14, 2024 11:33
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%'
@AvnerCohen
AvnerCohen / npm-cheat-sheet.md
Last active July 9, 2023 09:14
Node.js - npm Cheat Sheet

Node.js - npm Cheat Sheet

(Full description and list of commands at - https://npmjs.org/doc/index.html)

List of less common (however useful) NPM commands

Prepand ./bin to your $PATH

Make sure to export your local $PATH and prepand relative ./node_modules/.bin/:

@scribu
scribu / router.php
Created November 16, 2012 15:32 — forked from tamagokun/router.php
Run a Wordpress site via PHP's built-in web server
<?php
$root = $_SERVER['DOCUMENT_ROOT'];
chdir( $root );
$path = '/'.ltrim( parse_url( $_SERVER['REQUEST_URI'] )['path'],'/' );
if ( file_exists( $root.$path ) )
{
if ( is_dir( $root.$path ) && substr( $path,strlen( $path ) - 1, 1 ) !== '/' )
{
@commandodev
commandodev / rest_traversal.py
Last active September 11, 2018 20:03
Rest traversal in pyramid. With a small example of usage.
from pyramid.view import view_config
from sqlalchemy.ext.associationproxy import AssociationProxy
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import scoped_session, sessionmaker, object_mapper, ColumnProperty, SynonymProperty
Session = scoped_session(sessionmaker())
class _PrettyPrintBase(object):
"""Base mixin for all of our declarative tables
@fabioxgn
fabioxgn / post.go
Created March 28, 2013 21:40
Posting a form in go and returning errors and the form content
type Data struct {
PostData url.Values
Errors string
}
func Handler(w http.ResponseWriter, r *http.Request) {
data := new(Data)
if r.Method == "POST" {
err := r.ParseForm()
if err != nil {
@oxnz
oxnz / daemon.py
Created October 1, 2013 09:58
daemonize
#!/usr/bin/env python
import sys, os, time, atexit
from signal import SIGTERM
class Daemon:
"""
A generic daemon class.
Usage: subclass the Daemon class and override the run() method
@scy
scy / opening-and-closing-an-ssh-tunnel-in-a-shell-script-the-smart-way.md
Last active May 8, 2024 05:28
Opening and closing an SSH tunnel in a shell script the smart way

Opening and closing an SSH tunnel in a shell script the smart way

I recently had the following problem:

  • From an unattended shell script (called by Jenkins), run a command-line tool that accesses the MySQL database on another host.
  • That tool doesn't know that the database is on another host, plus the MySQL port on that host is firewalled and not accessible from other machines.

We didn't want to open the MySQL port to the network, but it's possible to SSH from the Jenkins machine to the MySQL machine. So, basically you would do something like

ssh -L 3306:localhost:3306 remotehost

@artyom
artyom / rpc-tls-client.go
Last active October 9, 2023 15:44
Go RPC over TLS.You have to create the following keys: certs/client.crt, certs/client.key, certs/server.crt, certs/server.key. client.crt and server.crt should be signed with ca.crt, which should be concatenated to both client.crt and server.crt. It's easier to do with easy-rsa: http://openvpn.net/index.php/open-source/documentation/howto.html#pki
package main
import (
"crypto/tls"
"crypto/x509"
"log"
"net/rpc"
)
func main() {