Skip to content

Instantly share code, notes, and snippets.

@igorzakhar
igorzakhar / md5_checksum.py
Last active April 20, 2017 16:33
MD5 checksum of a file
#from http://stackoverflow.com/questions/3431825/generating-an-md5-checksum-of-a-file
def md5(fname):
hash_md5 = hashlib.md5()
with open(fname, "rb") as f:
for chunk in iter(lambda: f.read(4096), b""):
hash_md5.update(chunk)
return hash_md5.hexdigest()
#Source http://www.saltycrane.com/blog/2008/11/python-datetime-time-conversions/
from datetime import datetime
import time
#-------------------------------------------------
# conversions to strings
#-------------------------------------------------
# datetime object to string
dt_obj = datetime(2008, 11, 10, 17, 53, 59)
@igorzakhar
igorzakhar / async_get_status_code.py
Last active June 1, 2024 19:29
Get response status code using asyncio/aiohttp
import sys
import time
import asyncio
import itertools
import aiohttp
async def spin(msg): # <2>
write, flush = sys.stdout.write, sys.stdout.flush
package main
import (
"fmt"
"math/rand"
"time"
)
func main() {
numbers := make([]int, 5)
@igorzakhar
igorzakhar / gist:fe79541bb5e430d300f1a1fb296cbfc4
Created January 15, 2018 15:29 — forked from ismasan/gist:3804361
async fetching of urls using goroutines and channels
package main
import (
"fmt"
"net/http"
"time"
)
var urls = []string{
"http://pulsoconf.co/",
@igorzakhar
igorzakhar / asyncfetchurls.go
Last active January 16, 2018 22:18
Load urls from file and get responses
package main
import (
"bufio"
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
"strings"
package main
import (
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
)
import os
def convert_bytes(num):
for x in ['bytes', 'KB', 'MB', 'GB', 'TB']:
if num < 1024.0:
return "%3.1f %s" % (num, x)
num /= 1024.0
import os
import requests
def open_file(file):
with open(file, 'rb') as file:
return file.read()
import asyncio
import re
import aiohttp
def load_ip_list(filename):
with open(filename, 'r') as fp:
ip_list = fp.read().rstrip().split('\n')
return ip_list