Skip to content

Instantly share code, notes, and snippets.

View doomhz's full-sized avatar

Dumitru Glavan doomhz

View GitHub Profile
@doomhz
doomhz / .vimrc
Last active February 2, 2024 11:11
VIM config
" Install Plug for plugin support
" curl -fLo ~/.vim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
" Don't try to be vi compatible
set nocompatible
" Helps force plugins to load correctly when it is turned back on below
filetype off
" Auto reload file when changed by linter
@doomhz
doomhz / crowding.js
Created August 22, 2017 08:15
crowding js
const {min, max} = require('underscore')
const first = (arr) => arr[0]
const last = (arr) => arr[arr.length - 1]
const almostZero = (a) => (a > -0.000001 && a < 0.000001)
const almostEqual = (a, b) => almostZero(Math.abs(a) - Math.abs(b))
const population = [
{ objectives: [0.1, 0.2, 0.3] },
{ objectives: [0.2, 0.4, 0.6] },
{ objectives: [0.1, 0.05, 0.3] }
]
@doomhz
doomhz / crowding.rb
Created August 22, 2017 08:15
crowding
def calculate_crowding_distance(pop)
pop.each {|p| p[:dist] = 0.0}
num_obs = pop.first[:objectives].size
num_obs.times do |i|
min = pop.min{|x,y| x[:objectives][i]<=>y[:objectives][i]}
max = pop.max{|x,y| x[:objectives][i]<=>y[:objectives][i]}
rge = max[:objectives][i] - min[:objectives][i]
pop.first[:dist], pop.last[:dist] = 1.0/0.0, 1.0/0.0
next if rge == 0.0
(1...(pop.size-1)).each do |j|
@doomhz
doomhz / lambda_api_gateway_basic_request.js
Created January 12, 2017 23:28
Lambda+API Gateway basic request
exports.handler = (event, context, callback) => {
var data = {
headers: event.headers,
path: event.resourcePath,
queryParams: event.queryStringParameters,
pathParams: event.pathParameters,
bodyParams: event.body,
method: event.httpMethod
}
var response = {
@doomhz
doomhz / index.html
Last active February 25, 2019 04:32 — forked from anonymous/index.html
React+Redux example JS Bin// source http://jsbin.com/fowacudise
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<script src="https://fb.me/react-with-addons-15.1.0.js"></script>
<script src="https://fb.me/react-dom-15.1.0.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/redux/3.5.2/redux.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-redux/4.4.5/react-redux.min.js"></script>
@doomhz
doomhz / index.html
Created August 15, 2016 12:33 — forked from anonymous/index.html
Redux example JS Bin// source http://jsbin.com/zekusiloxi
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/redux/3.5.2/redux.min.js"></script>
</head>
<body>
@doomhz
doomhz / lambda_handler.js
Last active July 21, 2016 15:32
Lambda example with NodeJS and API Gateway, pulled from AWS
'use strict';
console.log('Loading function');
let doc = require('dynamodb-doc');
let dynamo = new doc.DynamoDB();
/**
* Provide an event that contains the following keys:
*
* - operation: one of the operations in the switch statement below
# Add it to /etc/environment
LC_ALL="en_US.UTF-8"
# or execute it to the console
export LC_ALL="en_US.UTF-8"
@doomhz
doomhz / jslogger_console.js
Created May 26, 2013 15:43
Replace the browser console with JSLogger.
if (jslogger) {
if(!window.console) window.console = {};
var methods = ["log", "debug", "warn", "info"];
for(var i=0;i<methods.length;i++){
console[methods[i]] = function(){jslogger.log.apply(jslogger, arguments);};
}
}
@doomhz
doomhz / format_json.js
Created December 2, 2012 23:36
Format JSON for HTML display
// Format JSON function
// http://ketanjetty.com/coldfusion/javascript/format-json/
var formatJson = function (val) {
var retval = '';
var str = val;
var pos = 0;
var strLen = str.length;
var indentStr = '&nbsp;&nbsp;&nbsp;&nbsp;';
var newLine = '<br />';