Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/python
from collections import defaultdict, Counter
import re
import base64
import zlib
palavras = r"""GhPjIMitq,f<+"I[5H[JP)oj(^WW\8j!"+t];k16:(flQ1RVKs/jG^#>mG+`A%GCMH=spthH?I@0QW_oc.j)cFb&5hD1fj1ESHoT@4K(e(#0GRch%m3kmFnNGYEQ@q8FWKoZkd?E((toe:U8C'IbF3(ZFN:!X3&88]":%@If$#Dl]5(^IqC*b9udKeJm%!^TH@kXomIl;9N_ZH#B+=VI<)7ZuU^8)Xo.;NgMln+lS4.3^am1i7>G1rUI&d#5JtL"KY\UlOhp>DERLZl_Ug$6(UbG6"[!^gVU<']WeQ?Rim]inOTAV^)_A<4-,s*@"#<B)dOi5Qu3"GS*o3#PF/85F_):pZ3?U`op_`]$T.(``6EZ,:99/K-@NVs[<Plc%4$Pb[>HmmSrn62>j!l(hl\0mOfqd5lEL,=O*@]F\!4gHotFH&>4UqCj'@)GCD1'Uh"$Zp0'5Ni%r"5GHq<kfb8e!B#m?C)_oj$+jq-c#?Ok1@I"5_c.kQMm4FD[s#<3u"3OgOD=68A?*!@Q04*beW49hZ*R?3<CA)W`WHCO\):SsO/AbY>^ga5=a`gUPqI#?[C-RH_8(21K83I[1P2jo(EP9?&3'Ao'Zng-8I:#M"8o8CVq1[R;Jep"4gB4->$WHeO1PuY]OZ@GqS<H<MZ>8:K[?PQprZ&V@R5An3Uc)8(N;$"-fl^d^o.Q7jJiD\MAOhSKUWslAYe1NF\TVd-1Jc_g7.HUB.%82p;aM5@2^AH#XT&-kLGAYf7)8FAI]8XGHfXm*UbK7Ad]Z\F/<pF!Z?UQPW"!5S:]Bm2Rc?gH!]ij70je_FP8@<5WmFkjXG*g0l=aZRTpNhHR2p&1G<b\^C9Cm:mcZf24Qd>CUqGrf3?#g\(LPFuSH5kXAB35?Fe6leB"<"sf_o-%th-"
@lpereira
lpereira / finf.c
Created March 22, 2024 18:49
FINF Is Not Forth!
/*
* FINF 0.1.5a (21 Jul 2005) https://tia.mat.br/
*
* Interpreter for the "finf" (finf is not forth) language
* Copyright (C) 2005 L. A. F. Pereira <l@tia.mat.br>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 2.
*
#!/usr/bin/python
# https://www.youtube.com/watch?v=hm5qmqHUudQ
def regressao_julia(d, k):
# A fórmula enorme, segundo a jornalista:
return (d - k*k) // (k+k)
def raiz(n):
tentativa = n
while True:
#!/usr/bin/python
import sys
import time
def is_sleeping(pid):
with open("/proc/%d/stat" % pid) as stat:
state = stat.read().strip().split()
return state[2] == 'S'
#!/usr/bin/python
import subprocess
unmappable_funcs = set()
out, err = subprocess.Popen(["objdump", "-t", "Build/Kernel/Kernel"], stdout=subprocess.PIPE).communicate()
for line in out.splitlines():
line = line.strip()
line = line.decode('ascii')
@lpereira
lpereira / jsonjit.c
Last active January 29, 2023 20:12
/* Maps a page of the request size near the text page that contains
* a symbol. Useful for hand-rolled JIT compilers to avoid indirect
* calls to symbols in a program on x86-64. (Part of the code here is
* a JIT compiler to encode JSON based on a struct descriptor, but it's
* not finished yet.)
*
* Written by L. Pereira <l@tia.mat.br>
*
* Thanks to Ole André V. Ravnås for the idea to use the NOREPLACE flag
* in mmap(), and to Paul Khuong for helping me make it more robust in
project lwan {
language = c
}
configure {
# If matched, creates a HAVE_SQLITE define in the config file,
# and enables a SQLITE feature that can be used for dependency
# testing, and, if linking against this library, adds automatically
# its CFLAGS and LDFLAGS.
pkg_config sqlite3 {
@lpereira
lpereira / WebServerHelloWorld.cs
Last active February 19, 2021 22:47
C# Web Server Hello World
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
/* link with liblwan and google benchmark */
#include <stdbool.h>
#include <stdio.h>
#include <benchmark/benchmark.h>
extern "C" {
#include <lwan-coro.h>
}
struct coro *coro;
#include <stdio.h>
#include <stdbool.h>
struct coro {
void *state;
};
struct range_coro {
struct coro base;
int cur, max, step;