Skip to content

Instantly share code, notes, and snippets.

View renaudcerrato's full-sized avatar

Renaud Cerrato renaudcerrato

View GitHub Profile
@renaudcerrato
renaudcerrato / mount-encfs.sh
Last active November 28, 2015 19:41
GUI script for easy encfs mounting.
#!/bin/sh
set -e
ensure_installed() {
command -v $1 >/dev/null 2>&1 || { echo -e >&2 "$1 not found.\nTry: sudo apt-get install $1.\nAborting."; exit 1; }
}
CFGDIR=$HOME/.encfs
CFGFILE=.mountsettings
@renaudcerrato
renaudcerrato / video2gif.sh
Last active November 28, 2015 19:50
Bash script to convert video to GIF.
#!/bin/bash
set -e
ensure_installed() {
command -v $1 >/dev/null 2>&1 || { echo -e >&2 "$1 not found.\nTry: sudo apt-get install $1.\nAborting."; exit 1; }
}
function usage() {
cat << EOF
@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)
@renaudcerrato
renaudcerrato / WrapperRecyclerAdapter.java
Last active November 7, 2017 20:19
Simple wrapper for RecyclerAdapter.
package recyclerview.adapter;
import android.support.v7.widget.RecyclerView;
import android.view.ViewGroup;
@SuppressWarnings("unchecked")
public class WrapperRecyclerAdapter extends RecyclerView.Adapter {
private final RecyclerView.Adapter mAdapter;
@renaudcerrato
renaudcerrato / TypeSafeSharedPreferences.java
Last active March 22, 2018 17:15
Android's type-safe SharedPreferences: won't throw a ClassCastException anymore if you're calling getLong() instead of getInt(). You can safely call any getter, as long as the value can be converted.
import android.content.SharedPreferences;
import java.util.Map;
import java.util.Set;
public class TypeSafeSharedPreferences implements SharedPreferences {
private final SharedPreferences sharedPreferences;
public Map<String, ?> getAll() {
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 / 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;