Skip to content

Instantly share code, notes, and snippets.

View h0rn3t's full-sized avatar
🏠
Working from home

Eugene h0rn3t

🏠
Working from home
  • Ukraine
View GitHub Profile
@h0rn3t
h0rn3t / 0_reuse_code.js
Last active August 29, 2015 14:06
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@h0rn3t
h0rn3t / javascript_resources.md
Last active August 29, 2015 14:06 — forked from jookyboi/javascript_resources.md
Here are a set of libraries, plugins and guides which may be useful to your Javascript coding.

Libraries

  • jQuery - The de-facto library for the modern age. It makes things like HTML document traversal and manipulation, event handling, animation, and Ajax much simpler with an easy-to-use API that works across a multitude of browsers.
  • Backbone - Backbone.js gives structure to web applications by providing models with key-value binding and custom events, collections with a rich API of enumerable functions, views with declarative event handling, and connects it all to your existing API over a RESTful JSON interface.
  • AngularJS - Conventions based MVC framework for HTML5 apps.
  • Underscore - Underscore is a utility-belt library for JavaScript that provides a lot of the functional programming support that you would expect in Prototype.js (or Ruby), but without extending any of the built-in JavaScript objects.
  • lawnchair - Key/value store adapter for indexdb, localStorage
@h0rn3t
h0rn3t / python_resources.md
Last active August 29, 2015 14:06 — forked from jookyboi/python_resources.md
Python-related modules and guides.

Packages

  • lxml - Pythonic binding for the C libraries libxml2 and libxslt.
  • boto - Python interface to Amazon Web Services
  • Django - Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design.
  • Fabric - Library and command-line tool for streamlining the use of SSH for application deployment or systems administration task.
  • PyMongo - Tools for working with MongoDB, and is the recommended way to work with MongoDB from Python.
  • Celery - Task queue to distribute work across threads or machines.
  • pytz - pytz brings the Olson tz database into Python. This library allows accurate and cross platform timezone calculations using Python 2.4 or higher.

Guides

@h0rn3t
h0rn3t / threadpool.py
Created April 14, 2016 11:36 — forked from andreisavu/threadpool.py
Python Thread Pool
# Original code at http://code.activestate.com/recipes/203871/
# I have added a limit for the number of tasks waiting
# The method queueTask will block if the current taskList size
# exceeds the specified limit
import threading
from time import sleep
# Ensure booleans exist (not needed for Python 2.2.1 or higher)
@h0rn3t
h0rn3t / async_await_sample.py
Created April 14, 2016 11:39
Sample code demonstrating use of await with concurrent.futures
from concurrent.futures import ThreadPoolExecutor, Future
import asyncio
import time
async def sum_numbers(x, y):
await asyncio.sleep(1)
return x + y
def sum_numbers_blocking(x, y):
time.sleep(1)
@h0rn3t
h0rn3t / concurrent.futures-intro.md
Created April 15, 2016 21:27 — forked from mangecoeur/concurrent.futures-intro.md
Easy parallel python with concurrent.futures

Easy parallel python with concurrent.futures

As of version 3.3, python includes the very promising concurrent.futures module, with elegant context managers for running tasks concurrently. Thanks to the simple and consistent interface you can use both threads and processes with minimal effort.

For most CPU bound tasks - anything that is heavy number crunching - you want your program to use all the CPUs in your PC. The simplest way to get a CPU bound task to run in parallel is to use the ProcessPoolExecutor, which will create enough sub-processes to keep all your CPUs busy.

We use the context manager thusly:

with concurrent.futures.ProcessPoolExecutor() as executor:
@h0rn3t
h0rn3t / background_tasks.py
Created May 22, 2016 18:29 — forked from blakev/background_tasks.py
Background tasks manager for gevent Greenlets
#!/usr/bin/env python3
# ~*~ coding: utf-8 ~*~
#
# >>
# .. created: 5/20/16
# .. author: blake.vandemerwe
#
# LICENSE
# <<
@h0rn3t
h0rn3t / echo.go
Created May 10, 2017 18:26 — forked from paulsmith/echo.go
A simple echo server testing a few interesting Go language features, goroutines and channels.
// $ 6g echo.go && 6l -o echo echo.6
// $ ./echo
//
// ~ in another terminal ~
//
// $ nc localhost 3540
package main
import (
@h0rn3t
h0rn3t / aes-ecb.py
Last active December 23, 2022 07:19 — forked from lopes/aes-ecb.py
Simple Python example of AES in ECB mode.
from hashlib import md5
from base64 import b64decode
from base64 import b64encode
from Crypto.Cipher import AES
# Padding for the input string --not
# related to encryption itself.
BLOCK_SIZE = 16 # Bytes
pad = lambda s: s + (BLOCK_SIZE - len(s) % BLOCK_SIZE) * \
@h0rn3t
h0rn3t / haproxy, sending the source ip to the webserver.
Created September 17, 2018 08:45 — forked from PiBa-NL/haproxy, sending the source ip to the webserver.
haproxy, sending the source ip to the webserver.
To send the ip addres of the client/webbrowser to the server/webserver behind it there are a few options:
1- option forwardfor
2- send-proxy
3- source 0.0.0.0 usesrc clientip
1- option forwardfor
This is an easy option to configure in haproxy, it does require that http layer7 processing is used 'mode http' and the webserver/ webapplication that wants to log or use the ip of the client must use the http-header 'X-Forwarded-For' to read the clientip.
2- send-proxy / send-proxy-v2 / send-proxy-*
This is can be used both with mode tcp and http, it does however require that the server also understands the proxyprotocol. Some applications have added support for this protocol which adds a few bytes with ip information before the actual request.