Skip to content

Instantly share code, notes, and snippets.

@DeoluA
DeoluA / numberSort.js
Created December 30, 2022 20:05
Sort an array of integers in O(n) time. Array can also contain negative integers.
'use strict';
/**
* @param raw_numbers: an array of integer values. Can either be positive or negative
* @return: sorted array, from negative to positive
*/
const sortArrayOfIntegers = (raw_numbers) => {
let positives = {}, negatives = {};
for(let m = 0; m < raw_numbers.length; m++) {
if(raw_numbers[m] >= 0) {
// has it occured before?
@DeoluA
DeoluA / beforeUploadFunc.js
Last active March 22, 2024 12:24
Ant Design - Check the file type, file size and image dimensions before upload
// plugged in this answer from S.O. - https://stackoverflow.com/a/8904008/5172977
// import { Upload } from 'antd';
// function returns a promise
beforeUpload = (file) => {
return new Promise((resolve, reject) => {
// check the file type - you can specify the types you'd like here:
const isImg = file.type === 'image/jpeg' || file.type === 'image/jpg' || file.type === 'image/png' || file.type === 'image/gif';
if (!isImg) {
@DeoluA
DeoluA / rand_hex_col_gen.js
Created June 7, 2019 17:35
JavaScript Random Colour/Color Generator (Hex values)
var rand_hex_col_gen = function(){
// do the numbers first
var options = [];
for(var i=0; i<10; i++){
options.push(i.toString());
};
// add letters
options = [].concat.apply(options, ["a", "b", "c", "d", "e", "f"]);
@DeoluA
DeoluA / normal_cdf.js
Last active January 5, 2019 15:53
JavaScript Implementation of Error Function and Normal Cumulative Density Function
// https://interactive.deolua.com/normal-dist
/*
*@param number x - the value for which the cumulative probability value is desired
*@param number mean_val - the value of the mean of the distribution
*@param number sd_val_sqrd - the value of the SQUARE of the standard deviation of the distribution
*/
var normal_cdf = function(x, mean_val, sd_val_sqrd){
var err_input = (x - mean_val)/(Math.sqrt(2 * sd_val_sqrd));
@DeoluA
DeoluA / normal_pdf.js
Created January 5, 2019 14:10
JavaScript implementation of the Normal Probability Density Function
// https://interactive.deolua.com/normal-dist
/*
*@param number x - the value for which the probability value is desired
*@param number mean_val - the value of the mean of the distribution
*@param number sd_val_sqrd - the value of the SQUARE of the standard deviation of the distribution
*/
var pdf_formula = function(x, mean_val, sd_val_sqrd){
var numer = (x - mean_val)**2;
## from http://tr.im/hH5A
logsumexp <- function (x) {
y = max(x)
y + log(sum(exp(x - y)))
}
softmax <- function (x) {
exp(x - logsumexp(x))
}
@DeoluA
DeoluA / wordFreqWithLodash.html
Last active September 9, 2018 06:48
Get the frequency of words in a string using Lodash. AngularJS is used here for interactive functionality.
<!DOCTYPE html>
<head>
<script type="text/javascript" src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.4/lodash.min.js'></script>
<script type="text/javascript" src='https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.1/angular.min.js'></script>
<script type="text/javascript" src='wordFreq.js'></script>
</head>
<body ng-app='wordFreqApp'>
<div ng-controller='wordFreqCtrl'>
<h2>Input something below</h2>
@DeoluA
DeoluA / common-sci-symbols.md
Created December 10, 2015 08:31 — forked from benmarwick/common-sci-symbols.md
Commonly used scientific symbols in pandoc markdown

Commonly used scientific symbols in pandoc markdown

encoding is UTF-8, needs pdflatex

per mille sign

  • plain text: ‰ (doesn't render properly in PDF)
  • HTML: &permil; (renders properly in PDF)
  • LaTeX: $\text{\textperthousand}$ (renders properly in PDF)

delta sign

@DeoluA
DeoluA / server.R
Created October 23, 2015 13:57 — forked from withr/server.R
Encrypt password with md5 for Shiny-app.
library(shiny)
library(datasets)
Logged = FALSE;
PASSWORD <- data.frame(Brukernavn = "withr", Passord = "25d55ad283aa400af464c76d713c07ad")
# Define server logic required to summarize and view the selected dataset
shinyServer(function(input, output) {
source("www/Login.R", local = TRUE)
observe({
if (USER$Logged == TRUE) {