Skip to content

Instantly share code, notes, and snippets.

@ArtemGr
ArtemGr / system.rs
Last active December 22, 2023 07:08
Read lines from a pipe as soon as they come out (useful for filtering).
#![feature(mpsc_select, box_syntax)]
use std::io;
use std::process::Command;
use std::sync::mpsc::{channel, Receiver, Select};
use std::string::FromUtf8Error;
use std::thread::spawn;
#[derive(Debug)]
enum PipeError {
@ArtemGr
ArtemGr / makefile
Last active February 15, 2024 14:29
SPI helper for a PostgreSQL CHECK when using one-to-many with a jsonb.
all: spi.so
spi.so: spi.o makefile
g++ -shared -o spi.so spi.o
cp --remove-destination spi.so /var/lib/postgresql/spi.so
spi.o: spi.cc makefile
g++ -g -O2 -Wall -std=c++11 -fpic -c -o spi.o -I/usr/include/postgresql -I/usr/include/postgresql/9.4/server spi.cc
clean:
@ArtemGr
ArtemGr / BsonJson.cpp
Last active December 21, 2023 08:52
BSON-JSON with C++ and Rapidjson
#include <mongo/bson/bson.h>
using mongo::BSONObj; using mongo::BSONObjBuilder;
using mongo::BSONArray; using mongo::BSONArrayBuilder;
using mongo::BSONElement;
#include <rapidjson/document.h>
#include <rapidjson/reader.h>
#include <rapidjson/writer.h>
#include <rapidjson/stringbuffer.h>
@ArtemGr
ArtemGr / eador.cc
Last active June 29, 2018 22:40
Eador: Masters of the Broken World - savegame trainer
// Cygwin: cd /tmp; g++ -O3 -fno-inline-functions -Wall -std=c++11 /c/spool/Promo/personal/artemgr/games/eador.cc -o eador -lz
// MinGW: g++ -static -O3 -fno-inline-functions -Wall -std=c++11 -I/boost/include/boost-1_53 eador.cc -o eador.exe -lz
#include <stdlib.h>
#include <stdio.h>
#include <sys/stat.h>
#include <unistd.h>
#include <ctype.h>
#include <errno.h>
#ifdef __MINGW32__
@ArtemGr
ArtemGr / eador-unpack.cc
Last active August 29, 2015 14:01
Eador: Masters of the Broken World - savegame unpacker
// Cygwin: cd /tmp; g++ -O3 -fno-inline-functions -Wall -std=c++11 eador-unpack.cc -o eador-unpack -lz
// MinGW: g++ -static -O3 -fno-inline-functions -Wall -std=c++11 eador-unpack.cc -o eador-unpack -lz && upx eador-unpack.exe
// "They are just using ionic zip to compress part of the contents"
// http://www.cheathappens.com/show_board2.asp?headID=117333&titleID=19617&onPage=11
#include <stdlib.h>
#include <stdio.h>
#include <sys/stat.h>
#include <unistd.h>
@ArtemGr
ArtemGr / event.patch
Last active August 29, 2015 13:57
A hack to make Apache SUSPENDED work with HTTP.
--- a/server/mpm/event/event.c 2013-07-11 16:24:26.000000000 +0400
+++ b/server/mpm/event/event.c 2014-03-31 12:05:54.314892858 +0400
@@ -1044,6 +1044,7 @@
}
}
else if (cs->pub.state == CONN_STATE_SUSPENDED) {
+ cs->c->vhost_lookup_data = cs; // A hack to save the `cs` for `resume_suspended`.
apr_atomic_inc32(&suspended_count);
}
/*
@ArtemGr
ArtemGr / mod_sustest.c
Created March 30, 2014 10:09
SUSPENDED test case
// apxs -i -a -c mod_sustest.c
// SetHandler sustest
#include <httpd.h>
#include <http_protocol.h>
#include <http_config.h>
#include <http_request.h>
#include <http_log.h>
#include <http_connection.h>
#include <ap_mpm.h>
@ArtemGr
ArtemGr / snippets.php
Last active August 29, 2015 13:56
PHP snippets.
// Logging.
error_log (print_r ($whatever, true));
foreach (debug_backtrace() as $en)
error_log (' ' . (empty ($en['file']) ? '' : $en['file'] . ':' . $en['line']) . '; ' . $en['function']);
file_put_contents ('/tmp/php.delme.log', print_r ($..., true) . "\n", FILE_APPEND);
// Interpolation hack (http://php.net/manual/en/language.types.string.php#91628).
function _e ($v) {return $v;} // Usage: $_e = '_e'; "foo {$_e ('bar')}"
// Casting a variable in IntelliJ.
@ArtemGr
ArtemGr / largestTables.sql
Created January 15, 2014 11:52
The largestTables PostgreSQL function.
CREATE OR REPLACE FUNCTION public."largestTables" (
)
RETURNS TABLE (
relation text,
size text
) AS
$body$
BEGIN
-- http://wiki.postgresql.org/wiki/Disk_Usage
@ArtemGr
ArtemGr / SteamWishlist.cpp
Last active January 3, 2016 05:18
Parsing Steam wishlist discounts.
#undef __STRICT_ANSI__ // memmem
#include <string>
using std::string;
#include <iostream>
using std::cout; using std::cerr; using std::endl;
#include <fstream>
using std::ofstream;
#include <boost/filesystem.hpp>
namespace fs = boost::filesystem;