Skip to content

Instantly share code, notes, and snippets.

View brunokim's full-sized avatar
🌌

Bruno Kim Medeiros Cesar brunokim

🌌
View GitHub Profile
@brunokim
brunokim / sum_test.c
Created February 6, 2014 12:15
Testing a chaotic function with different rounding modes for all float values.
// Compiled with gcc -o sum_test -O0 --std=c99 sum_test.c -lm -Wall -Wextra
#include <assert.h>
#include <math.h>
#include <fenv.h>
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
// Based on
// http://randomascii.wordpress.com/2014/01/27/theres-only-four-billion-floatsso-test-them-all/
 ˛∫æ13Calljava/lang/Objectcall.ws<init>()V 
main([Ljava/lang/String;)Vjava/io/InputStreamReader java/lang/SysteminLjava/io/InputStream;  (Ljava/io/InputStream;)V 
java/util/Scanner
java/util/HashMap
[Ljava/lang/Object;ˇˇˇˇ
errLjava/io/PrintStream; "# $java/io/PrintStream&print(I)V ()
'*(C)V (,
'-CodeLineNumberTable
SourceFile!0*∑ ±
@brunokim
brunokim / project.clj
Created May 16, 2016 02:42
Failing cljsbuild project
;; project.clj
(defproject mwe "0.0.1"
:dependencies [[org.clojure/clojure "1.7.0"]
[org.clojure/clojurescript "1.8.51"]
[compojure "1.4.0"]
[ring "1.1.6"]
[ring/ring-defaults "0.1.5"]]
:source-paths ["src/clj" "src/cljs"]
:plugins [[lein-ring "0.9.7"]
@brunokim
brunokim / ExpectedExceptionTest.java
Last active September 21, 2016 00:53
Example of stacktrace hiding with ExpectedException rule
// I'm not sure this is the minimal possible example, edits are welcome
package assertion;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
@brunokim
brunokim / mwe.py
Last active March 8, 2019 22:10
pytype difficulties with classmethod
from typing import Generic, List, TypeVar
T = TypeVar('T')
class Container(Generic[T]):
def __init__(self, x: T):
self.x = x
def __repr__(self):
return f'<Container {self.x}>'
from collections import Counter
c = Counter()
with open('big_file.txt') as f:
for line in f:
c[line[:-1]] += 1 # Remove newline from line
for key, count in c.most_common():
print(f'{key} - {count}')
def create_file(num_elements: int, size: int, filename: str) -> int:
with open(filename, 'w') as f:
total = 0
while total < size:
value = random.randrange(num_elements)
total += f.write(f'{value}\n')
return total
import gc
import sys
def get_transitive_size(obj):
stack = [obj]
size = 0
seen = set()
while stack:
o = stack.pop()
if isinstance(o, type):
def get_counter_size(c: Counter) -> int:
size = sys.getsizeof(c)
size += sum(sys.getsizeof(key) for key in c)
return size
def memory_usage() -> int:
with open('/sys/fs/cgroup/memory/memory.memsw.usage_in_bytes') as f:
return int(f.read())
def memory_limit() -> int:
with open('/sys/fs/cgroup/memory/memory.memsw.limit_in_bytes') as f:
return int(f.read())