This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# rename dash to underscore using regex style | |
rename "s/-/_/g" * |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ~/.bashrc | |
# some more ls aliases | |
alias ll='ls -alF' | |
alias la='ls -A' | |
alias l='ls -CF' | |
alias ld='ls -ld -1 $PWD/*' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | |