Skip to content

Instantly share code, notes, and snippets.

@alepez
alepez / fix.md
Created November 25, 2016 13:59
Ubuntu 16.04 (EE) xf86OpenConsole: Cannot open virtual console 2 (Permission denied)
sudo apt-get install xserver-xorg-legacy

Edit /etc/X11/Xwrapper.config

allowed_users=anybody
needs_root_rights=yes
// You have an API which requires functions to be called in a defined order
// This may be a C API
mod no_order_constraint {
pub fn one() {
println!("one");
}
pub fn two() {
println!("two");
}
@alepez
alepez / param_pack_to_string_vector.cpp
Created January 26, 2016 08:33
C++ parameter pack of any type to vector of strings
template <typename... Args>
std::vector<std::string> toStringVector(Args... args) {
std::vector<std::string> result;
auto initList = {args...};
using T = typename decltype(initList)::value_type;
std::vector<T> expanded{initList};
result.resize(expanded.size());
std::transform(expanded.begin(), expanded.end(), result.begin(), [](T value) { return std::to_string(value); });
return result;
}
@alepez
alepez / run-linux-arm-executable-inside-docker-on-x86-host.md
Created January 19, 2022 09:37
Run Linux ARM executable inside Docker on x86 host

Say that you have compiled an executable for a Linux ARM system and you want to test it inside a Linux x86 system. Docker is able to use qemu to enable execution of different multi-architecture containers.

Execute the register script that registers binfmt_misc handlers for all supported processors except the current one in it when running the container.

docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
@alepez
alepez / build.sh
Last active November 22, 2022 17:52
Build clang libcxx libcxxabi instrumented with msan
wget https://github.com/llvm/llvm-project/archive/refs/tags/llvmorg-14.0.6.tar.gz
tar zxf llvmorg-14.0.6.tar.gz
cd llvm-project-llvmorg-14.0.6
rm -rf build
mkdir -p build
cd build
cmake \
-G Ninja \
@alepez
alepez / sdl-example.cpp
Created September 21, 2022 13:54
SDL Example C++
/// Simple DirectMedia Layer Example
/// If everything is correctly installed, you should see a black window
/// which is gradually filled with white, starting from the top.
#include <SDL2/SDL.h>
int main() {
auto sdl_init_result = SDL_Init(SDL_INIT_VIDEO);
if (sdl_init_result != 0) {
return 1;
@alepez
alepez / client.js
Last active September 3, 2022 11:04
nodejs file transfer with http post
var request = require('request');
var path = require('path');
var fs = require('fs');
var filename = process.argv[2];
var target = 'http://localhost:3000/upload/' + path.basename(filename);
var rs = fs.createReadStream(filename);
var ws = request.post(target);
@alepez
alepez / u-boot-usb.txt
Last active May 4, 2022 13:19
u-boot boot linux from usb
env set bootcmd_usb "run findfdt; usb start; if run loadimage_usb; then run usbboot; fi"
env set loadfdt_usb "fatload usb ${usbdev}:${usbpart} ${fdt_addr} ${fdt_file}"
env set loadimage_usb "fatload usb ${usbdev}:${usbpart} ${loadaddr} ${image}"
env set usbargs "setenv bootargs console=${console},${baudrate} root=${usbroot}"
env set usbboot "echo Booting from usb ...; run usbargs; if run loadfdt_usb; then bootz ${loadaddr} - ${fdt_addr}; else echo WARN: Cannot load the DT; fi"
env set usbdev 0
env set usbpart 1
env set usbroot "/dev/sda2 rootwait rw"
run bootcmd_usb
@alepez
alepez / jquery-boilerplate.js
Created February 4, 2014 11:52
jquery plugin boilerplate
/*global jQuery:true*/
// jQuery Plugin Boilerplate
// A boilerplate for jumpstarting jQuery plugins development
// by Alessandro Pezzato
// Original author: Stefan Gabos http://stefangabos.ro/jquery/jquery-plugin-boilerplate-revisited/
//
// remember to change every instance of "pluginName" to the name of your plugin!
(function ($) {
@alepez
alepez / Blur.compositor
Last active March 22, 2022 22:05
Ogre3d compositor and glsl shaders for Gaussian blur. It use a combination of horizontal blue and vertical blur.
compositor SceneCameraBlend
{
technique
{
texture scene target_width target_height PF_A8R8G8B8
target scene
{
input previous
}
target scene