Skip to content

Instantly share code, notes, and snippets.

View jnovikov's full-sized avatar

Ivan Novikov jnovikov

  • Dublin, Ireland
  • 00:41 (UTC)
View GitHub Profile
@jnovikov
jnovikov / num_output.asm
Created December 27, 2018 15:03
Assembler easy num_output
; Simple example
; Writes Hello World to the output
JMP start
digits: DB 0 ; Variable
DB 0
DB 0
output_p: DB 232
start:
@jnovikov
jnovikov / dirscan.cpp
Created December 23, 2018 09:00
Simple code to get files in directory using popen and ls
#include <iostream>
#include <cstdio>
int main() {
FILE *p = popen("ls -p | grep -v /", "r");
char *t = new char[1000];
int status = fscanf(p, "%s", t);
while (status != -1) {
std::cout << t << std::endl;
status = fscanf(p, "%s", t);
@jnovikov
jnovikov / main.cpp
Created December 16, 2018 10:33
signals and popen
//#include <cstdio>
//#include <iostream>
//#include <unistd.h>
//#include <fcntl.h>
//#include <sys/types.h>
//#include <sys/socket.h>
//#include <arpa/inet.h>
//#include <csignal>
//
//
@jnovikov
jnovikov / main.cpp
Created November 28, 2018 13:20
Caesar decryption
#include <iostream>
#include <string>
#include <vector>
int mod(int a, int b) {
return (a % b + b) % b;
}
std::string decrypt(std::string &s, int key) {
@jnovikov
jnovikov / server.cpp
Created November 10, 2018 20:09
Easy one threaded tcp server c++ implementation
#include <cstdio>
#include <iostream>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
int main() {
@jnovikov
jnovikov / calc.py
Created October 28, 2018 13:32
Balls collision
import random
import sys
import pygame
size = width, height = 800, 600
white = 255, 255, 255
class Ball(object):
@jnovikov
jnovikov / main.cpp
Last active October 14, 2018 10:10
Fork/exec wait example
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <climits>
#include <unordered_map>
#include <cstdlib>
#include <unistd.h>
#include <fcntl.h>
#include <fstream>
@jnovikov
jnovikov / users.py
Created July 6, 2018 14:47
Example usage of sqlite3 library on Python
import sqlite3
conn = sqlite3.connect("db.db")
cursor = conn.cursor()
init_db = "CREATE TABLE IF NOT EXISTS users " \
"(id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, " \
"login VARCHAR(200) UNIQUE, password VARCHAR(200))"
@jnovikov
jnovikov / example_requests.py
Created July 6, 2018 12:31
Example of usage python requests library
import requests
base_url = "https://shadowservants.ru"
url = "/"
def register(login,password):
data = dict(login=login,password=password)
r = requests.post(base_url + "/register",data=data)
print(r.status_code,r.text)
import sqlite3
conn = sqlite3.connect("test.db")
cursor = conn.cursor()
create_db = 'CREATE TABLE IF NOT EXISTS users (id INTEGER NOT NULL ' \
'PRIMARY KEY AUTOINCREMENT, login VARCHAR(200), password VARCHAR(200),' \
'favourite_team VARCHAR(300), favourite_number INTEGER )'