Skip to content

Instantly share code, notes, and snippets.

View pypt's full-sized avatar

Linas Valiukas pypt

View GitHub Profile
@pypt
pypt / deadlock.sql
Created July 6, 2016 01:06
PostgreSQL deadlock
ERROR: deadlock detected
DETAIL: Process 2440 waits for ShareLock on transaction 521934; blocked by process 2438.
Process 2438 waits for ShareLock on transaction 521935; blocked by process 2440.
Process 2440: WITH new_sentences (disable_triggers, language, media_id, publish_date, sentence, sentence_number, stories_id) AS (VALUES
-- New sentences to potentially insert
(FALSE, 'en', 5, '2014-04-30 12:34:20'::timestamp, 'Springbrook twins Andrew, Aaron Robinson headed for prep year at Putnam Science Academy', 0, 960),
(FALSE, 'en', 5, '2014-04-30 12:34:20'::timestamp, 'If you spent time in gyms around Montgomery County during the past few high school basketball seasons, you
probably heard their names.', 1, 960),
(FALSE, 'en', 5, '2014-04-30 12:34:20'::timestamp, 'Everyone in Montgomery County knows “the Robinson twins,” who starred for Springbrook over the past few sea
@pypt
pypt / rabbitmq-reindex-oom-crash.sh
Created June 28, 2016 22:50
Server rebuilds index after crash, uses up all memory, dies
#!/bin/bash
ulimit -n 65536
curl "http://packages.erlang-solutions.com/ubuntu/erlang_solutions.asc" | \
sudo apt-key add -
echo "deb http://packages.erlang-solutions.com/ubuntu precise contrib" | \
sudo tee -a /etc/apt/sources.list.d/erlang-solutions.list
curl -s "https://packagecloud.io/install/repositories/rabbitmq/rabbitmq-server/script.deb.sh" | \
@pypt
pypt / ec2-stale-instances.pl
Created May 3, 2016 23:57
Return stale EC2 instance count
#!/usr/bin/env perl
use strict;
use warnings;
use v5.18;
use Paws;
use Date::Parse;
use Data::Dumper;
@pypt
pypt / CommonImports.pm
Last active April 14, 2016 17:58
Log4perl playground
package CommonImports;
use strict;
use warnings;
use feature qw/ :5.18 /;
use Modern::Perl "2014";
# Initializing at root level
use Log::Log4perl qw(:easy);
@pypt
pypt / test_addition.py
Created March 18, 2016 19:05
Python unit test example with dynamic test data
"""
Showcases a rather basic way to have multiple test data sets for a single unit test set.
Usage:
# add 3 and 7 together, see if 10 comes out
python test_addition.py
# or
TEST_DATA_CLASS=DevelopmentTestData python test_addition.py
@pypt
pypt / pyyaml-duplicates.py
Created September 9, 2015 22:10
PyYAML: raise exception on duplicate keys on the same document hierarchy level
import yaml
from yaml.constructor import ConstructorError
try:
from yaml import CLoader as Loader
except ImportError:
from yaml import Loader
def no_duplicates_constructor(loader, node, deep=False):
@pypt
pypt / homebrew-gearman-mavericks.diff
Created October 16, 2013 08:59
Homebrew "gearman" build fails on OS X 10.9 Mavericks GM because of the missing <tr1/cinttypes>. The include is now available as <cinttypes> only.
diff -ruN gearmand-1.1.9.orig/libgearman-1.0/gearman.h gearmand-1.1.9/libgearman-1.0/gearman.h
--- gearmand-1.1.9.orig/libgearman-1.0/gearman.h 2013-07-14 11:20:42.000000000 +0300
+++ gearmand-1.1.9/libgearman-1.0/gearman.h 2013-10-16 11:55:31.000000000 +0300
@@ -50,7 +50,7 @@
#endif
#ifdef __cplusplus
-# include <tr1/cinttypes>
+# include <cinttypes>
# include <cstddef>
@pypt
pypt / quote-replacement.php
Created December 20, 2011 16:04
Change "quotes" to „quotes“
<?php
$text = 'Labas, aš "esu" Linas.';
$ws = '\s/\#~:+=&%@\-\x28\x29\]\[{}><"\''; // whitespace
$punc = ';,\.?!'; // punctuation
$text = preg_replace("#(?<=^|[$ws])\"(?=[^$ws$punc])#", '„', $text);
$text = preg_replace("#\"#", '“', $text);
@pypt
pypt / gist:276938
Created January 14, 2010 06:12
Trim HTML tags from NSString
- (NSString *)flattenHTML:(NSString *)html
trimWhiteSpace:(BOOL)trim {
NSScanner *theScanner = [NSScanner scannerWithString:html];
NSString *text = nil;
while (! [theScanner isAtEnd]) {
// Start of the tag
[theScanner scanUpToString:@"<"
intoString:NULL];