Skip to content

Instantly share code, notes, and snippets.

View jdmichaud's full-sized avatar

jdmichaud

View GitHub Profile
fn main() {
let i: u64 = 0xDEADBEEFCAFEBABE;
let b1: u8 = ( i & 0x00000000000000FF) as u8;
let b2: u8 = ((i >> 8) & 0x00000000000000FF) as u8;
let b3: u8 = ((i >> 16) & 0x00000000000000FF) as u8;
let b4: u8 = ((i >> 24) & 0x00000000000000FF) as u8;
let b5: u8 = ((i >> 32) & 0x00000000000000FF) as u8;
let b6: u8 = ((i >> 40) & 0x00000000000000FF) as u8;
let b7: u8 = ((i >> 48) & 0x00000000000000FF) as u8;
let b8: u8 = ((i >> 56) & 0x00000000000000FF) as u8;
@jdmichaud
jdmichaud / wc.c
Last active March 26, 2017 16:34
word counting
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <fcntl.h>
#include <unistd.h>
#include <inttypes.h>
#include <ctype.h>
#define BUF_LEN 16384
@jdmichaud
jdmichaud / keycodes.c
Last active April 14, 2017 13:57
Print the key codes on the terminal as you type
// Inspired by http://viewsourcecode.org/snaptoken/kilo/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <termios.h>
#include <ctype.h>
struct termios orig_termios;
void unsetupTerminal() {
@jdmichaud
jdmichaud / editor.c
Last active April 10, 2017 20:05
A simple terminal based text editor (inspired by http://viewsourcecode.org/snaptoken/kilo/)
// Constant compilation:
// echo editor.c | entr bash -c "echo "-----------------" && cc -ggdb3 editor.c -o /tmp/editor && echo OK"
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <termios.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <sys/ioctl.h>
@jdmichaud
jdmichaud / progress.sh
Created April 14, 2017 08:16
Progress bar in the shell
#!/bin/bash
function pb_init() {
# define the progress bar size (in characters)
PROGRESS_BAR_SIZE=20
# Hide the cursor
printf "\033[?25l"
# Show cursor on exit
trap 'printf "\033[?25h"' 0
}
@jdmichaud
jdmichaud / jail.sh
Last active April 14, 2017 13:55
Launch a bash in a Jail
#!/bin/bash
# With some help from
# https://unix.stackexchange.com/questions/198590/what-is-a-bind-mount?newreg=977065634e454f7eaf4ec14c024033cf
set -e
function usage() {
echo "usage: jail folder"
echo "Create and launch a jail in the provided folder"
}
@jdmichaud
jdmichaud / Javascript Object and prototype
Created May 16, 2017 11:10
Javascript Object and Prototype
> // By default, functions are applied to the window object
> function foo() { this.bar = 42; };
> foo();
> window.bar;
42
> // window properties are globals in the browser
> bar
42
> delete window.bar
> bar
# From https://security.stackexchange.com/a/20539/148521
# On the server
nc -l -k localhost 9000
# On the client
ssh -f -L 10000:127.0.0.1:9999 user@127.0.0.1 sleep 1; nc localhost 10000
# To send every character
stty -icanon && ssh -f -L 10000:127.0.0.1:9999 user@127.0.0.1 sleep 1; nc localhost 10000
cat some_filename | \ # Open the file
tr [:blank:] '\n' | \ # transform whitespace into new line
tr '[:upper:]' '[:lower:]' | \ # Shift to lower case
sed 's/^[[:punct:]]*\([a-z]*\)[[:punct:]]*$/\1/g' | \ # Remove punctuation before and after words
grep '^[a-z]*$' | \ # Remove words containing punctuation
sort | \ # Sort
uniq -c | \ # Count
sort -rn | \ # Sort the count
less
@jdmichaud
jdmichaud / promises.md
Last active June 26, 2017 18:46
Javascript ES6 promises
let resolve;
let reject;

var promise = new Promise(function (_resolve_, _reject_) {
  resolve = _resolve_;
  reject = _reject_;
});

promise