ITeye博客

日子头上一把刀--DRY&&KISS

wudixiaotie · 共 155 篇文章

erlang mnesia

mnesia: 1.查询语句如果是用qlc来编译查询语句的话需要在module中引用qlc库的头文件: -include_lib("stdlib/include/qlc.hrl”). 2.一个表的默认主见就是record声明的第一个属性,更新和删除操作都是以他为依据的例如表名为users的表删除时: ```erlang -record(users, {id, name, address, mobile, email}). del(Id) -> Key = {users, Id), Trans = fun() -> mnesia:delete(Key) end, mnesia:transact…

2015-01-11 13:52 · erlang · 评论(0)

erlang spawn_link

```erlang -module (test). -compile(export_all). a() -> PidB = spawn_link(fun() -> b() end), PidC = spawn_link(fun() -> c() end), {PidB, PidC}. b() -> receive after 2000 -> io:format("I'm b!~n"), b() end. c() -> receive after 2000 -> io:format("I'm c!~n"), c() end. ``` 在shell中运行{PidB, PidC} = test:a…

2015-01-11 13:48 · erlang · 评论(0)

rails缓存清空

rails清空缓存:rake tmp:cache:clear。 工作当中遇到了这种情况,由于网站图片切换,为了不修改代码,直接把图片内容替换了,没改名字,结果好多图片显示一半,开始以为是css的事,结果前端看了说css没问题,后来以为是图片的事,结果把图片拿出来单独写个静态的html,发现图片没问题,那就只能是rails的环境的事了,怀疑可能是缓存的事,上网找了清空缓存的命令,一试果真成功了。

2014-12-31 11:17 · Rails · 评论(1)

erlang 遇到的小问题

1.启动节点如果想用全名启动,用-name的话直接写: ```erlang erl -name gandalf -setcookie abc ``` 会报错:"Can't set long node name!\nPlease check your configuration\n" 查看了erlang的邮件列表,大概的意思是用简称的话只能用-sname,用-name的话必须要写成 name@host的形式。 ```erlang erl -name gandalf@localhost -setcookie abc ``` 2.如果用与分布式erlang的话,启动时最好是写成如下方式: ```s…

2014-12-27 19:26 · erlang · 评论(0)

erlang关于Pattern Matching the Fields of a Map

```erlang 1> Henry8 = #{ class => king, born => 1491, died => 1547 }. #{ born => 1491, class=> king, died => 1547 }. 2> #{ born => B } = Henry8. #{ born => 1491, class=> king, died => 1547 }. 3> B. 1491 ``` 这是erlang之父写的书的第二版,里面的代码,可是第二个命令行的语法是错误的,如果你按这个方式输入,会在shell里面报错:illegal pattern。应该用下面的写法。 ```…

2014-12-06 10:54 · erlang · 评论(0)

关于列表相加\

```erlang A = [{a,0},{b,0},{c,1}]. B = [{x,0},{y,0},{z,1}]. C = [A|B] % C=[[{a,0},{b,0},{c,1}],{x,0},{y,0},{z,1}]. ``` 因为 [A|B] 的意思是把A作为一个列表元素加入到新的列表中。所以是列表嵌套着列表。 如果是列表相加那么可以这么写: ```erlang A = [{a,0},{b,0},{c,1}]. B = [{x,0},{y,0},{z,1}]. D = A ++ B % D=[{a,0},{b,0},{c,1},{x,0},{y,0},{z,1}]. ```

2014-12-05 22:20 · erlang · 评论(0)

erlang bit

二进制当然是以位为单位的。一个字节(byte)是8位(bit),一位就是一个(0或1)。定义二进制是<<E1,E2,....,EN>>,每个逗号区分一个片段。一个片段的组成是这样的:Value:Size/Type,Size和Type可疑不写。一个片段的长度是Size*Unit。binary的长度必须是8的整数倍。integer,float,bitstring,bits的unit长度默认是1,binary的默认是8。 ```erlang <<1:8>> ``` 如果不指定unit或者value的类型,size的单位就是1bit

2014-12-03 19:20 · erlang · 评论(0)

About Tail Recursion(关于尾递归)

为了锻炼英语水平,为以后出国工作提前准备,我就用英文写了,也没查字典,可能有语法错误,欢迎大家指正。。 When we have to recursion we always prefer to use loop rather than recursion. Because when the recursion goes deep the stack will always overflow. Its like a nightmare to us. Why stack always overflow? Look at the code below. ```erlang normal(N) w…

2014-12-01 10:28 · erlang · 评论(0)

javascript直接把base64的字符串转换成图片显示在网页上的方法

<!DOCTYPE html> <html> <head> <title></title> <script type="text/javascript" src="http://su.bdimg.com/static/superplus/js/lib/jquery-1.10.2_d88366fd.js"></script> <script type="text/javascript"> $(function() { var img_str = "iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIB…

2014-11-17 17:48 · JavaScript · 评论(0) · JavaScript

RAILS自动测试环境部署

gemfile # source 'https://rubygems.org' source 'http://ruby.taobao.org' ruby '2.1.1' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' gem 'rails', '4.1.7' # Use sqlite3 as the database for Active Record gem 'sqlite3' # Use SCSS for stylesheets # gem 'sass-rails', '~> 4.0.3' # Use Ugl…

2014-11-15 14:42 · Rails · 评论(0)

ruby的变量浅谈

a = 1 puts "a = #{a}; a.object_id: #{a.object_id}" # =》 a = 1; a.object_id: 3 def abc(a) puts "a = #{a}; a.object_id: #{a.object_id}" # =》 a = 1; a.object_id: 3 a = 2 puts "a = #{a}; a.object_id: #{a.object_id}" # =》 a = 2; a.object_id: 5 end abc(a) puts "a = #{a}; a.object_id: #{a.object_id}" # =》…

2014-11-12 18:05 · ruby · 评论(0)

leetcode的一道题--Trapping Rain Water

Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining. For example, Given [0,1,0,2,1,0,1,3,2,1,2,1] , return 6 . The above elevation map is represented by array [0,1,0,2,1,0,1,3,2,1,2,1]. In this case, 6…

2014-11-11 17:46 · leetcode · 评论(0)

erb和slim的速度比较

看了一个家伙写的《Is Rails Slow?》的ppt,起了测试模板速度的念头。ppt里测试的是haml比erb快,那么我就测试一下slim和erb之间的速度把。我用的gem版本如下: gemfile source 'https://rubygems.org' ruby '2.1.1' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' gem 'rails', '4.1.1' # Use sqlite3 as the database for Active Record gem 'sqlite3' # Use S…

2014-11-10 10:06 · Rails · 评论(0)

map和each的区别

map是创建一个新数组返回,each只是执行,返回的还是原数组。 a = [1,2].map do |x| x + 1 end puts a # =》 [2, 3] a = [1,2].each do |x| x + 1 end puts a # =》 [1, 2]

2014-11-09 19:14 · ruby · 评论(0)

mongo 导出csv

mongoexport --host 119.254.88.88 --port 10410 -d gcj_tj -c tmp -q '{"_id.function": {$in: ["插件_价格体检_体检", "插件_价格体检_一键载入"]}}' --csv -o /tmp/fuck.scv -f _id,value 说明: options: --help produce help message -v [ --verbose ] be more verbose (include multiple times for more verbosity e.g. -vvvvv) --version…

2014-11-06 10:13 · mongodb · 评论(0)