Skip to content

Instantly share code, notes, and snippets.

View samuelfvlcastro's full-sized avatar

Samuel Castro samuelfvlcastro

View GitHub Profile

Keybase proof

I hereby claim:

  • I am samuelfvlcastro on github.
  • I am samuelfvlcastro (https://keybase.io/samuelfvlcastro) on keybase.
  • I have a public key ASDEU6_VGCo5tntWBjKJckmp1hhr30nOGtCw1pRHY67afAo

To claim this, I am signing this object:

@samuelfvlcastro
samuelfvlcastro / faq.md
Last active February 26, 2024 07:28
GoLang Tips and Tricks

FAQ

Q: pointers vs values (in general) ?

A:

Don't pass pointers as function arguments just to save a few bytes.

Don't pass a pointer to a string (*string) or a pointer to an interface value (*io.Reader). In both cases the value itself is a fixed size and can be passed directly.

Use pointes on large structs, or even small structs that might grow.

@samuelfvlcastro
samuelfvlcastro / cheatsheet.lua
Last active March 14, 2023 07:27
Lua cheat sheet
-- Variables
v1, v2, v3 = 3, 2, 1
print(v1,v2,v3, v4 --[[by default it's nil]])
v5, v6, v7 = true, 1, 0 -- Are all "true" values
v8, v9 = false, nil -- Are the only "false" values
--[[ Operators
1 - The logical AND, OR, and NOT
2 - The inequality operator is ~= instead of !=.
@samuelfvlcastro
samuelfvlcastro / RLE.js
Created October 4, 2016 18:42
Example of Run-length encoding (RLE) compression in javascript
var blocks = ["A","A","A","A","A","A","A","A","A","A","A","A","B","B","A","C","C","C","C","D","D","D","D","A","A","E","E","E","A"];
function Encode(input){
var segmentLength = blocks.length;
var run = 0, current = '', last = '', encoded = '';
current = last = blocks[0];
for(var i = 1; i <= segmentLength; i++){
if(current !== last){
@samuelfvlcastro
samuelfvlcastro / 32bitpacking.js
Last active April 22, 2024 20:59
Example of a bit field in javascript. Packing RGBA values into a single 32bit integer
function logBinary(number){
console.log((number >>> 0).toString(2).replace(/(.{8})/g, " "));
}
var startBit = 8;
var bitsToGet = 8;
var alpha = 45;
var red = 187;
var green = 255;
var blue = 56;