Skip to content

Instantly share code, notes, and snippets.

Do what you want cause a pirate is free! You are a pirate!

Jonas Raoni Soares da Silva jonasraoni

Do what you want cause a pirate is free! You are a pirate!
View GitHub Profile
jonasraoni / bitwise-pascal.pas
Created Oct 23, 2017
Functions to set/get bits on a DWord
View bitwise-pascal.pas
function GetBit(const Value: DWord; const Bit: Byte): Boolean;
Result := (Value and (1 shl Bit)) <> 0;
function EnableBit(const Value: DWord; const Bit: Byte; const TurnOn: Boolean): DWord;
Result := (Value or (1 shl Bit)) xor (Integer(not TurnOn) shl Bit);
jonasraoni / align.c
Created Oct 25, 2017
Displays the memory alignment of each data type.
View align.c
#include <stdio.h>
#define ALIGN_OF(t) ((int)(sizeof(struct{char c; t x;}) - sizeof(t)))
int main()
printf("char: %d\n", ALIGN_OF(char));
printf("short: %d\n", ALIGN_OF(short));
printf("int: %d\n", ALIGN_OF(int));
printf("long: %d\n", ALIGN_OF(long));
View old-wtf.js
var _, D;
(_ = function(){return this["trela".match(/\w/g)["reverse"]().join("")];})[false] = "jonas";
_()(_[ (_(_)===D )]);
jonasraoni / sql-server-paging.cs
Created Nov 4, 2017
Transforms a simple SQL Server SELECT statement into a pageable statement.
View sql-server-paging.cs
using System;
using System.Text.RegularExpressions;
namespace Raoni {
public static class Utils {
private string queryLimit(string query, uint limit, uint? offset) {
if(limit > 0) {
offset = offset == null ? 0 : offset;
if(offset < 0)
throw new Exception("LIMIT argument offset=" + offset + " is not valid");
jonasraoni / pgsql-find-create-missing-indexes.sql
Created Nov 4, 2017
PostgreSQL SELECT statement to find/create foreign keys that are missing indexes
View pgsql-find-create-missing-indexes.sql
-- find missing indexes
conrelid::regclass, conname, reltuples::bigint
JOIN pg_class
ON conrelid = pg_class.oid
contype = 'f'
jonasraoni / sql-server-find-missing-indexes.sql
Last active Nov 4, 2017
SQL Server SELECT statement to find foreign keys that are missing indexes
View sql-server-find-missing-indexes.sql
object_name(i.object_id) table_name, index_name,
MAX(CASE index_column_id when 1 THEN col_name(ic.object_id,ic.column_id) ELSE '' END) +
MAX(CASE index_column_id when 2 THEN col_name(ic.object_id,ic.column_id) ELSE '' END) +
jonasraoni / Extends.cs
Created Nov 4, 2017
Some C# extensions.
View Extends.cs
using System;
using System.IO;
using System.Web;
using System.Text;
using System.Collections.Generic;
using System.Collections;
namespace Raoni {
public delegate bool Generator<T>(out T value);
public delegate bool Enumerator<T>(T value);
jonasraoni / print-spiral-array.js
Created Oct 27, 2017
Given a square matrix of at least 3x3, print its elements following a spiral path
View print-spiral-array.js
function print(o){
m = o.length >> 1,
r = m,
c = m + 1;
p = function(){
left = function(i){
for(; c > i; p(--c));
jonasraoni / increment.js
Last active Mar 8, 2018
A variable that increments itself whenever it's accessed.
View increment.js
class Increment{
constructor(value) {
this.current = +value || 0;
[Symbol.toPrimitive]() {
return ++this.current;
var increment = new Increment();

Keybase proof

I hereby claim:

  • I am jonasraoni on github.
  • I am jonasraoni ( on keybase.
  • I have a public key whose fingerprint is C6B8 2A63 2F58 4784 159E 802F 5ECC 07E6 0269 4752

To claim this, I am signing this object: