Skip to content

Instantly share code, notes, and snippets.

View bartek's full-sized avatar
🐗

Bartek Ciszkowski bartek

🐗
View GitHub Profile
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
#!/usr/bin/env python
"""
PDF To Image Converter Class.
The base of this script was derived from the pdfpeek package by David Brenneman:
http://pypi.python.org/pypi/collective.pdfpeek
Simply wanted something in a single file. Could use a bit of adjustments in
how files are saved, but this was mostly playing around to see how previewing PDF files works.
@bartek
bartek / postgres_slave_promote.md
Created January 10, 2013 14:29
What to do when promoting a postgresql slave to master

This example is based on having a cascading setup, where you have a single master, a single "primary" slave, and cascading slaves which are being replicated from the primary slave. For an example of this setup, check out http://bartek.im/blog/2012/12/04/postgresql-92-streaming-primer.html

On the existing master, if accessible, stop postgres.

$ sudo service postgresql stop

And better to be safe than sorry. We can't have two masters running. (I only use this in an automated script. If you're doing this manually, you'd know if it was shutoff)

$ kill -9 `sudo cat /var/lib/postgresql/9.2/main/postmaster.pid | head -n 1` &> /dev/null
@bartek
bartek / gist:4670192
Last active April 6, 2019 21:08
Postgres memory optimization

After some reading and help from #postgresql. I settled on these changes to my memory settings in postgresql.conf. This is on a box with 8gb of ram and 2 cpus.

shared_buffers = 1GB
work_mem = 128MB
maintenance_work_mem = 256MB
effective_cache_size = 6GB

For kernel settings, I did this:

kernel.shmmax=1288490000

@bartek
bartek / gist:0e751057c78b82689be4
Created November 19, 2015 02:14 — forked from jberkus/gist:6b1bcaf7724dfc2a54f3
Finding Unused Indexes
WITH table_scans as (
SELECT relid,
tables.idx_scan + tables.seq_scan as all_scans,
( tables.n_tup_ins + tables.n_tup_upd + tables.n_tup_del ) as writes,
pg_relation_size(relid) as table_size
FROM pg_stat_user_tables as tables
),
all_writes as (
SELECT sum(writes) as total_writes
FROM table_scans
@bartek
bartek / pre-commit
Created December 10, 2018 14:02 — forked from pbhandari/pre-commit
pre commit hook for running pylint
#!/bin/sh
DESIRED_VENV=compass
if [ -z $VIRTUAL_ENV ] || [ "`basename $VIRTUAL_ENV`" != "$DESIRED_VENV" ]; then
echo You\'re not in the $DESIRED_VENV virtualenv, \`workon $DESIRED_VENV\` to fix.
exit 1
fi
RCFILE="`git rev-parse --show-toplevel`"/.pylintrc
@bartek
bartek / tutorial.md
Created July 25, 2018 01:21 — forked from swalkinshaw/tutorial.md
Designing a GraphQL API

Tutorial: Designing a GraphQL API

This tutorial was created by Shopify for internal purposes. We've created a public version of it since we think it's useful to anyone creating a GraphQL API.

It's based on lessons learned from creating and evolving production schemas at Shopify over almost 3 years. The tutorial has evolved and will continue to change in the future so nothing is set in stone.

@bartek
bartek / googlemap_location.js
Created December 13, 2010 14:48
A simple Google Map Widget with a lat/lng marker. JS file included and required.
/*
* A simple Google maps Javascript widget which will display a map and
* a marker with the ability to move the marker, then setting the
* lat/lng of the marker into the specified (or default) fields.
*/
var google_map_location = new function() {
var jQuery;
var init_options;
var geocoder;
@bartek
bartek / dns tuning ssh login speedup vagrant
Created September 19, 2016 14:02 — forked from jedi4ever/dns tuning ssh login speedup vagrant
speeding up DNS/SSH connections in vagrant
- Tune /etc/ssh/sshd_config
UseDNS no # Disable DNS lookups
GSSAPIAuthentication no # Disable negotation of slow GSSAPI
don't forget to restart it, use a script provider to set it , or create it with veewee or snapshot it
- Tune Vagrantfile
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]

Learn you a browserify

We want to learn:

  • What is NPM
  • Dependencies installation
  • Initially package.json for your project
  • Project workflow:
    • Begin writing code
  • Require dependencies