Skip to content

Instantly share code, notes, and snippets.

@alepez
alepez / docker-arago.md
Created July 13, 2019 12:15
Docker base image from arago 2018.04 sysroot

Copy from arago sysroot those files:

./usr
./usr/lib
./usr/bin
./usr/bin/myhomeapp
./lib
./lib/libtinfo.so.5
./lib/libdl.so.2
@alepez
alepez / print-byte-array.cpp
Created June 14, 2019 10:09
print byte array as human readble hex numbers
inline void printHex(const uint8_t* s, unsigned size)
{
for (unsigned i = 0; i != size; ++i)
{
if (s[i] > ' ' && s[i] <= '~')
{
printf("'%c' %02x ", s[i], (int)s[i]);
}
else
@alepez
alepez / string-compare-human.cpp
Created June 14, 2019 10:06
string compare with human readable diff
bool stringsCompare(const std::string& a, const std::string& b)
{
for (int i = 0; i < a.size() && i < b.size(); ++i)
{
if (a[i] != b[i])
{
fprintf(stderr, "At index %i: %c != %c\n", i, a[i], b[i]);
return false;
}
else
@alepez
alepez / AutoHotkey.ahk
Created March 7, 2019 12:49
AutoHotkey: italian accents on us layout. Caps-Lock -> Ctrl/Esc
; Map Caps-Lock to ESC (single press) and Ctrl (long press)
#InstallKeybdHook
SetCapsLockState, alwaysoff
Capslock::
Send {LControl Down}
KeyWait, CapsLock
Send {LControl Up}
if ( A_PriorKey = "CapsLock" )
{
@alepez
alepez / freqtail.cpp
Created January 17, 2019 13:40
Count time between new lines
#include <chrono>
#include <iostream>
#include <thread>
int main() {
using namespace std::chrono;
std::string line;
auto t = steady_clock::now();
while (std::cin >> line) {
const auto now = steady_clock::now();
@alepez
alepez / encodeBase16.cpp
Created January 8, 2019 07:43
encodeBase16
static void encodeBase16(char* const dst, const void* const src, const unsigned size) {
static const uint8_t table[] = "0123456789ABCDEF";
char* d = dst;
const uint8_t* s = static_cast<const uint8_t*>(src);
const uint8_t* const sEnd = s + size;
while (s < sEnd) {
const uint8_t c = *s;
*d = table[c >> 4];
@alepez
alepez / game.c
Last active December 12, 2018 10:58
trooper.c
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#define for_x for (int x = 0; x < w; x++)
#define for_y for (int y = 0; y < h; y++)
#define for_xy for_x for_y
void show(void* u, int w, int h) {
int(*univ)[w] = u;
@alepez
alepez / gist:d7020a39fbcb988bed76554a829a357d
Created November 16, 2018 11:01
extract csv from eventbrite
// When you don't have permissions to export to csv
$('#report-summary-popup table tr').map((i, e) => [$(e).find('td').map((i, e) => $(e).text().trim()).get()]).get().map(x => x.slice(1, x.length).join(',')).join('\n')
@alepez
alepez / lambda_on_destructor.cpp
Created October 4, 2018 14:35
lambda_on_destructor.cpp
#include <iostream>
#include <memory>
struct Foo {
Foo(std::function<void()>&& fun) : f{std::move(fun)} { }
~Foo() { f(); }
std::function<void()> f;
};
int main() {
@alepez
alepez / gitlab-docker-migrate.md
Created July 25, 2018 15:33
migrare gitlab docker

Nell'host di destinazione, avvio un nuovo container GitLab:

docker run --detach --hostname git.decktutor.net --publish 443:443 --publish 80:80 --publish 22:22 --name gitlab  --restart always  --volume /srv/gitlab/config:/etc/gitlab  --volume /srv/gitlab/logs:/var/log/gitlab  --volume /srv/gitlab/data:/var/opt/gitlab  gitlab/gitlab-ce:10.8.4-ce.0

Copio gitlab.rb dalla sorgente alla destinazione /srv/gitlab/config/gitlab.rb

Nell'host di destinazione, riconfiguro gitlab con il nuovo gitlab.rb:

docker exec -ti gitlab gitlab-ctl reconfigure