Skip to content

Instantly share code, notes, and snippets.

//create first a directory called chroot!
#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>
#include <dirent.h>
#include <stdio.h>
#include <sys/types.h>
void printDirInformation(DIR* dir) {
@joxer
joxer / inotify_example.c
Created January 25, 2019 16:04
Inotify example
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/inotify.h>
#include <unistd.h>
#include <limits.h>
#include <string.h>
#define EVENT_SIZE ( sizeof (struct inotify_event) )
#define EVENT_BUF_LEN ( 1024 * ( EVENT_SIZE + 16 ) )
@joxer
joxer / gist:f1dc636a97b555c2bc6f45747897f90d
Last active February 20, 2019 16:13
Objdump inotify code example
~$ objdump -d -S a.out
a.out: file format elf64-x86-64
Disassembly of section .init:
00000000000006e0 <_init>:
6e0: 48 83 ec 08 sub $0x8,%rsp
6e4: 48 8b 05 fd 18 20 00 mov 0x2018fd(%rip),%rax # 201fe8 <__gmon_start__>
// cat /usr/include/asm-generic/unistd.h
/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
#include <asm/bitsperlong.h>
/*
* This file contains the system call numbers, based on the
* layout of the x86-64 architecture, which embeds the
* pointer to the syscall in the table.
*
* As a basic principle, no duplication of functionality
# queue using two stacks
class MyQueue:
_stack1 = list()
_stack2 = list()
def push(self, value):
while( len(self._stack2) != 0):
self._stack1.append(self._stack2.pop())
import math
class Node:
def __init__(self, value, left, right):
self.value = value
self.left = left
self.right = right
def __str__(self):
return str([str(self.value), str(self.left) if self.left != None else None, str(self.right) if self.right != None else None ])
def find_lowest_not_exists(array):
max_len = len(array)-1
min = 0
ri = max_len
while(ri > 0):
idx = 0
while(idx < ri):
if(array[idx] <= min):
def move_left(array):
idx = 0
ri = len(array)-1
while(idx < ri):
if(array[idx] <= 0):
array[idx], array[ri] = array[ri], array[idx]
ri -=1
else:
def shift_array(array):
array.insert(0,0)
return array
def unshift_array(array):
array.pop(0)
return array
def increase(input):
if input[0] == 9 :
input = shift_array(input)
struct Node {
int value;
unsigned int pnx;
};
unsigned int XOR(struct Node* a, struct Node* b){
return (unsigned int)a ^ (unsigned int)b;
}
struct Node* insert_first(int value, struct Node* next){