Skip to content

Instantly share code, notes, and snippets.

from decimal import Decimal
bids = [int(a) for a in '60 62 60 56 56 57'.split('\t')]
print(bids)
price = min(bids)
total_payment = (len(bids) - 1) * price
total_bid = sum(bids) - price
min_pos = bids.index(price)
max_pos = bids.index(max(bids))
bids[min_pos] = 'min'
bids[max_pos] = 'max'
@taowen
taowen / gist:2568620
Created May 1, 2012 15:04
PPPoE Multiwan
# Dial
pppoecd vlan2 -u $user -p $password # wan1
pppoecd vlan2 -u $user -p $password # wan2
# Handle outgoing packet
# Make "ip route" contains a default route like this
# "ip route" final state
#default
# nexthop via $wan1_ip dev $wan1_dev weight 1 # such as 202.106.0.24 ppp0
@taowen
taowen / gist:2582586
Created May 3, 2012 02:20
m-route hotplug script
#!/bin/sh
# Copyright (C) 2009 Fabian Omar Franzotti <fofware@gmail.com>
# http://pastebin.ca/2098184
#
#include /lib/network
. /etc/functions.sh
. /lib/config/uci.sh
# 传入的参数有 INTERFACE, DEVICE ACTION
# ACTION有:ifup, update, ifdown, changeRoute
#include <numeric>
#include <algorithm>
#include <random>
#include <vector>
#include <iostream>
#include <limits>
typedef int V;
typedef std::vector<V> vi;
@taowen
taowen / StreamTracker.java
Created August 3, 2015 04:19
tracking multiple streams to tell if they are in sync
import backtype.storm.tuple.Tuple;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
public class StreamTracker {
import "github.com/modern-go/concurrent"
executor := concurrent.NewUnboundedExecutor()
executor.Go(func(ctx context.Context) {
everyMillisecond := time.NewTicker(time.Millisecond)
for {
select {
case <-ctx.Done():
fmt.Println("goroutine exited")
return
// set a logger to show who is blocking
concurrent.InfoLogger = log.New(os.Stdout, "", 0)
executor := concurrent.NewUnboundedExecutor()
executor.Go(func(ctx context.Context) {
everyMillisecond := time.NewTicker(time.Millisecond)
for {
select {
case <-ctx.Done():
// info log will be printed while we wait
time.Sleep(time.Second)
func ExampleUnboundedExecutor_Go_panic() {
concurrent.HandlePanic = func(recovered interface{}, funcName string) {
fmt.Println(funcName)
}
executor := concurrent.NewUnboundedExecutor()
executor.Go(willPanic)
time.Sleep(time.Second)
// output:
// github.com/modern-go/concurrent_test.willPanic
}
@taowen
taowen / main.lua
Created October 20, 2018 06:30
future in lua created by taowen - https://repl.it/@taowen/future-in-lua
function some_important_business_process(a, b)
result = a + b
c = 3
result = result * c
return result
end
result = some_important_business_process(1, 2)
print(result)
@taowen
taowen / main.lua
Created October 20, 2018 06:30
future in lua created by taowen - https://repl.it/@taowen/future-in-lua
function some_important_business_process(a, b)
result = a + b
c = 3
result = result * c
return result
end
result = some_important_business_process(1, 2)
print(result)