Skip to content

Instantly share code, notes, and snippets.

require 'rubypython'
arg1, arg2, arg3 = 800, 900, 1000
RubyPython.start
np = RubyPython.import("numpy")
@result = np.random.triangular(arg1, arg2, arg3, 100000).to_a.map(&:to_s).map(&:to_f)
RubyPython.stop
puts @result
@hungtatai
hungtatai / b2b.md
Last active November 8, 2016 03:54

vim /usr/bin/b2b

#! /usr/bin/env python

import sys

from_num, from_base = (sys.argv[1].split('/') + ["10"])[:2]

if len(sys.argv) > 2:

Nginx virtual host

vim /etc/nginx/sites-enabled/default

upstream app-a {
    server 127.0.0.1:3000;
}

server {
# http://stackoverflow.com/questions/19275856/auto-yes-to-the-license-agreement-on-sudo-apt-get-y-install-oracle-java7-instal
sudo add-apt-repository -y ppa:webupd8team/java
sudo apt-get update
echo debconf shared/accepted-oracle-license-v1-1 select true | sudo debconf-set-selections
echo debconf shared/accepted-oracle-license-v1-1 seen true | sudo debconf-set-selections
sudo apt-get -y install oracle-java8-installer
# sudo apt-get -y install oracle-java7-installer
String.prototype.copyToClipboard = function() {
/* https://gist.github.com/joeperrin-gists/8814825#gistcomment-1581738 */
var text = this;
const input = document.createElement('input');
input.style.position = 'fixed';
input.style.opacity = 0;
input.value = text;
document.body.appendChild(input);
input.select();
document.execCommand('Copy');
@hungtatai
hungtatai / listening.sh
Created October 10, 2016 13:14 — forked from mtarbit/listening.sh
A bash function wrapper for lsof to find any listening processes.
listening() {
if [ -z "$1" ]; then
lines=$(lsof -P -s TCP:LISTEN -i TCP | tail -n +2)
pairs=$(echo -n "$lines" | awk '{split($9,a,":"); print $2":"a[2]}' | uniq)
format_string="%5s %5s %s\n"
if [ -n "$pairs" ]; then
printf "$format_string" "PORT" "PID" "COMMAND"
for pair in $pairs; do
mv /etc/localtime /etc/localtime-old
ln -sf /usr/share/zoneinfo/Asia/Taipei /etc/localtime
/sbin/hwclock --systohc
date
from urllib.request import urlopen
import bs4
def dreye_dict(word):
html = urlopen("http://yun.dreye.com/dict_new/dict.php?w=%s" % word).read().decode("utf-8")
bs = bs4.BeautifulSoup(html, "html.parser")
usualExps = bs.select(".sg.block")[0]
from urllib.request import urlopen
import bs4
import os.path
import openpyxl
# openpyxl: http://liyangliang.me/posts/2013/02/using-openpyxl-to-read-and-write-xlsx-files/
def yahoo_dict(word):
html = urlopen("https://tw.dictionary.search.yahoo.com/search?p=%s" % word).read().decode("utf-8")
bs = bs4.BeautifulSoup(html, "html.parser")
from urllib.request import urlopen
import bs4
while True:
word = input("Please type your word here: ")
html = urlopen("https://tw.dictionary.search.yahoo.com/search?p=%s" % word).read().decode("utf-8")
bs = bs4.BeautifulSoup(html, "html.parser")
explainArea = bs.select(".explain.DictionaryResults")[0]
wordClassList = explainArea.select(".compTitle")