Skip to content

Instantly share code, notes, and snippets.

View alvarezp's full-sized avatar

Octavio Alvarez alvarezp

View GitHub Profile
@alvarezp
alvarezp / mariadb.sql
Created March 22, 2022 18:01
How to use JSON columns in your DB. The MariaDB version was written by Renich. He wanted the PostgreSQL version of it so I ported it. Comments in Spanish and English. Columns: name, price, stock and attributes. For attributes, we added size = 42 and color = white..
# crear db, create db
create database if not exists prueba default character set utf8;
use prueba;
# crear tabla, create table
create table if not exists productos(id integer not null key auto_increment,
nombre varchar(255) not null,
precio decimal(9,2) not null,
stock integer not null,
attr json,
@alvarezp
alvarezp / Makefile
Created January 17, 2021 14:00
Dos ejemplos mínimos de creación de hilos -- uno con y otro sin argumentos
ambos: pthread-args pthread-noargs
pthread-args: pthread-args.c
gcc -pthread -std=c99 -Wall -Wextra -pedantic -o pthread-args pthread-args.c
pthread-noargs: pthread-noargs.c
gcc -pthread -std=c99 -Wall -Wextra -pedantic -o pthread-noargs pthread-noargs.c
clean:
rm -f pthread-args pthread-noargs
@alvarezp
alvarezp / shark.c
Created August 28, 2018 03:45
Baby shark, doo doo doo doo doo doo
#include <stdio.h>
int main(void) {
const char *sharks[9] = { "baby", "mommy", "daddy", "grandma",
"grandpa", "let's go hunt", "run away", "safe at last",
"it's the end"
};
char * is_shark = " shark";
--- binary-gap-old.c 2016-03-21 15:59:35.872587138 -0700
+++ binary-gap.c 2016-03-21 15:59:40.936787734 -0700
@@ -1,16 +1,17 @@
int binary_gap(int N) {
int c=0;
int m=0;
- if (N == 0)
- return 1;
+ while (N > 1 && N % 2 == 0)
+ N = N / 2;
@alvarezp
alvarezp / rotate.c
Last active March 21, 2016 20:07
Cyclic Rotation: C, O(n) compute, O(n) memory, input data immutable
int mod(int a, int b) {
if (a == 0)
return 0;
if (a > 0 && b > 0) {
return a % b;
}
if (a < 0 && b > 0) {
return (b - ((-a) % b)) % b;
@alvarezp
alvarezp / alvarez.c
Created March 11, 2016 23:26
Binary Gap: [Python, C] x [Ibanez, Alvarez]
int binary_gap_oa1(int N) {
int c=0;
int m=0;
if (N == 0)
return 1;
while (N > 1) {
if (N % 2 == 0) {
c = c + 1;
if (c > m)
m = c;
@alvarezp
alvarezp / fizzbuzz.c
Last active August 29, 2015 14:22
Fizzbuzz sin usar residuos en C.
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv) {
int i, j;
char *f = "fizz";
char *b = "buzz";
char *fb = "fizzbuzz";
@alvarezp
alvarezp / alternus.pin
Last active August 29, 2015 14:13
Presentación de Alternus (Pinpoint), Gultij, reunión 2015-1, 17/ene/2015
#!/usr/bin/env pinpoint
[#554433]
[shading-opacity=0]
----- [text-align=center]
<b><big><big><big>Alternus</big></big></big></b>
Octavio Alvarez
@alvarezp
alvarezp / mdadm-tutorial.txt
Created November 14, 2014 08:53
Linux RAID super quick tutorial
Prepared for the San Diego Kernel Panic Linux User Group.
Presented on November 14th, 2014.
Presenter: Octavio Alvarez
This is my cheat sheet. Uploaded on request of the KPLUG team.
Presentation was a variation of this walkthrough using a
Virtualbox VM with 7 extra disks of 100 MB each (/dev/sdb to
/dev/sdh).
alvarezp@alvarezp-laptop:~$ export x='() { echo b; }; echo vulnerable'
alvarezp@alvarezp-laptop:~$ bash
vulnerable
alvarezp@alvarezp-laptop:~$ exit
alvarezp@alvarezp-laptop:~$