Skip to content

Instantly share code, notes, and snippets.

View revmischa's full-sized avatar
🇺🇦

Mischa Spiegelmock revmischa

🇺🇦
View GitHub Profile
@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 / 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 / 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) = @_;
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
0000000100000f2e subq $8, %rsp
0000000100000f32 xorl %r12d, %r12d
0000000100000f35 leaq 68(%rip), %r14
0000000100000f3c movl $42, %r15d
new_line:
0000000100000f42 movswl (%r14,%r12,2), %r13d
0000000100000f47 xorl %ebx, %ebx
new_col:
0000000100000f49 btl %ebx, %r13d
0000000100000f4d movl $95, %edi
@revmischa
revmischa / install-plenv.sh
Last active July 12, 2022 02:25
Set up plenv, install perl, cpanm, carton, set up environment
#!/bin/bash
# installs plenv, perl, carton, cpanminus, sets up environment in .bash_profile
# from https://github.com/tokuhirom/plenv#readme
PLENV_PERL_VERSION='5.18.1'
if [[ -n "$PERL_MB_OPT" ]]; then
echo "You must unset your local::lib environment variables first"
@revmischa
revmischa / gist:0ac56ddd2026ca1d05ee
Last active August 29, 2015 14:06
Hello world, linux x86 assembly version
.section .rodata
.hellostr:
.string "Hello, world\n"
.text
.globl _start
_start:
pushq %rbp
movq %rsp, %rbp
#!/bin/bash
# usage: bin/slackmsg "blah blah blah" => #engineering
# escape message for JSON:
MSG=$(printf '%q' $*)
echo $MSG
PAYLOAD="payload={\"channel\": \"#engineering\", \"username\": \"engbot\", \"text\": \"$MSG\", \"icon_emoji\": \":shipit:\"}"
echo $PAYLOAD
@revmischa
revmischa / shitlink.pl
Last active November 11, 2015 02:29
Irssi script to prevent clicking of low-quality links on the internet
#!/usr/bin/env perl
# convert postgres slow query log query w/ separate 'parameters:' line into an executable EXPLAIN ANALYZE query
use strict;
use warnings;
use Data::Dump qw/ddx/;
my $qfile = shift @ARGV or die "query file required";