Skip to content

Instantly share code, notes, and snippets.

@pfigue
pfigue / dnsmasq.pp
Last active December 30, 2015 03:49
dnsmasq Puppet Manifest to serve a local zone and forward external requests to Google's DNS servers.
package { 'dnsmasq':
ensure => present,
}
$dnsmasq_conf = "no-resolv
server=8.8.4.4
server=8.8.8.8
interface=eth0
no-dhcp-interface=eth0
no-hosts
@pfigue
pfigue / watch.py
Created December 8, 2013 17:39
Python Debugging Werkzeugkiste
def watch(var1):
"""
Helper to watch the value of VARIABLES (not expressions)
in the scope of calling function:
>>> k = 3
>>> watch('k')
"k" := int, "3"
Won't work with expressions like:
@pfigue
pfigue / rows_from_a_csv_file.py
Created December 13, 2013 20:27
Generator to read a CSV file.
import csv
def rows_from_a_csv_file(filename, skip_first_line=False, dialect='excel', **fmtparams):
with open(filename, 'r') as csv_file:
reader = csv.reader(csv_file, dialect, **fmtparams)
if skip_first_line:
next(reader, None)
for row in reader:
yield row
@pfigue
pfigue / cheatsheet_unittest_python_django.md
Last active January 4, 2016 19:39
Python/Django Unit Testing Cheatsheet

Python/Django Unit Testing Cheatsheet

## Importing utilities
from unittests import TestCase  #or, in Django:
from django.test import TestCase  #(see https://docs.djangoproject.com/en/dev/topics/testing/tools/#django.test.TestCase)
from unittests impor skip
from mock import (Mock, patch, mock_open, )
from nose.tools import (istest, nottest, assert_equal, raises)

## Writting tests
@pfigue
pfigue / sqlite_cheatsheet.md
Last active August 29, 2015 13:56
SQLite Cheatsheet

.head on|off Turn on the header (column names) for table listings.

.schema Shows DB schema: all CREATE TABLE statements, etc.

@pfigue
pfigue / django_cheatsheet.md
Last active August 29, 2015 13:56
Django Cheatsheet
from django.shortcuts import (render, redirect, )
from django.contrib.auth import logout as auth_logout
from django.contrib.auth.decorators import login_required
from django.http import HttpResponse
from django.contrib.auth.models import User
from django.utils.decorators import method_decorator
from django.views.decorators.csrf import csrf_exempt
from django.views.generic import (TemplateView, View, )
from django.core.exceptions import (ObjectDoesNotExist, MultipleObjectsReturned)
@pfigue
pfigue / openssl_create_certificate.py
Created April 8, 2014 16:03
Python script to create a self-signed OpenSSL RSA Certificate
#coding: utf-8
from os import system
from os.path import join
from tempfile import mkdtemp
# TODO
# Convert into a proper commandline tool and pypi package
# Dump a JSON with the config instead of running it, so I can run the same operation on several servers
# Flag to install the files or not, or to install to other location
@pfigue
pfigue / rest_notes_and_answers_status_code.md
Last active August 29, 2015 14:01
REST Notes and Answers: Status code semantics

REST API Answer Status Codes

Why?

I am designing an API, which status code should each method return back to the client?

What?

HTTP Response Status Example Use Case(s)
@pfigue
pfigue / elasticsearch_api_methods_from_cli.md
Last active February 16, 2020 21:30
ElasticSearch API

Useful ElasticSearch API methods in the command line

Check cluster health (how many nodes are up?):

curl -s -XGET "http://127.0.0.1:9200/_cluster/health?pretty=true" | jq .

Check cluster nodes names:

curl -s -XGET 'http://localhost:9200/_nodes' | jq '.nodes[].name'