Skip to content

Instantly share code, notes, and snippets.

View sn1p3r46's full-sized avatar
💭
Lost in Coding

Alexander Ows sn1p3r46

💭
Lost in Coding
View GitHub Profile
@sn1p3r46
sn1p3r46 / node_calls_python.js
Last active December 13, 2018 14:14
nodejs execFile python script reads the parameter and sends it back through the stdout
const { execFile } = require('child_process');
var js = JSON.stringify({a:"fiore", b:[1,2,3], c:{}, d:[]});
execFile('/tmp/comm.py', [js], { encoding: 'utf8' }, (error, stdout) => {
if (error) {
throw new Error(error);
}
console.log(stdout);
});
@sn1p3r46
sn1p3r46 / micordata.py
Last active March 31, 2020 11:42
Python Implementation of: "Fast Generation of Accurate Synthetic Microdata" https://crises-deim.urv.cat/web/docs/publications/lncs/443.pdf
import numpy as np
def compute_mean(v):
return sum(v)/len(v)
def subtract_mean_to_col(M, idx):
M[:, idx] = M[:, idx] - compute_mean(M[:, idx])
def alg_two(n=None, m=None, A=None):
#1
@sn1p3r46
sn1p3r46 / app.py
Created June 19, 2018 01:04
Example of Flask admin making use of foreign keys and image upload. Just for illustrative proposes!
from flask import Flask, url_for
from flask_admin import Admin, form
from flask_sqlalchemy import SQLAlchemy
from flask_admin.contrib.sqla import ModelView
from jinja2 import Markup
"""
This just an illustrative example, take it as a concept example,
nothing more, it is not secure and does not handle image deletion.
Hereby more complete examples:
@sn1p3r46
sn1p3r46 / matrix_mul.py
Last active January 18, 2018 00:24
Recursive Matrix Multiplication
#!/usr/bin/python3
# ref http://www.cs.mcgill.ca/~pnguyen/251F09/matrix-mult.pdf
import numpy as np
def matrix_mul(A,B):
if A.shape == (1,1):
return A.dot(B)
@sn1p3r46
sn1p3r46 / README.md
Last active November 18, 2017 00:43
Raspberry Pi debian locales fix

Simple list of commands useful to fix locales on raspberry pi. In fact after a fresh install often perl is complaining about misconfigured locales. \

alternatively one can fill the /etc/default/locale with

LANG=en_US.UTF-8
LC_TIME=it_IT.UTF-8
LANGUAGE=en_US:en
LC_ALL=en_US.UTF-8
@sn1p3r46
sn1p3r46 / README.md
Created November 17, 2017 22:11 — forked from gdamjan/README.md
Setup for an easy to use, simple reverse http tunnels with nginx and ssh. It's that simple there's no authentication at all. The end result, a single ssh command invocation gives you a public url for your web app hosted on your laptop.

What

A lot of times you are developing a web application on your own laptop or home computer and would like to demo it to the public. Most of those times you are behind a router/firewall and you don't have a public IP address. Instead of configuring routers (often not possible), this solution gives you a public URL that's reverse tunnelled via ssh to your laptop.

Because of the relaxation of the sshd setup, it's best used on a dedicated virtual machine just for this (an Amazon micro instance for example).

Requirements

# Your init script
#
# Atom will evaluate this file each time a new window is opened. It is run
# after packages are loaded/activated and after the previous editor state
# has been restored.
#
# An example hack to log to the console when each text editor is saved.
#
# atom.workspace.observeTextEditors (editor) ->
# editor.onDidSave ->
@sn1p3r46
sn1p3r46 / index.html
Last active September 14, 2017 19:23
Simple WebSocket Client-Server Example
<!DOCTYPE html>
<html>
<head>
<title>WebSocket demo</title>
</head>
<body>
<script>
var messages = document.createElement('ul');
@sn1p3r46
sn1p3r46 / LatexPro.tex
Last active June 12, 2017 20:14
Array with overlapping windows
% https://www.overleaf.com/9963466dzbgyfnsjpmx#/36591581/
\documentclass{article}
\usepackage{tikz}
%%%<
\usepackage{verbatim}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength{\PreviewBorder}{10pt}%
\usetikzlibrary{patterns,decorations.pathreplacing}
\usetikzlibrary{snakes}
@sn1p3r46
sn1p3r46 / exercises0.erl
Last active November 16, 2016 00:25
Erlang functional programming exercises;
%%% Exercises description on comments;
-module(exercises0).
-export([count/1,repeated_elems/1,most_frequent_elem/1,ntimes/3]).
%%% #1
count([H|T]) ->
count([H|T],[]);
count([]) -> [].