Skip to content

Instantly share code, notes, and snippets.

View firewut's full-sized avatar
🎯
Focusing

Andrey Chibisov firewut

🎯
Focusing
View GitHub Profile
@jruizvar
jruizvar / InstallOpenCV.md
Last active February 27, 2021 12:53
Building OpenCV 3.2.0 from source on macOS Sierra with Python 3 support

Building OpenCV 3.2.0 from source with Python 3 support

Install OpenCV on macOS Sierra enabling Python 3 with the following instructions:

  • Install CMake, Python 3 + Numpy in advance
  • Download latest OpenCV source code (https://github.com/opencv/opencv/releases)
  • Move the folder opencv-3.2.0 to the current directory
  • In the current directory, execute the following steps:
mkdir build
@pythonhacker
pythonhacker / ttldict.py
Created October 12, 2016 05:54
A Python dictionary type with keys having specific time to live (TTL)
import threading
import time
class TTLDict(dict):
""" A dictionary with keys having specific time to live """
def __init__(self, ttl=5):
self._ttl = ttl
# Internal key mapping keys of _d
# to times of access
@jmvrbanac
jmvrbanac / app.py
Created February 18, 2016 01:05
Using Jinja2 with Falcon
import os
import falcon
import jinja2
def load_template(name):
path = os.path.join('templates', name)
with open(os.path.abspath(path), 'r') as fp:
return jinja2.Template(fp.read())
@leonjza
leonjza / netcat.py
Last active July 30, 2023 16:28
Python Netcat
import socket
class Netcat:
""" Python 'netcat like' module """
def __init__(self, ip, port):
self.buff = ""
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
@olebedev
olebedev / debug.sh
Last active August 29, 2015 14:08
Golang test debugging snippet for cgdb
#!/usr/bin/env bash
rm go-swarm.test || true
nohup go test -c -gcflags '-N -l' -work github.com/olebedev/go-swarm
WORK=$(cat nohup.out)
rm nohup.out
cgdb go-swarm.test -- -d ${WORK#WORK=} || rm go-swarm.test || true
# gdb --tui go-swarm.test -d ${WORK#WORK=} || rm go-swarm.test || true
rm go-swarm.test || true
echo ${WORK#WORK=}
@davidvthecoder
davidvthecoder / round.go
Created April 9, 2014 19:58
Arggh Golang does not include a round function in the standard math package. So I wrote a quick one.
package main
import (
"log"
"math"
)
func Round(val float64, roundOn float64, places int ) (newVal float64) {
var round float64
pow := math.Pow(10, float64(places))
@ibeex
ibeex / foo.log
Created August 4, 2012 13:46
Flask logging example
A warning occurred (42 apples)
An error occurred
@jboner
jboner / latency.txt
Last active July 19, 2024 09:51
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@samuraisam
samuraisam / deep_eq.py
Last active March 29, 2024 22:17
Deep Equality Test for Nested Python Structures
#Copyright (c) 2010-2013 Samuel Sutch [samuel.sutch@gmail.com]
#
#Permission is hereby granted, free of charge, to any person obtaining a copy
#of this software and associated documentation files (the "Software"), to deal
#in the Software without restriction, including without limitation the rights
#to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
#copies of the Software, and to permit persons to whom the Software is
#furnished to do so, subject to the following conditions:
#
#The above copyright notice and this permission notice shall be included in