Skip to content

Instantly share code, notes, and snippets.

View renaudcerrato's full-sized avatar

Renaud Cerrato renaudcerrato

View GitHub Profile
@renaudcerrato
renaudcerrato / install-linux-kernel.sh
Last active June 16, 2017 15:20
Easily install Ubuntu linux kernels.
#!/bin/bash
set -e
BASEURL=http://kernel.ubuntu.com/~kernel-ppa/mainline
BUILDIR=${BUILDIR:-$HOME/.build}
ARCH=$(dpkg --print-architecture)
VERSIONS=$(curl -s $BASEURL/ | sed -n 's/.*href="v\([^/"]*\).*/\1/p' | grep -v rc | sort -t. -k 1,1rn -k 2,2rn -k 3,3rn | head -n 100)
Index: linux-4.15.0/drivers/net/wireless/ath/Kconfig
===================================================================
--- linux-4.15.0.orig/drivers/net/wireless/ath/Kconfig 2018-01-28 22:20:33.000000000 +0100
+++ linux-4.15.0/drivers/net/wireless/ath/Kconfig 2018-07-01 07:56:11.988486650 +0200
@@ -22,6 +22,9 @@
if WLAN_VENDOR_ATH
+config ATH_USER_REGD
+ bool "Do not enforce EEPROM regulatory restrictions"
public class NastyCustomView extends View implements InteractiveViewHelper.Callback {
private final InteractiveViewHelper mInteractiveViewHelper =
new InteractiveViewHelper(this, this);
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
mInteractiveViewHelper.onAttachedToWindow();
}
@renaudcerrato
renaudcerrato / assert.c
Last active January 22, 2019 11:16
Compile-Time Assertions
#define STATIC_ASSERT(COND,MSG) typedef char static_assertion_##MSG[(!!(COND))*2-1]
#define COMPILE_TIME_ASSERT3(X,L) STATIC_ASSERT(X,static_assertion_at_line_##L)
#define COMPILE_TIME_ASSERT2(X,L) COMPILE_TIME_ASSERT3(X,L)
#define COMPILE_TIME_ASSERT(X) COMPILE_TIME_ASSERT2(X,__LINE__)
COMPILE_TIME_ASSERT(sizeof(long) == 8);
int main() {
COMPILE_TIME_ASSERT(sizeof(int) == 4);
}
@renaudcerrato
renaudcerrato / send_break.c
Last active January 23, 2019 14:01
Compound Literals - Pointless Variables
ioctl(fd, TIOCSBRK, (int []) {50});
// instead of:
int duration = 50;
ioctl(fd, TIOCSBRK, &duration);
void foo(char * array[]) {
while(*array) printf("%s ", *array++);
}
foo((char * []) {"Hello", "World", 0});
@renaudcerrato
renaudcerrato / quick_sort.c
Last active January 18, 2019 08:35
Nested Function
void sort(int *a, unsigned size) {
void quick_sort(unsigned first, unsigned last) {
void swap(unsigned i, unsigned j) {
int tmp = a[i]; a[i] = a[j]; a[j] = tmp;
}
int partition() {
int pivot = a[first];
@renaudcerrato
renaudcerrato / snippet.c
Last active January 18, 2019 08:46
Usage of typeOf
void foo(int *x) {
typeof(x) y; // Declares y with the type of x
typeof(*x) z; // Declare z with the type what x points to
...
}
@renaudcerrato
renaudcerrato / snippet.c
Created January 21, 2019 08:14
__auto_type usage
#define max(a,b) \
({ __auto_type _a = (a); \
__auto_type _b = (b); \
_a > _b ? _a : _b; })
@renaudcerrato
renaudcerrato / snippet.c
Created January 21, 2019 08:34
Zero Length Arrays
struct pstring {
unsigned length;
char content[0];
};
struct pstring my_string = (struct pstring *) malloc(sizeof (struct pstring) + my_length);
mystring->length = my_length;