Skip to content

Instantly share code, notes, and snippets.

@WonRhee
WonRhee / findModeInArrayOfIntegers.js
Created December 20, 2016 08:31
Given array of integers, find its mode. (the number which appears most often in it)
// Given array of integers, find its mode. (the number which appears most often in it)
function arrayMode(sequence) {
var arr = {};
for (var i=0; i < sequence.length; i++) {
var num = sequence[i];
if (arr[num] === undefined){
arr[num] = 0;
}
arr[num] += 1;
@WonRhee
WonRhee / renameCmdExample.sh
Created July 26, 2017 21:31
Rename shell script example - dash to underscore
# rename dash to underscore using regex style
rename "s/-/_/g" *
@WonRhee
WonRhee / .bashrc
Created March 16, 2018 15:55
.bashrc
# ~/.bashrc
# some more ls aliases
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'
alias ld='ls -ld -1 $PWD/*'
@WonRhee
WonRhee / Native app communication
Created May 26, 2019 05:56 — forked from NielsLeenheer/Native app communication
How a web app running on HTTPS can communicatie with local services
I have a web app that needs to talk to point of sale hardware: receipt printers, customer displays,
cash drawers and payment terminals. Direct communication from the web app with these devices is
impossible, so I created a native app that can be installed on the computer that can talk to the
devices. The app runs a web server that exposes these devices using a REST api.
The native app registers itself upon startup with a webservice. It sends its own IP address on
the local network and the server also sees the external IP address of the network. The web app
sends a discovery request to the webservice and it receives all the local IP addresses which
have the same external IP address.
@WonRhee
WonRhee / model_relation_ex.py
Created April 17, 2021 04:49 — forked from kirang89/model_relation_ex.py
Example for many-to-many relationship with extra columns in SQLAlchemy
import sqlalchemy
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, Integer, String, ForeignKey
from sqlalchemy.orm import sessionmaker, relationship
engine = sqlalchemy.create_engine('sqlite:///:memory:')
Base = declarative_base()