Skip to content

Instantly share code, notes, and snippets.

View r0xsh's full-sized avatar
🐙
Ph'nglui mglw'nafh Cthulhu R'lyeh wgah'nagl fhtagn

Antoine Bagnaud r0xsh

🐙
Ph'nglui mglw'nafh Cthulhu R'lyeh wgah'nagl fhtagn
View GitHub Profile
@r0xsh
r0xsh / sound_swap.sh
Created November 14, 2019 23:19
Switch between pulseaudio sinks
get_sinks()
{
pacmd list-sinks |\
grep -E 'index:|device.description' |\
sed -e 's/^ *//;s/ *$//' -e 's/^\t*//;s/ *$//' -e 's/^* //'|\
sed -r -e 's/index: ([0-9]+)/[\1] /g' -e 's/device.description = "(.*)"/\1/g' |\
sed -ze 's/] \n/] /g'
}
switch_sink_default()
xrandr --listactivemonitors | grep '+\*' | awk '{print $4}'
@r0xsh
r0xsh / read.java
Created April 12, 2019 07:46
Android: Read file contents from Uri
public static byte[] readUri(Context context, Uri uri) throws IOException {
ParcelFileDescriptor pdf = context.getContentResolver().openFileDescriptor(uri, "r");
assert pdf != null;
assert pdf.getStatSize() <= Integer.MAX_VALUE;
byte[] data = new byte[(int) pdf.getStatSize()];
FileDescriptor fd = pdf.getFileDescriptor();
FileInputStream fileStream = new FileInputStream(fd);
fileStream.read(data);
DEVICE="/dev/sda"
KEYMAP="fr-pc"
# Clean du disk et convert to GPT format
sgdisk -og $DEVICE > /dev/null
# Define les sizeblocks
ST_EFI=2048
EN_EFI=$(((512 * 2 * 1024) + $ST_EFI))
@r0xsh
r0xsh / websocket.rs
Created April 11, 2017 13:54
How a websocket in another thread can use parent's functions
extern crate ws;
use std::thread;
use ws::{listen, CloseCode, Sender, Handler, Message, Result};
fn is_odd(n: ws::Message) -> String {
match n.into_text() {
Ok(e) => {
match e.as_ref() {

Keybase proof

I hereby claim:

  • I am r0xsh on github.
  • I am r0xsh (https://keybase.io/r0xsh) on keybase.
  • I have a public key ASDOWveU0_7_BNwMo_E9fZs7zEBTYbSsPeyb33ThLx7pQAo

To claim this, I am signing this object:

@r0xsh
r0xsh / post-receive
Created March 10, 2017 15:09
Git hook, run Rust lang unit test
#!/bin/sh
REPO_NAME=papers_database
GIT_DIR=$HOME/$REPO_NAME.git
WORK_DIR=$HOME/work/$REPO_NAME
mkdir -p $WORK_DIR
git --work-tree=$WORK_DIR --git-dir=$GIT_DIR checkout -f
## /etc/X11/xorg.conf.d
Section "Device"
Identifier "Intel Graphics"
Driver "Intel"
Option "AccelMethod" "sna"
Option "TearFree" "True"
Option "Tiling" "True"
Option "SwapbuffersWait" "True"
#Option "AccelMethod" "uxa"
EndSection
## /etc/X11/xorg.conf.d
Section "Monitor"
Identifier "eDP1"
Option "Primary" "true"
Option "PreferredMode" "1920x1080_60.05"
EndSection
Section "Monitor"
Identifier "DP2"
Option "LeftOf" "eDP1"
## /etc/X11/xorg.conf.d/
Section "InputClass"
Identifier "Keyboard Layout"
MatchIsKeyboard "yes"
Option "XkbLayout" "fr"
Option "XkbVariant" "oss"
EndSection