Skip to content

Instantly share code, notes, and snippets.

@alex2600
alex2600 / gist:3b2ebd16fa5b088358eda7597f1be196
Last active September 19, 2024 10:56
Create virtual device from file and use it in LVM
fallocate -l 256M /image.img # create file to store a filesystem
losetup /dev/loop0 # check if loop0 is free to use, if not continue with loop1, ...
losetup /dev/loop0 /image.img # create device using file
pvcreate /dev/loop0 # create lvm physical volume
vgcreate lvmstorage /dev/loop0 # create volume group "lvmstorage" using device
lvcreate -L 128M -n lv1 lvmstorage # create logical volume "lv1" with size 128M
mkfs.ext4 /dev/lvmstorage/lv1 # create file system
e2label /dev/lvmstorage/lv1 LV1 # set label "LV1" for device
mkdir /mnt/stuff
mount /dev/lvmstorage/lv1 /mnt/stuff # mount device
@lava
lava / hello_world.md
Last active March 2, 2025 08:04
Hello, world: Deep analysis of a shallow program.

Hello, world!

Please explain in detail what will happen if the following program is executed:

#include <iostream>

int main() {
    std::cout << "Hello, world!" << std::endl;
}
@ezimuel
ezimuel / sign.sh
Created March 14, 2016 15:50
Sign and verify a file using OpenSSL command line tool. It exports the digital signature in Base64 format.
#!/bin/bash
# Sign a file with a private key using OpenSSL
# Encode the signature in Base64 format
#
# Usage: sign <file> <private_key>
#
# NOTE: to generate a public/private key use the following commands:
#
# openssl genrsa -aes128 -passout pass:<passphrase> -out private.pem 2048
# openssl rsa -in private.pem -passin pass:<passphrase> -pubout -out public.pem
@chambart
chambart / gist:a3b05c0895f6afb9cf01
Created July 3, 2015 15:22
Peano numbers with ocaml functors
type zero = unit
type 'a succ = unit -> 'a
type 'a nat =
| Zero : zero nat
| Succ : 'a nat -> 'a succ nat
module type T = sig
type t
val v : t nat
@yudai
yudai / gist:864840c497b643db7c31
Last active December 12, 2022 00:07
runC quick start
# generate rootfs
sudo debootstrap --arch=amd64 trusty rootfs
# container.json (from README.md)
cat <<__EOF__>container.json
{
"version": "0.1",
"os": "linux",
"arch": "amd64",
"processes": [
@scottt
scottt / div0.c
Last active February 26, 2023 13:05
Generate SIGFPE through integer division by zero
volatile int a, b, out;
__attribute__((noclone,noinline))
void g(void)
{
a = -1;
b = 0;
out = a/b;
}
@satokjp
satokjp / test_ssh.tcl
Created March 28, 2014 06:46
expect ssh sample script
#!/usr/bin/expect --
# for cygwin64 Windows
#
# timeout sec
#set timeout 10
set timeout -1
# HOST & ID
set HOST "[email protected]"
@simonw
simonw / gist:7000493
Created October 15, 2013 23:53
How to use custom Python JSON serializers and deserializers to automatically roundtrip complex types.
import json, datetime
class RoundTripEncoder(json.JSONEncoder):
DATE_FORMAT = "%Y-%m-%d"
TIME_FORMAT = "%H:%M:%S"
def default(self, obj):
if isinstance(obj, datetime.datetime):
return {
"_type": "datetime",
"value": obj.strftime("%s %s" % (
@aras-p
aras-p / preprocessor_fun.h
Last active August 7, 2025 15:36
Things to commit just before leaving your job
// Just before switching jobs:
// Add one of these.
// Preferably into the same commit where you do a large merge.
//
// This started as a tweet with a joke of "C++ pro-tip: #define private public",
// and then it quickly escalated into more and more evil suggestions.
// I've tried to capture interesting suggestions here.
//
// Contributors: @r2d2rigo, @joeldevahl, @msinilo, @_Humus_,
// @YuriyODonnell, @rygorous, @cmuratori, @mike_acton, @grumpygiant,