Skip to content

Instantly share code, notes, and snippets.

Avatar
🐧
Programming

Sebastian Karlsson sebbekarlsson

🐧
Programming
View GitHub Profile
View to_str2.s
.type to_str, @function
to_str:
pushl %ebp
movl %esp, %ebp
movl 8(%esp), %eax
jmp to_str_loop
to_str_loop:
View to_str.s
.section .data
divtable:
.long 100, 10, 1, 0
.section .bss
.lcomm buffer, 16
.section .text
View input.tac
hello = (x: string, y:string, z:string) => {
print(x);
print(y);
print(z);
return 0;
};
main = (argc: int, argv: Array<string>):int => {
foo:string = "the first string\n";
View serialize.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct FRUIT_STRUCT
{
char* name;
} fruit_T;
View hex_to_decimal.py
'''
Simple example on how to manually convert hex to decimal without using
'int()' method.
'''
from functools import reduce
def to_decimal(hexnr):
assert hexnr.startswith('0x')
@sebbekarlsson
sebbekarlsson / c_vs_cpp.md
Created Aug 1, 2019
C vs CPP, binary size
View c_vs_cpp.md

hello_cpp_cout:

#include <iostream>
int main()
{
    std::cout << "Hello world" << std::endl;
    return 0;
}

Size: 14,924 bytes

@sebbekarlsson
sebbekarlsson / questions.sh
Created Oct 11, 2018
Asking questions in bash
View questions.sh
question_state=0
function ask() {
read -p "$1" -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
question_state=1
fi
}
@sebbekarlsson
sebbekarlsson / cpp_multiple_types.cpp
Last active Sep 18, 2018
C++ function that returns multiple types and multiple types as argument
View cpp_multiple_types.cpp
#include <iostream>
template <typename T>
T perform_operation(const T& left, std::string op, const T& right) {
if (op == "+")
return left + right;
if (op == "-")
return left - right;
}
@sebbekarlsson
sebbekarlsson / python-flask-nginx.md
Last active Jul 13, 2018
Creating a simple web application in Python and running it under Nginx
View python-flask-nginx.md

Python web application with Nginx

Let us create a simple API in Python and serving it using Nginx.

In this example we will use Debian 9 as a distro for the server.

The code

Alright, let's write some code.
We will create an API that will serve an array of fruits.

Let's create a __main__.py file: