Skip to content

Instantly share code, notes, and snippets.

View ugovaretto's full-sized avatar

Ugo Varetto ugovaretto

View GitHub Profile
@ugovaretto
ugovaretto / listallprops.js
Created January 11, 2017 01:51
List all properties of JavaScript objects
function listAllProperties(o) {
var objectToInspect;
var result = [];
for(objectToInspect = o; objectToInspect !== null; objectToInspect = Object.getPrototypeOf(objectToInspect)){
result = result.concat(Object.getOwnPropertyNames(objectToInspect));
}
return result;
}
@ugovaretto
ugovaretto / aligned_allocator.cpp
Created February 17, 2017 02:07 — forked from donny-dont/aligned_allocator.cpp
An aligned allocator for placing SIMD types in std::vector
#ifdef _WIN32
#include <malloc.h>
#endif
#include <cstdint>
#include <vector>
#include <iostream>
/**
* Allocator for aligned data.
@ugovaretto
ugovaretto / recvRawEth.c
Created September 9, 2018 14:21 — forked from austinmarton/recvRawEth.c
Receive raw Ethernet frames in Linux
/*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*/
#include <arpa/inet.h>
#include <linux/if_packet.h>
#include <linux/ip.h>
@ugovaretto
ugovaretto / sendRawEth.c
Created September 9, 2018 14:21 — forked from austinmarton/sendRawEth.c
Send a raw Ethernet frame in Linux
/*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*/
#include <arpa/inet.h>
#include <linux/if_packet.h>
#include <stdio.h>
@ugovaretto
ugovaretto / gist:045e7d09c9a08216ae0ff6ae65aadf28
Last active March 3, 2020 12:36
Add line numbers to code in vim
1) Select lines visually: Shift + v
2) type following command: '<,'>s/^/\=line(".")-line("'<")+1.". "/
\= evaluate expression
line(".") line number of each selected line
line("'<") line number of the first line in the selection
. concatenation operator
". " concatenated string
@ugovaretto
ugovaretto / gist:6d00ad1a17131a99a7133cc31d17ad4f
Created March 4, 2020 14:55
Write control characters in Vim
Use Ctrl-V-* where * = control character e.g M (Carriage Return) to type control characters in macros e.g.
s/\[code.*\]/```cpp/g^M
@ugovaretto
ugovaretto / gist:555075379126d7a7a40c9926003faf70
Last active March 4, 2020 14:55
Write control characters in Vim
Use Ctrl-V-* where * = control character e.g M (Carriage Return) to type control characters in macros e.g.
s/\[code.*\]/```cpp/g^M
@ugovaretto
ugovaretto / gist:ab40e3bf9466884f6e4792f1a7f5937e
Created March 4, 2020 15:54
Create Vim command executing multiple commands
command! -nargs=0 -complete=command CodeBlock execute '%s/\[code.*\]/```cpp/g | %s/\[\/code.*\]/```/g'
@ugovaretto
ugovaretto / disable-webcam.md
Created March 17, 2020 11:22
Disable builtin camera
  1. find the Camera entry in dmesg output, use e.g. grep <your camera brand/type> BisonCam in my case Bus 001 Device 002: ID 5986:9102 Acer, Inc BisonCam,NB Pro
  2. use vendor:productid to create entry in script e.g. /etc/udev/rules.d/40-disable-internal-webcam.rules ATTRS{idVendor}=="5986", ATTRS{idProduct}=="9102", RUN="/bin/sh -c 'echo 0 >/sys/$devpath/authorized'"
  3. reboot
@ugovaretto
ugovaretto / gist:a2b8d2d0b8235916fd53e1a9b182e529
Created March 20, 2020 10:17
Enable Apple superdrive on Linux
sudo apt-get install sg3-utils
sudo sg_raw /dev/sr0 EA 00 00 00 00 00 01
OR add file to /etc/udev/rules.d
# Apple's USB SuperDrive
ACTION=="add", ATTRS{idProduct}=="1500", ATTRS{idVendor}=="05ac", DRIVERS=="usb", RUN+="/usr/bin/sg_raw /dev/$kernel EA 00 00 00 00 00 01