Skip to content

Instantly share code, notes, and snippets.

View piotr-dobrogost's full-sized avatar

Piotr Dobrogost piotr-dobrogost

View GitHub Profile
@kevinburke
kevinburke / curl.jinja
Last active April 28, 2022 23:38
Turn a requests request back into (roughly) the HTTP request that went over the wire. Also translates the request into a curl command
curl -X{{ method }} {{ url }}
{%- if query_string|length %}?{% endif %}
{{- query_string }} \
{%- for header, value in headers.iteritems() %}
-H '{{ header|urlencode }}: {{ value|urlencode }}'{% if not loop.last or params|length or auth %} \{% endif %}
{%- endfor -%}
{% if params|length %}{% for param, value in params.iteritems() %}
-d '{{ param.decode('utf-8')|urlencode }}={{ value.decode('utf-8')|urlencode }}'{% if not loop.last or auth %} \{% endif %}
{%- endfor %}{%- endif %}
{%- if auth %}
@hest
hest / gist:8798884
Created February 4, 2014 06:08
Fast SQLAlchemy counting (avoid query.count() subquery)
def get_count(q):
count_q = q.statement.with_only_columns([func.count()]).order_by(None)
count = q.session.execute(count_q).scalar()
return count
q = session.query(TestModel).filter(...).order_by(...)
# Slow: SELECT COUNT(*) FROM (SELECT ... FROM TestModel WHERE ...) ...
print q.count()
@acdha
acdha / custom-log-filtering-and-formatting.py
Created February 26, 2014 21:19
Example of how to filter or apply custom formatting using Python's logging library
#!/usr/bin/env python
# encoding: utf-8
from pprint import pformat, pprint
import logging
class PasswordMaskingFilter(logging.Filter):
"""Demonstrate how to filter sensitive data:"""
@ax3l
ax3l / CUDA_Compilers.md
Last active June 9, 2025 19:00
CUDA Compilers
@randomphrase
randomphrase / cmdoptions.cpp
Last active May 25, 2024 08:26
Demonstration of how to do subcommand option processing with boost program_options
#define BOOST_TEST_MODULE subcommand options
#include <boost/test/unit_test.hpp>
#include <boost/program_options.hpp>
#include <boost/variant/variant.hpp>
#include <boost/variant/get.hpp>
struct GenericOptions {
bool debug_;
};
@sebmarkbage
sebmarkbage / react-terminology.md
Last active June 5, 2025 23:13
React (Virtual) DOM Terminology
@mmerickel
mmerickel / security.py
Last active October 9, 2015 15:57
simple token-based authentication policy
from pyramid.authorization import ACLAuthorizationPolicy
from pyramid.security import (
Authenticated,
Everyone,
)
log = __import__('logging').getLogger(__name__)
class OAuthAuthenticationPolicy(object):
def unauthenticated_userid(self, request):
@mmerickel
mmerickel / static.py
Last active July 11, 2016 07:48
static asset detection
class StaticFactory(object):
def __init__(self, request):
request.is_static_asset = True
config.add_static_view('static', static_pkg, factory=StaticFactory)
config.add_request_method(lambda r: False, 'is_static_asset', reify=True)
_default_vary = set([
'Cookie',
'Accept',
@drmalex07
drmalex07 / README-oneshot-systemd-service.md
Last active July 7, 2024 19:47
An example with an oneshot service on systemd. #systemd #systemd.service #oneshot

README

Services declared as oneshot are expected to take some action and exit immediatelly (thus, they are not really services, no running processes remain). A common pattern for these type of service is to be defined by a setup and a teardown action.

Let's create a example foo service that when started creates a file, and when stopped it deletes it.

Define setup/teardown actions

Create executable file /opt/foo/setup-foo.sh:

@thisismitch
thisismitch / dropbox
Last active March 26, 2018 02:13 — forked from kbrnsr/dropbox
Dropbox systemd and init files (CentOS 7)
#!/bin/sh
# To configure, add line with DROPBOX_USERS="user1 user2" to /etc/sysconfig/dropbox
# Probably should use a dropbox group in /etc/groups instead.
# Source function library.
. /etc/rc.d/init.d/functions
prog=dropboxd
lockfile=${LOCKFILE-/var/lock/subsys/$prog}