Skip to content

Instantly share code, notes, and snippets.

View uhho's full-sized avatar

Lukasz uhho

  • Axelspace
  • Tokyo
View GitHub Profile
@uhho
uhho / node nginx configuration
Created October 4, 2013 01:16
Sample nginx configuration for NodeJS + SocketIO app
# Load balancer configuration
upstream exampleApp {
# Directs to the process with least number of connections.
least_conn;
# One failed response will take a server out of circulation for 20 seconds.
server 127.0.0.1:10080 fail_timeout=20s;
#server 127.0.0.1:10081 fail_timeout=20s;
#server 127.0.0.1:10082 fail_timeout=20s;
#server 127.0.0.1:10083 fail_timeout=20s;
@uhho
uhho / linear_regression.js
Last active August 10, 2023 23:59
Simple linear regression in JS
/**
* Simple linear regression
*
* @param {Array.<number>} data
* @return {Function}
*/
function regression(data) {
var sum_x = 0, sum_y = 0
, sum_xy = 0, sum_xx = 0
, count = 0
@uhho
uhho / lpf.js
Created April 7, 2014 10:42
Low Pass Filter
// array of values
var values = [10,8,12,10,11,9,10,12,8,50,10,12,8];
// smoothing whole array
function lpf(values, smoothing){
var value = values[0];
for (var i = 1; i < values.length; i++){
var currentValue = values[i];
value += (currentValue - value) / smoothing;
values[i] = Math.round(value);
@uhho
uhho / gaussian.js
Created June 27, 2014 04:57
Two-dimensional Gaussian function in JavaScript
/**
* Two-dimensional Gaussian function
*
* @param {number} amplitude
* @param {number} x0
* @param {number} y0
* @param {number} sigmaX
* @param {number} sigmaY
* @returns {Function}
*/
@uhho
uhho / gist:481c20f093d56e1fe59c
Created February 26, 2015 06:08
Extracting private key and key certificate from .pfx file.
// create private key (any password is ok)
openssl pkcs12 -in xxx.pfx -nocerts -out example.key
// remove password
openssl rsa -in example.key -out example.key
// generate private/public pair
openssl pkcs12 -in xxx.pfx -out privpub.pem
// get public certificate from privpub
@uhho
uhho / MultivariateVsMultipleNormal.ipynb
Created April 4, 2017 01:22
Multivariate Normal vs Multiple Normal
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@uhho
uhho / pandas_s3_streaming.py
Last active December 2, 2022 18:57
Streaming pandas DataFrame to/from S3 with on-the-fly processing and GZIP compression
def s3_to_pandas(client, bucket, key, header=None):
# get key using boto3 client
obj = client.get_object(Bucket=bucket, Key=key)
gz = gzip.GzipFile(fileobj=obj['Body'])
# load stream directly to DF
return pd.read_csv(gz, header=header, dtype=str)
def s3_to_pandas_with_processing(client, bucket, key, header=None):
@uhho
uhho / qrcode_with_image.py
Created September 1, 2017 00:07
Generating QR code with image at the center.
import pyqrcode
from PIL import Image
# create background - QR code
qr = pyqrcode.create('Some text',error = 'H')
qr.png('output.png', scale=10)
im = Image.open('output.png')
im = im.convert("RGBA")
@uhho
uhho / pnpoly.ipynb
Last active April 5, 2018 00:01
Check if a point lies within a polygon
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@uhho
uhho / gravitational_accelleration.py
Created June 18, 2018 23:36
Gravitational accelleration
def g_at_distance(g_base, radius, distance):
"""
Calculate gravitational accelleration at a distance
- above the surface G * (radius / distance)^2
- below the surface G * (distance / radius)
Parameters
----------
g_base : float
gravitational accelleration at the surface