Skip to content

Instantly share code, notes, and snippets.

View sebbekarlsson's full-sized avatar
🐧
Programming

Sebastian Karlsson (ianertson) sebbekarlsson

🐧
Programming
View GitHub Profile
@sebbekarlsson
sebbekarlsson / python-flask-nginx.md
Last active June 25, 2021 21:04
Creating a simple web application in Python and running it under Nginx

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:

@sebbekarlsson
sebbekarlsson / cpp_multiple_types.cpp
Last active September 18, 2018 07:12
C++ function that returns multiple types and multiple types as argument
#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 / questions.sh
Created October 11, 2018 06:34
Asking questions in bash
question_state=0
function ask() {
read -p "$1" -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
question_state=1
fi
}
@sebbekarlsson
sebbekarlsson / c_vs_cpp.md
Created August 1, 2019 20:20
C vs CPP, binary size

hello_cpp_cout:

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

Size: 14,924 bytes

'''
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')
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct FRUIT_STRUCT
{
char* name;
} fruit_T;
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";
.section .data
divtable:
.long 100, 10, 1, 0
.section .bss
.lcomm buffer, 16
.section .text
.type to_str, @function
to_str:
pushl %ebp
movl %esp, %ebp
movl 8(%esp), %eax
jmp to_str_loop
to_str_loop:
# Convert number to string
# (number, buffer) => buffer
.type itoa, @function
itoa:
pushl %ebp
movl %esp, %ebp
movl $12, %edi
leal (%esp, %edi, 1), %ebx # buffer
movl 8(%esp), %eax # number