- 11
我是阿里云函数计算团队技术专家清宵,用动图撩一下大家吧~~大家好!

我的第83行代码来自这个简单的Life模型,非项目非社区贡献,纯业余时间自娱自乐。
看了《药神》之后,对人生的感悟加深。回来没有写什么观后感,却是随便写了一段代码,构造一个极其简单的人生模型,算作总结思考了。
人生如码,以梦为马。珍惜所爱,精彩过好每一天!
package main
import (
"fmt"
"math/rand"
"sync"
"time"
)
var (
r = rand.New(rand.NewSource(time.Now().Unix()))
disasterSignal = make(chan string)
accidentSignal = make(chan string)
diseaseSignal = make(chan string)
)
// Element : abstract factor which life consisted by
type Element interface {
Improve()
Depress()
Stable()
Enable() bool
BeAbleHandle(event string) bool
}
type Activity interface {
IsSuitable(life *Life) bool
Do(life *Life)
Interrupted()
}
type Life struct {
Sex string
Age time.Duration
Health Element
Knowledge Element
Ability Element
RelationShip Element
Wealth Element
OtherElement Element
Work Activity
Study Activity
Exercise Activity
Entertain Activity
Rest Activity
OtherActive Activity
isDoings []Activity
vitalitySignal chan struct{}
NaturalDeath chan struct{}
}
func (f *Life) Join(oppositeSex *Life, love, family Element) (*Life, error) {
if !love.Enable() || !family.Enable() || f.Sex == oppositeSex.Sex {
return nil, fmt.Errorf("Sorry, no boby should be borned!")
}
boby := &Life{
Sex: []string{"male", "female"}[r.Intn(2)],
Age: 0,
isDoings: []Activity{},
NaturalDeath: make(chan struct{}),
vitalitySignal: make(chan struct{}),
}
return boby, nil
}
func (f *Life) Run() {
go ExternalEndanger(f)
// time elapses day by day
for {
startTime := time.Now().UTC()
wg := &sync.WaitGroup{}
for _, active := range []Activity{f.Study, f.Work, f.Entertain, f.Exercise, f.Rest, f.OtherActive} {
if f.SuitableFor(active) {
wg.Add(1)
go func(activity Activity) {
defer wg.Wait()
activity.Do(f)
}(active)
}
}
select {
case <-f.NaturalDeath:
f.Close()
fmt.Println("Life is short, make it colourful and cherish the love around all!")
return
case <-f.vitalitySignal:
fmt.Println("记得买保险!")
return
case <-time.After(24*time.Hour - time.Now().UTC().Sub(startTime)):
fmt.Println("One day went by...")
}
//wg.Wait()
f.Age += 24 * time.Hour
}
fmt.Println("Goodbye, life!")
}
func (f *Life) Somehow() {
// happened something to effect one to reach some life stage
}
func (f *Life) SuitableFor(active Activity) bool {
return active.IsSuitable(f)
}
func (f *Life) Survive(event string) bool {
for _, e := range []Element{f.Health, f.Knowledge, f.Ability, f.RelationShip, f.Wealth, f.OtherElement} {
if !e.BeAbleHandle(event) {
return false
}
}
return true
}
func (f *Life) Close() {
for _, doing := range f.isDoings {
doing.Interrupted()
}
close(f.vitalitySignal)
}
var female = LifeFromSomeWhere("female")
var male = LifeFromSomeWhere("male")
func ExternalEndanger(f *Life) {
for {
event := ""
select {
case event = <-diseaseSignal:
case event = <-disasterSignal:
case event = <-accidentSignal:
}
if !f.Survive(event) {
f.Close()
return
}
}
}
func LifeFromSomeWhere(sex string) *Life {
life := &Life{Sex: sex}
life.Somehow()
return life
}
func main() {
// I don't know the question of "鸡生蛋 or 蛋生鸡"...
newLife, err := female.Join(male, ElementImp{Type: "love"}, ElementImp{Type: "family"})
if err != nil {
newLife.Run()
}
} 发布时间:23小时前 19人评论
- 8
大家好,我是饿了么大前端的打杂工程师敖天羽。
照片:
别的小姐姐们晒得代码都太厉害了……只有我是来搞笑的,前年情人节的单身狗翻译器代码,两块钱你买不了吃亏,两块钱你买不了上当:
const pinyin = require('pinyin');
const program = require('commander');
const translate = require('./translator');
program
.version('0.0.5')
.description('单身狗汪化翻译机,把你的话都变成汪星语')
.option('-e --emoj', '使用emoj来替代汉字汪')
.option('-i --stdin', '传输标准输入流文本而不是命令行参数')
.option('-c --clip', '自动复制到剪贴板(文本过大慎用)')
.parse(process.argv);
const word = !program.emoj;
const clip = program.clip;
if (program.stdin) {
process.stdin.setEncoding('utf-8');
process.stdin.on('readable', () => {
let chunk = process.stdin.read();
if (chunk !== null) {
translate(chunk, word, clip);
}
});
} else {
if (program.args.length > 0) {
translate(program.args[0], word, clip);
process.stdout.write(`\n`);
}
else
program.outputHelp();
}
对了,新晋花名「天汪」,请多多指教汪。(路过,给各位小姐姐们端茶送水)
发布时间:22小时前 5人评论- 2
海洋的云
已获得83行代码限量T恤
平时习惯于用Jupyter Notebook写代码,以至于很多代码像是这样:
# 分块计算缺失程度(23块)
block_list = [1,5,6,20,24,28,32,36,48,52,54,64,72,76,102,107,111,155,161,166,211,254,278,298]
for i in tqdm(range(len(block_list)-1)):
tmp_df = train_test.iloc[:,block_list[i]-1:block_list[i+1]-1]
print(tmp_df.columns)
tmp_df_T = tmp_df.T
tmp_df['count'] = tmp_df_T.count()
train_test['count_f' + str(block_list[i]) + '_f' +str(block_list[i+1])] = tmp_df['count']
train_test['count_label_f' + str(block_list[i]) + '_f' +str(block_list[i+1]-1)]=np.where(train_test['count_f' + str(block_list[i]) + '_f' +str(block_list[i+1])] > 0,0,1)
# 计算占比(基于date)
for i in tqdm(r_list):
df_dratio = pd.DataFrame()
for j in date_list:
df_tmp = train_test[train_test['date'] == j]
f_ratio = pd.DataFrame(df_tmp[i].value_counts())
f_ratio['date'] = j
f_ratio[i + '_rcount'] = f_ratio[i]
f_ratio[i + '_ratio'] = f_ratio[i]/len(df_tmp)
f_ratio[i] = f_ratio.index
f_ratio = f_ratio.reset_index(drop = True)
df_dratio = pd.concat([df_dratio, f_ratio], axis = 0)
df_dratio = df_dratio.reset_index(drop = True)
train_test = train_test.merge(df_dratio,on = ['date',i],how = 'left')
比较喜欢的一段代码是这样:
import copy
def cal_all_altcol_1(col_, labelcol = None, error_corr = False):
# if labelcol is not None:
# print("pcsing by groups")
col = copy.deepcopy(col_)
colname = col.columns[0]
if(error_corr == True):
if labelcol is not None:
mean = pd.DataFrame(calmean(col, labelcol))
alt_col = [col, 1 / col, col-mean, np.fabs(col-mean)]
alt_col_name = [colname + "_X", colname + "_1/X", colname + "_Xerr", colname + "_Xerr_abs"]
else:
mean = calmean(col, labelcol)
alt_col = [col, 1 / col, np.fabs(col-mean)]
alt_col_name = [colname + "_X", colname + "_1/X", colname + "_Xerr_abs"]
elif(error_corr == False):
alt_col = [col , 1 / col]
alt_col_name = [colname + "_X", colname + "_1/X"]
alt_list = pd.concat(alt_col, axis = 1)
alt_list.columns = alt_col_name
return alt_list
def cal_all_altcol_1_base(col_, labelcol = None, error_corr = False):
# 只取正负列
# if labelcol is not None:
# print("pcsing by groups")
col = copy.deepcopy(col_)
colname = col.columns[0]
if(error_corr == True):
if labelcol is not None:
mean = pd.DataFrame(calmean(col, labelcol))
alt_col = [col, np.fabs(col-mean), col-mean, ]
alt_col_name = [colname + "_X", colname + "_Xerr_abs", colname + "_Xerr"]
else:
mean = pd.DataFrame(calmean(col, labelcol))
print(mean)
alt_col = [col, np.fabs(col-mean)]
alt_col_name = [colname + "_X", colname + "_Xerr_abs"]
elif(error_corr == False):
alt_col = [col]
alt_col_name = [colname + "_X"]
alt_list = pd.concat(alt_col, axis = 1)
# print (alt_list)
alt_list.columns = alt_col_name
return alt_list
def cal_all_altcol_2(col_i, col_j, labelcol = None, error_corr = False):
# if labelcol is not None:
# print("pcsing by groups")
coli = copy.deepcopy(col_i)
colj = copy.deepcopy(col_j)
coliname = coli.columns[0]
coljname = colj.columns[0]
colbet = coliname + "_" + coljname
coli.columns, colj.columns = [colbet], [colbet] # 需要把列名统一不然不能直接减
Plus = coli + colj
Minus = coli - colj
Multiply = coli * colj
Divide_1 = coli / colj
Divide_2 = colj / coli
everynum_perpart = 5
if(error_corr == True):
P_mean = pd.DataFrame(calmean(Plus, labelcol))
Mi_mean = pd.DataFrame(calmean(Minus, labelcol))
Mu_mean = pd.DataFrame(calmean(Multiply, labelcol))
D1_mean = pd.DataFrame(calmean(Divide_1, labelcol))
D2_mean = pd.DataFrame(calmean(Divide_2, labelcol))
if labelcol is not None:
alt_col = [Plus, Minus, Multiply, Divide_1, Divide_2,
np.fabs(Plus - P_mean), np.fabs(Minus - Mi_mean), np.fabs(Multiply - Mu_mean),
np.fabs(Divide_1 - D1_mean), np.fabs(Divide_2 - D2_mean),
Plus - P_mean, Minus - Mi_mean, Multiply - Mu_mean,Divide_1 - D1_mean, Divide_2 - D2_mean]
alt_col_name = [colbet + "_X+Y", colbet + "_X-Y", colbet + "_X*Y", colbet + "_X/Y", colbet + "_Y/X",
colbet + "_X+Yerr_abs", colbet + "_X-Yerr_abs", colbet + "_X*Yerr_abs",
colbet + "_X/Yerr_abs", colbet + "_Y/Xerr_abs",
colbet + "_X+Yerr", colbet + "_X-Yerr", colbet + "_X*Yerr",
colbet + "_X/Yerr", colbet + "_Y/Xerr",]
elif labelcol is None:
alt_col = [Plus, Minus, Multiply, Divide_1, Divide_2,
np.fabs(Plus - P_mean), np.fabs(Minus - Mi_mean), np.fabs(Multiply - Mu_mean),
np.fabs(Divide_1 - D1_mean), np.fabs(Divide_2 - D2_mean)]
alt_col_name = [colbet + "_X+Y", colbet + "_X-Y", colbet + "_X*Y", colbet + "_X/Y", colbet + "_Y/X",
colbet + "_X+Yerr_abs", colbet + "_X-Yerr_abs", colbet + "_X*Yerr_abs",
colbet + "_X/Yerr_abs", colbet + "_Y/Xerr_abs"]
elif(error_corr == False):
alt_col = [Plus, Minus, Multiply, Divide_1, Divide_2]
alt_col_name = [colbet + "_X+Y", colbet + "_X-Y", colbet + "_X*Y", colbet + "_X/Y", colbet + "_Y/X"]
alt_list = pd.concat(alt_col, axis = 1)
alt_list.columns = alt_col_name
# print(alt_list)
return alt_list
# def cal_all_alt2tol(coli, colj, )
# cal_all_altcol_2(test, test2)
发布时间:24小时前 6人评论
- 4
我是钉钉smart work团队的高级开发专家,花名采霜,工作一忙有时候饭也顾不上吃,顺手写一段终结选择困难症的代码,大家随意看看~
# -*- coding:utf-8 -*-
import random
what_to_eat = ['牛肉拉面', '麻辣烫', '麻辣香锅', '重庆小面', '水饺', '沙拉', '煎饼果子', '米线', '盖浇饭', '凉皮肉夹馍', '粥+煎饺', '寿司', '石锅拌饭']
random.shuffle(what_to_eat)
what_to_eat_this_week = random.sample(what_to_eat, 5)
for index in range(len(what_to_eat_this_week)):
print('周' + str(index + 1) + ':' + what_to_eat_this_week[index])
知道大家想看的是照骗~ 海报里面的C位就是我,想和我一起工作么,钉钉smart work团队诚招java、ios、安卓、前端以及产品经理。有意者简历到caishuang@alibaba-inc.com,有投必回
- 3
我是云效的全栈开发女工程师,朱默,花名:墨瑜。
据说认真工作的程序员魅力值加10:
我的第83行代码来自云效RDC上某一功能的代码, 猜猜是哪个功能:
public class MysqlLockBuilder {
private DataSource dataSource;
private String mysqlTableName;
private LockDataAccessor lockDataAccessor;
private LockStateAccessor lockStateAccessor;
private String defaultClientId;
public void init() throws SQLException {
MysqlLockDataAccessor mysqlLockDataAccessor = new MysqlLockDataAccessor();
mysqlLockDataAccessor.setMysqlTableName(mysqlTableName);
mysqlLockDataAccessor.setConnection(dataSource.getConnection());
lockDataAccessor = mysqlLockDataAccessor;
defaultClientId = IP.getIpAddr();
lockStateAccessor = buildMysqlLockStateAccessor();
}
private LockStateAccessor buildMysqlLockStateAccessor() throws SQLException {
MysqlLockStateAccessor lockStateAccessor = new MysqlLockStateAccessor();
lockStateAccessor.setMysqlTableName(mysqlTableName);
lockStateAccessor.setConnection(dataSource.getConnection());
lockStateAccessor.init();
return lockStateAccessor;
}
public String getDefaultClientId() {
return defaultClientId;
}
public void setDefaultClientId(String defaultClientId) {
this.defaultClientId = defaultClientId;
}
public TimedLock lockForAWhile(String lockId, int timeout) throws LockAccessException {
TimedLock lock = new TimedLock(lockId, defaultClientId, timeout);
try {
lock.setLockStateAccessor(buildMysqlLockStateAccessor());
lock(lock);
return lock;
} catch (SQLException e){
lock.close();
throw new LockAccessException(e);
} catch (LockAccessException e) {
lock.close();
throw e;
}
}
public ScopedLock lockWhenAlive(String lockId) throws LockAccessException {
ScopedLock lock = new ScopedLock(lockId, defaultClientId);
try {
lock.setLockStateAccessor(buildMysqlLockStateAccessor());
lock(lock);
return lock;
} catch (SQLException e){
lock.close();
throw new LockAccessException(e);
} catch (LockAccessException e){
lock.close();
throw e;
}
}
/**
* 指定clientId,加时间锁
* @param lockId: 锁名称
* @param timeout: 加锁时长
* @param clientId: 锁的持有者
* @return
* @throws LockAccessException
*/
public TimedLock lockForAWhileByClient(String lockId, int timeout, String clientId) throws LockAccessException {
TimedLock lock = new TimedLock(lockId, clientId, timeout);
try {
LockStateAccessor timeLockStateAccessor = buildMysqlLockStateAccessor();
lock.setLockStateAccessor(timeLockStateAccessor);
lock(lock);
return lock;
} catch (SQLException e){
lock.close();
throw new LockAccessException(e);
} catch (LockAccessException e) {
lock.close();
throw e;
}
}
/**
* 刷新时间锁,延长加锁时长
* @param lockingContext
* @return
* @throws LockAccessException
*/
public Boolean refreshTimeLockByContext(LockingContext lockingContext) throws LockAccessException {
if(lockStateAccessor == null){
try {
lockStateAccessor = buildMysqlLockStateAccessor();
}catch (SQLException e) {
throw new LockAccessException(e);
}
}
return lockStateAccessor.refreshTimeLock(lockingContext);
}
/**
* 手动解锁
* @param lockingContext
* @return
* @throws LockAccessException
*/
public Boolean unlockTimeLockByContext(LockingContext lockingContext) throws LockAccessException {
if(lockStateAccessor == null){
try {
lockStateAccessor = buildMysqlLockStateAccessor();
}catch (SQLException e) {
throw new LockAccessException(e);
}
}
return lockStateAccessor.timedUnlock(lockingContext);
}
/**
* 根据锁id,获取时间锁信息
* @param lockId
* @return
* @throws LockAccessException
*/
public LockingInfo getTimedLockInfo(String lockId) throws LockAccessException{
return lockStateAccessor.getTimedLockingInfo(lockId);
}
private void lock(Lockable lock) throws LockAccessException {
try {
lockDataAccessor.createIfNotPresent(lock.id());
boolean locked = lock.lock();
if (!locked) {
throw new LockAccessException("Lock has been occupied");
}
} catch (Exception e) {
throw new LockAccessException(e);
}
}
public String getMysqlTableName() {
return mysqlTableName;
}
public void setMysqlTableName(String mysqlTableName) {
this.mysqlTableName = mysqlTableName;
}
public void setDataSource(DataSource dataSource) {
this.dataSource = dataSource;
}
public DataSource getDataSource() {
return dataSource;
}
} 发布时间:19小时前 5人评论
- 2
cn_suqingnian
已获得83行代码限量T恤
在下*的程序媛,平时喜欢自己写点宏文件……最喜欢自己写的啦
照片:
听说要爆照然后:
/*by Qingnian Su,Only want to write sonething useful*/
#ifndef suqingnian
#define suqingnian
template<typename _Element_pow>
_Element_pow
_pow(_Element_pow _a,_Element_pow _b,_Element_pow _mod)
{
_Element_pow _res=1;
for(;_b;_b >>= 1, _a= _a * _a % _mod)
if(_b & 1) _res = _res * _a % _mod;
return _res ;
}
template<typename _Element_gcd>
_Element_gcd
_gcd(_Element_gcd _m, _Element_gcd _n)
{
while (_n != 0)
{
_Element_gcd _t = _m % _n;
_m = _n;
_n = _t;
}
return _m;
}
bool __check[1000010];
int __size;
int _num[1000010];
void _prime(int __n)
{
for(int _i=2;_i<=__n;_i++)
{
if(!__check[_i]) _num[__size++]=_i;
for(int _j=0;_j<__size;_j++)
{
if(_i*_num[_j]>__n) break;
__check[_num[_j]*_i]=1;
if(_i%_num[_j]==0) break;
}
}
return ;
}
bool _isprime(int __n) {return ~__check[__n];}
#include<cstdio>
template<typename _Element_stack>
struct _stack{
_Element_stack __st[100010];
int __size_st;
void __push(_Element_stack __x)
{__st[++__size_st]=__x;return ;}
void __pop()
{__size_st--;return ;}
_Element_stack __top()
{return __st[__size_st];}
bool _empty() {return __size_st==0;}
};
#endif
#endif 发布时间:20小时前 2人评论
- 0
难道这只是妹子间的游戏,不允许大叔参与。
发布时间:24小时前 2人评论- 2
听说程序媛这个物种十分罕见,我是作为罕见中的一员happy(被)来(逼)的,毕业几年的人生感悟:每个人在浩瀚的宇宙中都有自己独特的坐标,这个坐标会因为你的选择而变的不同,同样这个世界也会因为你坐标的移动而变得不同!SO,COME ON 加入我们,让我们一起改变世界,成就更好的自己!我在tmall一直等你!caiyue@tmall.com 
package tmall;
import lombok.*;
/**
- Created by caiyue on 2018/7/16.
*/
@AllArgsConstructor
class Business {
private String buName, salary, awardMoney, mission, colleague;
public Person change(Person p) {return p;}
public String toString() {
return buName + "公司:[工资:" + salary + ",奖金:" + awardMoney + ",同事:" + colleague + ",使命:" + mission + "]";
}
}
@Data
@AllArgsConstructor
class Person {
private String role, x, y, z;
public String toString() {return role + ":[" + x + "、" + y + "、" + z + "]";}
}
class TmallBu extends Business {
public TmallBu(String buName, String salary, String awardMoney, String misson, String colleague) {
super(buName, salary, awardMoney, misson, colleague);
}
public Person change(Person p) {
switch (p.getRole()) {
case "程序媛":
return new Person(p.getRole(), "人美", "码赞", "会生活");
case "程序员":
return new Person(p.getRole(), "人帅", "钱多", "疼老婆");
default:
return new Person(p.getRole(), "坐标丢失", "坐标丢失", "坐标丢失");
}
}
}
public class TransformAll {
public static void main(String[] args) {
Business tmall = new TmallBu("天猫", "五颗星", "五颗星", "改变自己改变世界", "一群有情有义的人");
Person ordinaryGirl = new Person("程序媛", "定位自我", "找寻理想", "探索生活意义");
Person tmallProgrammerGirl = tmall.change(ordinaryGirl);
System.out.println(tmall.toString());
System.out.println(tmallProgrammerGirl.toString());
System.out.println("欢迎来天猫一起成为更好的自己!");
}
}
发布时间:5小时前 1人评论- 0
要是参与。。能得妹子不?
发布时间:24小时前 1人评论- 1
嘿嘿
发布时间:9小时前 0人评论- 1
能在这个行业坚持不懈,不容易的程序媛
发布时间:19小时前 0人评论- 0
这么好
发布时间:3小时前 0人评论- 0
女人是上帝开发的艺术品。
女人的代码是什么呢?
- 0
嗯哼,强势仰望大佬中
发布时间:4小时前 0人评论- 0
大家好,我是贵州九丰农业公司苏培军
发布时间:4小时前 0人评论- 0
挺好的
发布时间:5小时前 0人评论- 0
钓鱼可以么
发布时间:6小时前 0人评论- 0
留下足迹才美丽
发布时间:7小时前 0人评论- 0
正在通往程序员的道路中
发布时间:17小时前 0人评论- 0
奖品上来就是20个,大气!
发布时间:23小时前 0人评论