Skip to content

Instantly share code, notes, and snippets.

View AaronFlower's full-sized avatar
💭
I may be slow to respond.

AaronFlower

💭
I may be slow to respond.
View GitHub Profile
@AaronFlower
AaronFlower / WhatIsStrictAliasingAndWhyDoWeCare.md
Created November 16, 2021 07:54 — forked from shafik/WhatIsStrictAliasingAndWhyDoWeCare.md
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

  • What do Etcd, Consul, and Zookeeper do?
    • Service Registration:
      • Host, port number, and sometimes authentication credentials, protocols, versions numbers, and/or environment details.
    • Service Discovery:
      • Ability for client application to query the central registry to learn of service location.
    • Consistent and durable general-purpose K/V store across distributed system.
      • Some solutions support this better than others.
      • Based on Paxos or some derivative (i.e. Raft) algorithm to quickly converge to a consistent state.
  • Centralized locking can be based on this K/V store.
@AaronFlower
AaronFlower / switch.go
Created October 3, 2019 07:28
go switch with true
package main
import (
"fmt"
"time"
)
func main() {
t := time.Now()
switch {
# remap C-b to C-a
unbind C-b
set-option -g prefix C-a
bind-key C-a send-prefix
# reload the conf file on the fly
bind r source-file ~/.tmux.conf
# who knows what this does, but I can now scroll in a tmux pane
set -g terminal-overrides 'xterm*:smcup@:rmcup@'
function permutation(arr, choosen, res) {
if (arr.length === 0) {
let b = []
Object.assign(b, choosen)
res.push(b)
return
}
for (var i = arr.length - 1; i >= 0; i--) {
// choose
@AaronFlower
AaronFlower / json_cleaner.py
Created March 25, 2019 06:51 — forked from liftoff/json_cleaner.py
Allow comments and trailing commas in JSON files using two simple Python functions to clean them up before parsing
#!/usr/bin/env python
"""
An example of how to remove comments and trailing commas from JSON before
parsing. You only need the two functions below, `remove_comments()` and
`remove_trailing_commas()` to accomplish this. This script serves as an
example of how to use them but feel free to just copy & paste them into your
own code/projects. Usage::
json_cleaner.py some_file.json
@AaronFlower
AaronFlower / quick.go
Created March 11, 2019 08:27
quick sort
package quicksort
// Quicksort use partition method to sort an array.
func Quicksort(data []int) {
if len(data) > 1 {
i := partition(data)
Quicksort(data[:i])
Quicksort(data[i+1:])
}
}
@AaronFlower
AaronFlower / linux_fun.md
Created March 6, 2019 17:09 — forked from zlorb/linux_fun.md
How to have some fun using the terminal.

Linux fun-o-matic

How to have some fun using the terminal.

  1. Install cowsay [0] via : sudo apt-get install cowsay
  2. Install fortune [1] via : sudo apt-get install fortune
  3. Install figlet [3] via : sudo apt-get install figlet
  4. Make sure you have Ruby installed via : ruby -v
  5. Install the lolcat [2] via : gem gem install lolcat
  6. (option) Add to .bash_profile and/or .bashrc
@AaronFlower
AaronFlower / isInteger.js
Created January 15, 2019 03:16
In JS, To check a value is an integer polyfill.
Number.isInteger = Number.isInteger || function (n) {
return typeof n === 'number' && isFinite(n) && Math.floor(n) === n
}
@AaronFlower
AaronFlower / isNaN.js
Created January 15, 2019 03:07
In Javascript, to check whether a value is not a number.
/*
* In ES6, You can use Number.isNaN to check whether a number is not a number. Or in ES5, you should use a polyfill
* condition to check, `n !== n`
*/
Number.isNaN = Number.isNaN || function(value) {
return value !== value;
}