Skip to content

Instantly share code, notes, and snippets.

View povilasb's full-sized avatar
🏗️

Povilas Balciunas povilasb

🏗️
View GitHub Profile
let numberConstat: Double = 5
var count = 1
count += 2
@povilasb
povilasb / http.cpp
Created September 21, 2015 05:47
Create proxy authorization header
#include <string>
#include "base64.h"
std::string
http_make_proxy_basic_auth_header(const std::string& username,
const std::string& password)
{
return "Proxy-Authorization: Basic " + base64_encode(username, password);
}
@povilasb
povilasb / tree.py
Last active January 31, 2016 18:40
"""Tree data structure.
NOTE: this module is "a good enough": it's far from complete implementation,
but has all the functionality needed at the moment.
More info: http://github.com/povilasb/pytree
"""
class Tree(object):
"""Tree data structure.
@povilasb
povilasb / unix_signals.py
Created June 23, 2016 16:51
Unix signal handling in python
import signal
def handler(signum, frame):
print("SIGHUP")
signal.signal(signal.SIGHUP, handler)
print("Press enter to finish")
input()
@povilasb
povilasb / unix_signals_asyncio.py
Created June 23, 2016 17:00
Unix signal handling with python asyncio
import signal
import asyncio
def handler():
print("SIGHUP")
ev_loop = asyncio.get_event_loop()
ev_loop.add_signal_handler(signal.SIGHUP, handler)
ev_loop.run_forever()
import asyncio
@asyncio.coroutine
def queue_loader(packet_queue):
for i in range(1, 4):
yield from packet_queue.put('item%s' % i)
yield from asyncio.sleep(1)
yield from packet_queue.put('DONE')
import asyncio
@asyncio.coroutine
def queue_loader(packet_queue):
for i in range(1, 10):
yield from packet_queue.put('item%' % i)
yield from asyncio.sleep(1)
@asyncio.coroutine
@povilasb
povilasb / soundex.py
Created August 8, 2016 16:06
Soundex naive implementation
from functools import reduce
from typing import Iterable
from itertools import filterfalse
CONSONANTS_DIGITS = {
'b': '1',
'f': '1',
'p': '1',
'v': '1',
'c': '2',
@povilasb
povilasb / Makefile
Created November 10, 2016 10:47
Pattern as variable
all: config-1 config-2
.PHONY: all
config-%: %
@echo "building conf $^"
.PHONY: config-%
1:
.PHONY: 1
@povilasb
povilasb / raw_http.rs
Created May 7, 2017 09:58
Do HTTP request with raw sockets
use std::net::TcpStream;
use std::io::{Write, Read};
fn main() {
let target_addr = "54.243.92.110:80"; // httpbin.org
let mut stream = TcpStream::connect(target_addr).unwrap();
stream.write(b"GET /ip HTTP/1.1\r\nHost: httpbin.org\r\nConnection: close\r\n\r\n");
let mut buff = [0; 65536];
stream.read(&mut buff);