Skip to content

Instantly share code, notes, and snippets.

open Core
let () =
let unit_str = "y\n" and unit_str_len = 2 in
let buf = Buffer.create 0 in
let rec print_endlessly () =
Out_channel.output_buffer stdout buf;
print_endlessly ()
in
let rec grow_buf () =
/*
* gcc -Wall -Wextra -fstack-protector-explicit k.c
*
* lix@ipass-lix01 /tmp % time ./a.out 0
* ./a.out 0 4.73s user 0.02s system 99% cpu 4.763 total
* lix@ipass-lix01 /tmp % time ./a.out 1
* ./a.out 1 5.60s user 0.02s system 99% cpu 5.648 total
*
*/
#include <limits.h>
void array_access0(void)
{
int a[10];
int i;
for (i = 0; i < 10; ++i) {
a[i] = 0;
}
@b4284
b4284 / yes.scm
Last active July 20, 2017 15:38
Mimic GNU yes' behavior of cmdline arguments.
(use-modules (ice-9 binary-ports)
(rnrs bytevectors))
(define (build-string s n)
(let* ((s2 (string-append s "\n"))
(s2len (string-length s2)))
(let A ((s3 (string-copy s2))
(s3len s2len))
(if (> (+ s3len s2len) n)
s3
#include <stdio.h>
#include <stdbool.h>
#include <ctype.h>
#include <string.h>
typedef struct {
char hr1;
char hr2;
char delim1;
char min1;
#include <stdio.h>
#define SWAP(a, b) \
do { \
typeof(a) SWAP = a; \
a = b; \
b = SWAP; \
} while (0)
void dump_array(FILE *stream, int *arr, int arr_size)
#include <iostream>
using namespace std;
class A {
public:
A(){print();}
virtual print(){cout << "in A"<<endl;}
};
// With sub %rsp, 0x10, because plus1() called min1().
int min1(int a, int b) {
return (a - b);
}
int plus1(int a, int b, int c) {
return (a + min1(b, c));
}
// Without sub %rsp, 0x10, because plus1() doesn't call any procedure.
#include <stdio.h>
int main(void) {
int criedForLesMiserables = 0;
for (int i = 1; i < 10; i++) {
printf("criedForLesMiserables = %d\n", criedForLesMiserables);
criedForLesMiserables += i;
}
return 0;
.text
.globl _start
_start:
mov $1, %eax
mov $5, %ebx
int $0x80
# as -o /tmp/hello.o hello.s && ld -o /tmp/hello /tmp/hello.o