- 博客(99)
- 收藏
- 关注
转载 golang 一行一行读文件
package mainimport ( "bufio" "fmt" "os")func main() { counts := make(map[string]int) files := os.Args[1:] if len(files) == 0 { count
2017-04-11 19:33:26
6278
转载 golang LRU实现(使用双向链表实现)
LRU(Least recently used,最近最少使用)算法根据数据的历史访问记录来进行淘汰数据,其核心思想是“如果数据最近被访问过,那么将来被访问的几率也更高”。lru.gotype Key interface{}type entry struct { key Key value interface{} } type Cache Str
2017-03-27 17:27:08
1565
转载 golang chan 使用例子
type TcpListeners struct { conns chan *net.TCPConn closing chan bool wait *sync.WaitGroup}func NewTcpListeners(addrs []string) (v *TcpListeners, err error) { v = &TcpListeners{
2017-03-24 18:31:07
728
转载 golang 线程池下载
type GoroutinePool struct { 2 Queue chan func() error 3 Number int 4 Total int 5 6 result chan error 7 finishCallback func() 8 } 9 10 // 初始化11 func (self *Goro
2017-03-24 17:30:11
557
转载 golang 线程池
package mainimport "fmt"func worker(id int, jobs chan int, results chan int) { for j := range jobs { fmt.Println("worker", id, "procesing job", j) results <
2017-03-24 17:12:58
1346
转载 golang json处理
package mainimport ( "encoding/json" "fmt" "os")type ConfigStruct struct { Host string `json:"host"` Port int `json:"port"` AnalyticsFile string `json
2017-03-24 16:04:57
690
转载 golang使用信号量热更新
package mainimport ( "encoding/json" "fmt" "io/ioutil" "log" "os" "os/signal" "sync" "syscall")//用json配置测试type Config struct { Test1 string `json:"Test1:`
2017-03-20 18:25:46
2249
原创 1-100 分成10组计算算法
import "fmt"func test(){ fmt.Println("hello") sum := 0 for i := 0; i <= 100; i++{ sum += i } fmt.Println(sum)}/*这里不计算最后一个数字*/func count(
2017-03-20 18:12:12
4113
原创 python curses
#!/usr/bin/env pythonfrom os import systemimport cursesdef get_param(prompt_string): screen.clear() screen.border(0) screen.addstr(2, 2, prompt_string) screen.refresh() i
2017-02-07 15:52:01
459
原创 socket 访问百度
#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include
2016-06-14 18:10:10
1375
原创 穷举破解linux登录密码
适用于以root用户登录后执行代码,密码存放在password.txt中,读取/etc/shadow内容,解密加密后密码# -*- coding: utf-8 -*-import osimport cryptimport timeimport multiprocessingdef decrypt_linux_passwd(find_user, salt, passwd): p
2016-02-16 18:03:46
1063
原创 python 将一维列表转二维列表
增加并发性的需求, 将一维列表转为二维列表if __name__ == "__main__": fd = open("domains.txt") domains = [] domains = [domain.strip() for domain in fd.readlines() if domain.strip()] n = 1 send_count =
2016-02-16 17:56:23
12409
转载 linux select例子
#include #include #include #include #include #include #include #include #include #define MYPORT 1234 // the port users will be connecting to#define BACKLOG 5 // how many pending con
2015-12-16 12:31:03
418
原创 python学习第四天
wxpython写的计算器#!/usr/bin/env python# -*- coding: utf-8 -*-# -*- coding: utf-8 -*-才能支持中文import osimport wxclass MainWindow(wx.Frame): """docstring for MainWindow""" def __init__(self, paren
2015-08-24 23:39:41
467
原创 python学习第三天
网上找了个 TextCtrl 单行文本框的例子, 挺好,保存下来#!/usr/bin/env python#coding:UTF-8import wxclass TextFrame(wx.Frame): def __init__(self): wx.Frame.__init__(self,None,-1,u"请登录", size=(400,400))
2015-08-22 23:17:35
638
原创 python学习第二天
今天用wxpython 实现简单的menu、 button 并为其绑定点击事件和对话框输出,很简单, 但还是需要好好体会#!/usr/bin/env python# -*- coding: utf-8 -*-# -*- coding: utf-8 -*-才能支持中文import osimport wxclass MainWindow(wx.Frame): def __init
2015-08-16 22:42:50
703
原创 python学习第一天
在windows 上搭建 python、wxpython、py2exe 需要下载的软件有: 1:首先安装python-2.7.10,然后其它顺序无所谓,2:全部安装完毕后 配置环境变量,出现下图说明安装成功 3:先来个hello world爽爽#! /usr/bin/env python#-*- encoding: utf-8 -*-#autho
2015-08-15 14:23:04
497
转载 Linux下更改转移mysql数据库目录
【MySql】Linux下更改转移mysql数据库目录 (2013-11-26 15:42:26)转载▼ 分类: mysql1、关闭MySql: #service mysqld stop2、转移数据: #cd /var/lib #ls #cp -a mysql /opt/mysq
2015-08-12 18:26:53
457
原创 linux c select函数使用求解释
代码很简单,就是发送c语言发送http请求,但 i= read(sockfd, buf, BUFSIZE-1); 可以正常运行, 替换为i= Read(sockfd, buf, BUFSIZE-1);后程序退出,不知什么原因,求解答。#include #include #include #include #include #include #include #incl
2015-06-04 18:22:57
891
原创 20150527
#include #define QLEN 100/************************************************************************/ /* * 正整数序列Q中的每个元素都至少能被正整数a和b中的一个整除,现给定a和b, * 需要计算出Q中的前几项,例如,当a=3,b=5,N=6时,序列为3,5,6,9,10,12 *
2015-05-27 18:01:05
554
原创 分析能力亟待加强
问题:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA打印10行A, 每行递增一个,最后一行10个A我的解决方案:package mainimport "fmt"func main() { str := "A" for i := 0; i < 1
2015-04-27 17:14:21
572
转载 数据结构(C实现)------- 图的邻接矩阵表示
http://blog.youkuaiyun.com/jesson20121020/article/details/42467797
2015-01-07 13:43:46
754
原创 Copy-On-Write 写时复制原理
linux内核在使用fork创建进程时,基本上会使用Copy-On-Write(COW)技术。这里解释一下COW技术以及为什么在fork中使用。WIKI上对COW的解释:Copy-on-write (sometimes referred to as "COW") is an optimization strategy used in computer programming.
2014-04-01 19:10:54
17895
1
转载 kernel: TCP: time wait bucket table overflow错误的解决办法
kernel: TCP: time wait bucket table overflow错误的解决办法现象为message日志报如下错误:Feb 27 10:53:36 web kernel: __ratelimit: 5 callbacks suppressedFeb 27 10:53:36 web kernel: TCP: time wait bucket tabl
2014-03-14 18:45:50
5018
转载 linux下TIME_WAIT过多的解决办法(ip_local_port_range)(转)
p.s. 最近nginx不正常,表现为首次打开的时候会很慢或者干脆打不开,要刷新下才能继续。fast-cgi的TIME_WAIT比较多5百左右,占到总连接 4分之1。试试是不是ip_local_port_range问题,原则就是不与本地已经使用的端口范围冲突,设置端口 2**** 到 4**** 。 (重启系统需要重新设置)如 果使用了nginx代理,那么系统TIME_WAIT的数量会
2014-03-14 18:14:30
11877
转载 有空分析下,链表很牛逼
/*********************** Licence: MIT* Author: Leo Ma* Date: 2014-03-01*********************/#include #include struct sk_link { struct sk_link *next, *prev;};static inline voidskip_list
2014-03-12 19:01:15
766
原创 linux 下磁盘满问题
df -h显示/home空间被占用100G,但是du -sh统计出来的结果却是/home分区下所有文件总共只占用2G的大小。 非常奇怪的情况。 后来用lsof /home | grep -i delete 查找了一下终于发现问题的关键所在。 存在很多已被删除的文件占用磁盘。 造成这种情况的原因是什么呢
2014-02-19 19:01:40
880
转载 20140208完成博客
字符串分割 总结 std::string::size_type spos = 0, epos = 0; int len = strlen(SYSTEM_UID_SPLIT); std::string tmp_uids(""); while ( (epos = systemuids.find(SYSTEM_UID_SPLIT, spos)) != std::
2014-02-08 15:07:57
812
原创 linux 下mysql忘记密码
1.首先确认服务器出于安全的状态,也就是没有人能够任意地连接MySQL数据库。 因为在重新设置MySQL的root密码的期间,MySQL数据库完全出于没有密码保护的 状态下,其他的用户也可以任意地登录和修改MySQL的信息。可以采用将MySQL对 外的端口封闭,并且停止Apache以及所有的用户进程的方法实现服务器的准安全 状态。最安全的状态是到服务器的Console上面操作,并且
2014-01-20 17:48:33
709
原创 改掉几个使用Linux命令习惯
好的习惯可以提高工作效率以及命令的运行效率1:创建目录习惯~ $ mkdir tmp~ $ cd tmp~/tmp $ mkdir a~/tmp $ cd a~/tmp/a $ mkdir b~/tmp/a $ cd b~/tmp/a/b/ $ mkdir c~/tmp/a/b/ $ cd c~/tmp/a/b/c $应使用:mkdir -p tmp/a/b/c
2014-01-14 15:37:13
1217
转载 linux下 mysql data目录迁移
错误提示 100716 3:35:54 [Warning] Can't create test file /home/data/mysql/localhost.lower-test100716 3:35:54 [Warning] Can't create test file /home/data/mysql/localhost.lower-test/usr/sbin/mysqld:
2014-01-09 19:24:52
4904
转载 md5值计算方式
shell中计算字符串的md5值echo 123|md5sumba1f2511fc30423bdbb183fe33f3dd0f - php -r "echo md5('123');"202cb962ac59075b964b07152d234b70两者的md5值不一致,于是有很多有趣的解法:1 Mysql解法:mysql> select md5('123');+--
2013-11-29 14:24:56
1116
原创 ping 原理
假定主机A的IP地址是192.168.1.1,主机B的IP地址是192.168.1.2,都在同一子网内,则当你在主机A上运行“Ping 192.168.1.2”后,都发生了些什么呢? 首先,Ping命令会构建一个固定格式的ICMP请求数据包,然后由ICMP协议将这个数据包连同地址“192.168.1.2”一起交给IP层协议(和ICMP一样,实际上是一组后台运行的进程),IP层协议将以
2013-10-09 19:38:20
1053
原创 动手写快排
自己写了一篇才知道,原来的理解是错误的并不是high指针和low指针交换,而是直接赋值一直理解错误,郁闷#include #define SIZE_OF_ARRAY(x) (sizeof(x)/sizeof(x[0]))void print_array(int array[], int len){ //printf("%d\n", SIZE_OF_
2013-10-08 19:35:52
884
转载 异步 与非阻塞概念
老张爱喝茶,废话不说,煮开水。出场人物:老张,水壶两把(普通水壶,简称水壶;会响的水壶,简称响水壶)。1 老张把水壶放到火上,立等水开。(同步阻塞)老张觉得自己有点傻2 老张把水壶放到火上,去客厅看电视,时不时去厨房看看水开没有。(同步非阻塞)老张还是觉得自己有点傻,于是变高端了,买了把会响笛的那种水壶。水开之后,能大声发出嘀~~~~的噪
2013-09-11 19:44:29
721
原创 经典领悟
1、父子二人经过五星级饭店门口,看到一辆十分豪华的进口轿车。儿子不屑地对他的父亲说:「坐这种车的人,肚子里一定没有学问!」父亲则轻描淡写地回 答:「说这种话的人,口袋里一定没有钱!」(注:你对事情的看法,是不是也反映出你内心真正的态度?)2、晚饭后,母亲和女儿一块儿 洗碗盘,父亲和儿子在客厅看电视。突然,厨房里传来打破盘子的响声,然后一片沉寂。是儿子望着他父亲,说道:「一定是妈妈打破的。」
2013-08-28 19:30:29
897
原创 职场名言
俗话说得好:会干的不如会说的。你想仅仅凭着熟练的技能和勤恳的工作,就在职场游刃有余、出人头地,未免有些天真了。虽然能力加勤奋很重要,但会说 话,却能让你工作起来更轻松,并且可能帮助你加薪、升职。1、应答上司交代的工作:我立即去办。冷静、迅速地做出这样的回应,会让上司直观地感觉你是一个工作讲效率、处理问题果断,并且服从领导的好下属。如果你犹豫不决,只会让上司不快,会给上司 留下优柔寡
2013-08-28 16:32:19
996
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人