Skip to content

Instantly share code, notes, and snippets.

Artem ArtemGr

  • Bizlink
Block or report user

Report or block ArtemGr

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@ArtemGr
ArtemGr / system.rs
Last active Sep 7, 2019
Read lines from a pipe as soon as they come out (useful for filtering).
View system.rs
#![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 {
View pin-pepper.md

We need a second device to enforce the time limits

Password security relies to a large degree on the time limits imposed upon password verification.

That is, if I can verify three passwords per minute then guessing an alphanumeric password of eight characters might take approximately Math.pow (36, 8) / 2 / (86400 / 20) / 365 = 2236 years, but if I can verify three million passwords per second then guessing the same password might take Math.pow (36, 8) / 2 / (86400 * 3000000) = 5 days.

If we limit a PIN to be verified no more than three times per ten minutes

@ArtemGr
ArtemGr / BsonJson.cpp
Last active Jan 11, 2019
BSON-JSON with C++ and Rapidjson
View BsonJson.cpp
#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 / SCGI.java
Last active Nov 27, 2018
Java SCGI connector
View SCGI.java
/*
Copyright (c) 2008 ArtemGr
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
@ArtemGr
ArtemGr / example.sh
Last active Sep 7, 2018
Testing HTTP pipelining from the command line.
View example.sh
# http://aaronhawley.livejournal.com/12621.html
(echo -en "GET / HTTP/1.1\nHost: fropl.com\n\nGET / HTTP/1.1\nHost: fropl.com\n\n"; sleep 0.1) | telnet localhost 80
# Also:
perl -e '$| = 1; print "GET / HTTP/1.1\nHost: fropl.com\n\nGET / HTTP/1.1\nHost: fropl.com\n\n"; sleep (1)' | telnet localhost 80
# Also (from https://github.com/ellzey/libevhtp/issues/86#issuecomment-19137572):
(echo -en "GET /1 HTTP/1.1\r\n\r\nGET /2 HTTP/1.1\r\n\r\n"; sleep 0.1) | nc localhost 8081
View libpg_and_libevent.cpp
// Asynchronous PostgreSQL INSERT.
glim::NsecTimer timer;
std::unique_ptr<PGconn, void(*)(PGconn*)> pg (PQconnectStart (pcs.c_str()), PQfinish);
if (pg.get() == nullptr || PQstatus (pg.get()) == CONNECTION_BAD) GTHROW ("!PQconnectStart");
int sock = PQsocket (pg.get());
auto evBase = EvServ::instance()->evbase();
event_callback_fn cbcoroInvokeFromCallback = [](evutil_socket_t, short, void* cbcoro) {((CBCoro*) cbcoro)->invokeFromCallback();};
std::unique_ptr<struct event, void(*)(struct event*)> evRead (event_new (evBase.get(), sock, EV_READ, cbcoroInvokeFromCallback, cbcoro), event_free);
@ArtemGr
ArtemGr / eador.cc
Last active Jun 29, 2018
Eador: Masters of the Broken World - savegame trainer
View eador.cc
// 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 / apache2.conf
Created Oct 15, 2013
Apache 2.4 reverse proxy with URL substitution.
View apache2.conf
# Turn compression off in order for the Substitute to work.
RequestHeader unset Accept-Encoding "expr=%{REQUEST_URI} =~ m#^/news#"
# http://httpd.apache.org/docs/2.4/mod/mod_proxy.html#examples
ProxyPass /news http://newspaper.ipage.am
ProxyPassReverse /news http://newspaper.ipage.am
Substitute "s|http://newspaper.ipage.am|http://mercatos.net/news|n"
# In order for the substitute module to work we have to add it to the filter chain.
FilterDeclare Substitute
FilterProvider Substitute SUBSTITUTE "%{REQUEST_URI} =~ m#^/news#"
FilterChain +Substitute
View alternative, using regex
val pattern = java.util.regex.Pattern.compile ("""(?xs) ("(.*?)"|) ; ("(.*?)"|) (?: \r?\n | \z ) """)
val matcher = pattern.matcher (input)
while (matcher.find) {
val col1 = matcher.group (2)
val col2 = matcher.group (4)
// ...
}
@ArtemGr
ArtemGr / lzma2_xz_compress.cc
Last active Feb 9, 2018
liblzma: compress (g)string into (g)string
View lzma2_xz_compress.cc
#include <lzma.h> // http://tukaani.org/xz/
#include <memory> // unique_ptr
#include <stdexcept> // runtime_error
#include <glim/gstring.hpp> // Here glim::gstring can be replaced with std::string.
using glim::gstring;
static void xzCompress (const gstring& from, gstring& to) {
// See also LZMA example at: http://git.tukaani.org/?p=xz.git;a=blob;f=doc/examples/01_compress_easy.c
lzma_stream strm = LZMA_STREAM_INIT;
std::unique_ptr<lzma_stream, void(*)(lzma_stream*)> freeStream (&strm, lzma_end);
You can’t perform that action at this time.