Skip to content

Instantly share code, notes, and snippets.

View envil's full-sized avatar
🎓
Busying doing Master Degree.

Viet Ta envil

🎓
Busying doing Master Degree.
View GitHub Profile
@envil
envil / pix-angle-utils.py
Last active May 1, 2019 20:49
Utility function to convert between pixel to angle and vice versa in Eye Tracking. Ported from matlab code. Original article here: https://courses.washington.edu/matlab1/matlab/
import math
class Display:
def __init__(self, dist, width, resolution):
self.distance = dist
self.width = width
self.resolution = resolution
# Credit to gmb zre 11/1/07, ported to python by Viet Ta
@envil
envil / main.py
Created April 30, 2019 15:41
kwargs for python running via cli
import sys
# RUN:
# python main.py fd_min=100 fd_max=250 sd_min=20 sd_max=50 vel_min=30 vel_max=100 sam_freq=50 X=1024 Y=768 dist=60 size=53.34
def main():
kwargs_raw = sys.argv[1:]
kwargs = {key: val for key, val in (a.split('=', 1) for a in kwargs_raw)}
print(kwargs)
@envil
envil / gendata.py
Created October 13, 2018 16:22
Generate a very large random text file
import random
import string
def generator(size=6, chars=string.ascii_uppercase + string.digits):
return ''.join(random.choice(chars) for _ in range(size))
def ran():
return random.randint(0, 3800)
@envil
envil / circle-area-stupid-calculator.py
Created October 12, 2018 05:27
Monte Carlo circle area calculator
import numpy as np
import math
def test(iteration):
radius = np.random.randint(0, 1000)
sum_area = 0
for i in range(iteration):
x = np.random.uniform(-radius, radius)
y = math.sqrt(radius * radius - x * x)
@envil
envil / monte-carlo-sort.py
Last active October 11, 2018 21:34
Monte Carlo Sort
import numpy as np
'''
This's a just a stupid example with the sole purpose of
demonstrating the Monte Carlo randomization strategy
'''
A = np.random.randint(0, 10000, 1000)
for x in range(1000000):
first_position = np.random.randint(0, 1000)
second_position = np.random.randint(0, 1000)
@envil
envil / Highcharts Cheat Sheet
Created December 14, 2017 16:35 — forked from mulhoon/Highcharts Cheat Sheet
Highcharts Cheat Sheet
$('#container').highcharts({
chart: {
alignTicks: true, // When using multiple axis, the ticks of two or more opposite axes will automatically be aligned by adding ticks to the axis or axes with the least ticks.
animation: true, // Set the overall animation for all chart updating. Animation can be disabled throughout the chart by setting it to false here.
backgroundColor: '#FFF', // The background color or gradient for the outer chart area.
borderColor: '#4572A7', // The color of the outer chart border.
borderRadius: 5, // The corner radius of the outer chart border. In export, the radius defaults to 0. Defaults to 5.
borderWidth: 0, // The pixel width of the outer chart border.
className: null, // A CSS class name to apply to the charts container div, allowing unique CSS styling for each chart.
defaultSeriesType: 'line', // Alias of type.
@envil
envil / multiple-ng-class.jade
Created April 18, 2017 04:46
Populate multiple class by ng-class #angularjs
div(ng-class="{'class1': $index === 1,
'class2': $index === 2,
'class3': $index !== 1 && $index !== 2}")
@envil
envil / lodash.factory.js
Created April 17, 2017 04:26
Factory to inject non-Angular library to the application, here is Lodash for example.
(function () {
angular
.module('shared.factories')
.factory('_', LodashFactory);
LodashFactory.$inject = ['$window', '$state'];
function LodashFactory($window, $state) {
if(!$window._){
var lodashCdnUrl = 'https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.4/lodash.min.js';
loadScript(lodashCdnUrl, function () {
@envil
envil / AlterQueryString.js
Last active November 26, 2017 10:25
Util function that can append/delete a param in a query string. (pass in 1 param to delete that param)
function AlterQueryString(param, val) {
var queryString = window.location.search.replace("?", "");
var parameterListRaw = queryString == "" ? [] : queryString.split("&");
var parameterList = {};
for (var i = 0; i < parameterListRaw.length; i++) {
var parameter = parameterListRaw[i].split("=");
if (typeof val != 'undefined') {
parameterList[parameter[0]] = parameter[1];
} else if (param != parameter[0]) {
parameterList[parameter[0]] = parameter[1];
@envil
envil / HorizontalScrolling.ahk
Created November 10, 2016 03:03
AutoHotKey - Fine Horizontal Scrolling for Windows
; Shift + Wheel for horizontal scrolling
+WheelUp::
; Scroll to the left
MouseGetPos,,,id, fcontrol,1
Loop 8 ; <-- Increase for faster scrolling
SendMessage, 0x114, 0, 0, %fcontrol%, ahk_id %id% ; 0x114 is WM_HSCROLL and the 0 after it is SB_LINERIGHT.
return
+WheelDown::
;Scroll to the right
MouseGetPos,,,id, fcontrol,1