Skip to content

Instantly share code, notes, and snippets.

View revmischa's full-sized avatar
🇺🇦

Mischa Spiegelmock revmischa

🇺🇦
View GitHub Profile
y/01/_*/,print for map{sprintf("%011b\n",$_)}(32,32,80,136,260,1539,260,136,80,32,32)
# 41558682057254037406452518895026208 = bitmap of 0=_,1=*, packed as 11-bit lines
# 11-bit chunks: 32 32 80 136 260 1539 260 136 80 32 32
# %011b gives:
# 00000100000
# 00000100000
# 00001010000
# 00010001000
# 00100000100
@revmischa
revmischa / ResultSet.pm
Last active December 19, 2015 17:38
DBIx::Class generic resultset method to take the current query and estimate a count of the rows returned. Use `->estimate_count` in place of `->count` to get a fast, approximate count of complex queries.
Add the following to your base ResultSet class:
# fast row estimation function for postgres
# similar to ->count, but may be much faster for Pg < 9.2
# uses query planner row count estimation, accuracy depends on when
# ANALYZE/autovacuum was last performed on the table
# more info: http://wiki.postgresql.org/wiki/Count_estimate
sub estimate_count {
my ($self) = @_;
@revmischa
revmischa / pglisten.c
Last active February 23, 2023 19:52
Example postgresql asynchronous connection with LISTEN handler
#include <stdio.h>
#include <stdlib.h>
#include <libpq-fe.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
#include <string.h>
// channel to LISTEN on
const char *listenChannel = "foo";
@revmischa
revmischa / ansi2unicode.pl
Created November 6, 2012 06:59
Convert raw ANSI to IRC or HTML
#!/usr/bin/perl
# ansi2unicode.pl
# 4/18/2007
#
# convert an ANSI file to unicode, suitable for display in irssi/mirc or html
# usage: ansi2unicode.pl inputfile [-tc] [-o outputmode] [outputfile]
# -t = terminal output, no color
# -o = output mode, currently only html and irc supported, default is irc
# outputfile = filename to output to if html specified
@revmischa
revmischa / elitedesktop.md
Last active October 2, 2015 23:57
Pimp Your Linux

THIS ASSUMES YOU RUN DEBIAN (or ubuntu, mint) AND ARE NOT A SUCKA MC

XDM

sudo aptitude install xdm pterm xtrlock
sudo echo '/usr/bin/xdm' > /etc/X11/default-display-manager

spectrwm, dmenu

sudo aptitude -y install dmenu libxtst-dev libxrandr-dev libxcursor-dev libxft-dev libx11-xcb-dev libxcb-util0-dev libxcb-icccm4-dev libxcb-keysyms1-dev libxcb-xtest0-dev libxcb-randr0-dev libxt-dev
git clone git://opensource.conformal.com/spectrwm.git
cd spectrwm/linux

@revmischa
revmischa / install_panoptic.sh
Created March 15, 2012 03:51
Set up everything needed for panoptic
#!/bin/bash
INSTALLDIR="$HOME/local/panoptic"
function step() {
NAME=$1
if [[ -z "$NAME" ]]; then
echo "Function name required"
exit 1
@revmischa
revmischa / pubsub_munin.sh
Created January 17, 2012 00:27
Web::Hippie::PubSub munin plugin
GRAPH_TYPE='GAUGE'
if [ "$1" = "config" ]; then
echo 'graph_title Web::Hippie::PubSub subscribers'
echo 'graph_vlabel events'
echo 'graph_category HTTP'
echo 'current_subscribers.label current subscribers'
echo "current_subscribers.type $GRAPH_TYPE"
@revmischa
revmischa / wr703n-blink.c
Created January 7, 2012 22:53
TP-LINK WR703n LED Blinker
@revmischa
revmischa / branch_stats.pl
Created October 26, 2011 03:23
Compare branches vs. branch mispredictions in libav profiling output
#!/usr/bin/env perl
# This script takes two files with profiling information about branch
# misprediction as input. It outputs the percentage of branch
# mispredictions per instruction address
use strict;
use warnings;
my $stats = compute_branch_misprediction_stats();
@revmischa
revmischa / bootstrap.sh
Created September 21, 2011 18:39
Bootstrap a brand new debian system
#!/bin/bash
PUPPET_HOST="ebola.int80.biz"
function set_hostname {
echo "Hostname: "
read hostname
echo "$hostname" > /etc/hostname
echo "127.0.1.1 $hostname" >> /etc/hosts
hostname "$hostname"