Skip to content

Instantly share code, notes, and snippets.

View nmmmnu's full-sized avatar

Nikolay Mihaylov nmmmnu

View GitHub Profile
@nmmmnu
nmmmnu / multiplication.php
Last active August 29, 2015 13:57
Multiplication with shift
<?
function multiplicate2($a, $b){
printf("%16b x %b\n%16b\n", $a, $b, $a * $b);
}
function multiplicate($a, $b){
printf("%1s %32d x %8d = %d\n", "", $a, $b, $a * $b);
printf("%1s %32b x %8b\n", "", $a, $b);
@nmmmnu
nmmmnu / oop_class_demo.c
Last active August 29, 2015 13:57
OOP using plane C
#include <stdlib.h>
#include <stdio.h>
/*
* Base class. It defines int area() method.
* The class is abstract so we did not made constructor.
* Calling the area() method will probably core dump.
*/
@nmmmnu
nmmmnu / div.sh
Last active August 29, 2015 13:57
$ php
<?
error_reporting(E_ALL);
$a = 5 / 0;
var_dump($a);
<ctrl-d>
#include <stdio.h>
#define MAX 2000000000
//#define IMPL 0
int do_loop(int max);
int main(){
printf("%d\n", do_loop(MAX) );
@nmmmnu
nmmmnu / read_prom.js
Created September 8, 2014 19:44
NodeJS Q Promises Demo
var fs = require('fs');
var Q = require("q");
/*
Q.all(
[
Q.ninvoke(fs, "readFile", "/etc/hosts", "utf8")
]
)
*/
@nmmmnu
nmmmnu / mmap_test.c
Created January 3, 2015 22:17
mmap test
gcc mmap_test.c -Wall
touch file.bin
./a.out
hexdump -C file.bin
./a.out Hello Sir
hexdump -C file.bin
@nmmmnu
nmmmnu / malloc_calc.c
Created January 22, 2015 11:14
malloc calculator
#include <stdlib.h>
#include <stdio.h>
size_t malloc_calc(size_t size){
const size_t realloc_size = sizeof(void *) * 2;
const size_t realloc_add = sizeof(void *);
size_t newsize = size / realloc_size;
if (size % realloc_size)
@nmmmnu
nmmmnu / malloc_size.cc
Created July 23, 2015 08:07
Malloc Size Test
#include <stdlib.h>
#include <malloc.h>
#include <stdio.h>
void test(size_t size){
char *a = new char[size]; //malloc(size);
size_t usize = malloc_usable_size(a);
printf("%5zu %5zu %5zu\n", size, usize, usize - size);
@nmmmnu
nmmmnu / string.cc
Created July 23, 2015 21:03
SSO String C++11
#include "string.h"
const char *String::__NULLSTR = "";
// ==============================
String::String(const char *s){
if (s == nullptr){
_terminator = TERM_LOCAL;
_buff.local[0] = '\0'; // the NULL terminator.
@nmmmnu
nmmmnu / priority_queue.cc
Created August 20, 2015 19:52
priority_queue
#include <queue>
#include <vector>
#include <iostream>
struct comparator{
bool operator()(int a, int b) const{
return a > b;
}
};