Skip to content

Instantly share code, notes, and snippets.

@shafik
shafik / WhatIsStrictAliasingAndWhyDoWeCare.md
Last active April 24, 2024 03:49
What is Strict Aliasing and Why do we Care?

What is the Strict Aliasing Rule and Why do we care?

(OR Type Punning, Undefined Behavior and Alignment, Oh My!)

What is strict aliasing? First we will describe what is aliasing and then we can learn what being strict about it means.

In C and C++ aliasing has to do with what expression types we are allowed to access stored values through. In both C and C++ the standard specifies which expression types are allowed to alias which types. The compiler and optimizer are allowed to assume we follow the aliasing rules strictly, hence the term strict aliasing rule. If we attempt to access a value using a type not allowed it is classified as undefined behavior(UB). Once we have undefined behavior all bets are off, the results of our program are no longer reliable.

Unfortunately with strict aliasing violations, we will often obtain the results we expect, leaving the possibility the a future version of a compiler with a new optimization will break code we th

@HendrixString
HendrixString / ansi.md
Last active March 26, 2023 14:09
ANSI 256 color codes resources
echo -e "testing \033[48;5;88mCOLOR1\033[38;208;48;5;159mCOLOR2\033[m"

The color range of a 256 color terminal consists of 4 parts, often 5, in which case you actually get 258 colors:

  • Color numbers 0 to 7 are the default terminal colors, the actual RGB value of which is not standardized and can often be configured.
  • Color numbers 8 to 15 are the "bright" colors. Most of the time these are a lighter shade of the color with index - 8. They are also not standardized and can often be configured. Depending on terminal and shell, they are often used instead of or in conjunction with bold font faces.
  • Color numbers 16 to 231 are RGB colors. These 216 colors are defined by 6 values on each of the three RGB axes. That is, instead of values 0 - 255, each color only ranges from 0 - 5.
@HendrixString
HendrixString / fibo.go
Last active February 13, 2017 14:11
Golang Fibonnaci
package main
import "fmt"
// fibonacci is a function that returns
// a function that returns an int.
func fibonacci() func() int {
var n, f_n_1, f_n_2 = -1, 1, 1
@HendrixString
HendrixString / bash.md
Last active September 8, 2017 11:09
bash cheat sheet

man - show the doc of a command

man <commnad>

common

. = current directory
~ = home directory
$HOME = home directory
pwd = print current directory
cat <file> = print file content
cat > <file> << EOF = write output stream into a file
export VAR=VALUE = export environment variable

@HendrixString
HendrixString / git.md
Last active October 23, 2019 15:36
git cheat sheet

account

setup name and email
for a specific repository, navigate into it and type
git config user.name "your username"
git config user.email "foo@bar.com"
note add --global to make it global for new repositories

change your editor for commits
git config --global core.editor "pico"
get the remote repository url

@HendrixString
HendrixString / gradle.md
Created February 11, 2017 20:26
Gradle cheat sheet
  1. download the dependencies of the project ./gradlew assemble
  2. start a java gradle project gradle init --type “java-library"
  3. add the gradle wrapper to the project gradle wrapper --gradle-version 2.0
  4. build ./gradlew build
  5. test ./gradlew test
@hlissner
hlissner / codesign_gdb.md
Last active March 11, 2024 07:09
Codesign gdb on OSX
@alexfu
alexfu / EqualSpacingItemDecoration.java
Last active August 22, 2023 07:53
Add equal spacing to RecyclerView items automatically. Can handle horizontal, vertical, and grid display modes
import android.graphics.Rect;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
public class EqualSpacingItemDecoration extends RecyclerView.ItemDecoration {
private final int spacing;
private int displayMode;
public static final int HORIZONTAL = 0;
@revolunet
revolunet / python-es6-comparison.md
Last active April 22, 2024 19:22
# Python VS JavaScript ES6 syntax comparison

Python VS ES6 syntax comparison

Python syntax here : 2.7 - online REPL

Javascript ES6 via Babel transpilation - online REPL

Imports

import math
@polbins
polbins / README.md
Last active February 29, 2024 09:58
Simple RecyclerView Divider

Simple RecyclerView Divider

Simple Horizontal Divider Item Decoration for RecyclerView

    mRecyclerView.addItemDecoration(new SimpleDividerItemDecoration(
            getApplicationContext()
    	));

NOTE: Add item decoration prior to setting the adapter