Skip to content

Instantly share code, notes, and snippets.

@villadora
Last active December 15, 2015 22:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save villadora/5333826 to your computer and use it in GitHub Desktop.
Save villadora/5333826 to your computer and use it in GitHub Desktop.

note snippets

Here's a short list of programming-language features that have become ad-hoc standards that everyone expects:

  • Object-literal syntax for arrays and hashes
  • Array slicing and other intelligent collection operators
  • Perl 5 compatible regular expression literals
  • Destructuring bind (e.g. x, y = returnTwoValues())
  • Function literals and first-class, non-broken closures
  • Standard OOP with classes, instances, interfaces, polymorphism, etc.
  • Visibility quantifiers (public/private/protected)
  • Iterators and generators
  • List comprehensions
  • Namespaces and packages
  • Cross-platform GUI
  • Operator overloading
  • Keyword and rest parameters
  • First-class parser and AST support
  • Static typing and duck typing
  • Type expressions and statically checkable semantics
  • Solid string and collection libraries
  • Strings and streams act like collections

bash script

set -e

fail ths shell script if any command failed.

set -o pipefail

this will failed even you have commands failed in pipe

中国金融市场

基金 —— 养券

‘养券’其实是一种息差交易。一般来说,回购的利率会低一点,如7天回购一般就是3%左右,而券的收益率较高,一般是6%左右。理论上来说,借钱(回购)买券,吃息差。 养券和利益输送之间没有必然联系,但是中间可能存在利益输送的环节。比如,B基金的债券给A基金代持,A基金只能获得比较低的收益,而中间的息差则由B基金获得,这就涉嫌利益输送。违规的可能则存在于债券久期上,比如,某些基金规定其持有的债券剩余天数不能超过180天,但是该基金通过养券而持有超过180天的债券。

“养券”其实在金融机构非常普遍,尤其是在券商固定收益部门。养券的模式有很多,一般有很多的方式进行变通,以规避监管层,比如通过银行理财基金、结构化的信托产品等。代持养券一方面可以扩大自营的范围;同时,委托机构支付高额的费用也对代持机构产生一定的吸引力。

“养券”伴随着巨大的风险。其最大的风险在于回购与券的期限是不匹配的。(短债长投) 回购的钱,短的一天、一周,长的一个月,而为了息差高,拿的券的期限则比较长,因为一般来说,期限长其收益率就越高。这是养券最常见的模式。

Custom tags in html

<book pages="400" author="Nietzsche">The Wanderer and His Shadow</book>

There are just a couple things you have to keep in mind:

All custom elements have a display of inline by default. You can change that with CSS or JavaScript, however.

Internet Explorer does not recognize any of these elements unless you first "create" them with JavaScript:

document.createElement('book');

Flex handles Date in a very strange way, it doesn't store any timezone information in Date class. The value contains in the internal only is a number from a specific date. All the timezone issue are handled during the process when you want to display it, like in the function toString(), toUTCString().

That means if you persist a Date object, the string it shows for localtime will be different and depends on you client's timezone.

And also that cause a problem when transferring data between client and server.

ref 1 ref 2

In Flash Player Internal: swf => bytecode in AVM => !DisplayList => Renderer => FP

in flex,the component tree represents the structure of an MXML document, it represents the data relationship between different components. the layout tree represents the runtime layout, it knows nothing about the logical relationship of components, only know the status when components display in screen.

the displaylist is a low-level structure maintained in flash player.

Wiki:Display List concept common in GL

• When using interactive commands for find&replace, emacs won't understand \t, \n. To enter a Tab character, press 【Ctrl+q Tab ↹】. To enter a new line, press 【Ctrl+q Ctrl+j】. (For explanation, see: Emacs's Key Notations Explained (/r, ^M, C-m, RET, , M-, meta)).

ref: http://ergoemacs.org/emacs/emacs_regex.html

  1. put head and body in different container(div).

  2. make table-layout to be fixed, so the head table will share the same width as the body table by default.

  3. add a overfix th in the head table to adjust width with scrollbar

  4. using javascript to check whether the scrollbar is showing or not

simple example:

http://jsfiddle.net/Trf6y/13/

Elastic Racetrack in AVM2 Flash Player Mental Model in FP9 & older

Great Slides to explain this and component lifecycle

video in adobe website

About the frameRate

  1. Player tries its best to maintain the targetted framRate, but no garuntees
  2. The rate can also go over what you asked for
  3. Tinic says "the actual frame rate will sway between -10 to +5 frames/sec from the actual selected frame rate"
  4. Browsers cause reduced framerates if Tab is not in focus or Browser is minimized
    • On OSX - Safari cuts it down to 0 when minimized, Firefoxt doesnt
    • On Tab out of focus its about 10 on both Safari and Firefox

Test Code

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
            xmlns:s="library://ns.adobe.com/flex/spark" 
            xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"
           enterFrame="application1_enterFrameHandler(event)"
           render="application1_renderHandler(event)"
           frameRate="1"
           creationComplete="application1_creationCompleteHandler(event)">

   <fx:Script>
      <![CDATA[
         import flash.utils.getTimer;
         
         import mx.events.FlexEvent;
         
         
         private var _startFrame:Number = 0;
         protected function application1_enterFrameHandler(event:Event):void
         {
            if(_startFrame != 0)
            {
               trace("EnterFrame Event: last frame length => " + (getTimer() - _startFrame) +" ms"); 
               _startFrame = getTimer();
            }
         }

         private var timer:Timer;
         protected function application1_creationCompleteHandler(event:FlexEvent):void
         {
            _startFrame = getTimer();
            timer = new Timer(1);
            timer.addEventListener(TimerEvent.TIMER,function(event:TimerEvent):void {
               if(_startFrame != 0)
                  trace("Elastic Slide: elastic slide run=> " + (getTimer()-_startFrame) + " ms");
            });
            timer.start();
         }


         protected function application1_renderHandler(event:Event):void
         {
            if(_startFrame != 0)
               trace("Render Event: render => " + (getTimer()-_startFrame) + " ms");      
         }

      ]]>
   </fx:Script>

   <fx:Declarations>
      <!-- Place non-visual elements (e.g., services, value objects) here -->
   </fx:Declarations>
</s:Application>

周小川: 汇率、增值税与服务业发展

=老文,感兴趣的原因是里面提到了很多以前不了解的历史情况,以及综合性的理念,税收和汇率等之前自己没有结合起来了解过的=

文章中提到在改革开放之初,中国实行的是多重汇率体制,这也是计划经济遗传基因之一;而多重汇率之复杂和考虑问题之细致,是我以前没有想到过的,可以看出在调节市场结构和供给方面,并不是说计划经济就是不顾客观规律的一路蛮行。而是也有很细致的研究,只不过实现目的的手段不同罢了,而手段的限制在于理念的不同,这个牵涉到更多哲学上的问题。

在计划经济时代,并不是说完全以强制性的方针来实行计划,流传的以粮票等票据来限制供给实际上还是比较落后的方式,苏联在这方面走的比中国要远也要有效和聪明得多,毕竟经验要远比才开始工业化建设不久的中国要丰富的多。这也很可能是在之后无法像中国开放所做的一样温和扭转发展路径的原因之一,积重难返。

为了避免价格传导效应破坏国内市场,同时也为了给予计划当局分配外汇的权利,所以本币通常被高估。

产品税有累计效应,所以对于下游产品征收的税多,也促使制成品价格的高企。而为了进行国家质检贸易,对于不同的产品出口就实行了退税政策,而因为计划的不同,不同产品的需求度不一样,不同行业不同公司的换汇成本不一样。从而也应该可以想到当年的炒汇不仅仅是正规途径和黑市之间的汇差,还有由于多重汇率制度引起的汇差。

直到1994年,中国菜宣布实施汇率并轨,明确建立单一的、有管理的浮动汇率制度。这个历史从现在来看也不过20年。可以说是很短暂的。中间的推进和改革也是很混乱的。90年代中期的各种金融制度的改革也同时进行,从现在回看那时候改革的勇气不可谓不大。而在进入新世纪之后,改革的力度减缓是不争的事实。

汇率改革就必须修正国内价格体系和国际市场价格体系之间的不平行,否则汇率的调节作用也是扭曲的。而要调节国内价格体系,则必须对税收体系进行改革。在这里,注意到的汇率实际上是做为两个不同市场之间起到转接的作用。也在调控中起到控制国内外市场交流规模的作用。

1994年税收体制改革主要包括三个方面:一是广泛推行增值税;二是企业所得税不必再搞差别化,即所有类型的企业(后来也包括金融企业)统一所得税率;三是在中央与各级地方政府之间重新安排财力并改进财权、事权的匹配,即当时的分税制改革。现在的关注主要注重在有争议的分税制。前面两个都已经习惯并且可以说得到验证了。

汇率在概念上可表达为一国可贸易货品和不可贸易货品的比价。所谓的不可贸易货品,最主要的就是服务,大多数服务不可跨境递交。当然不可贸易货品也包括一些工业产品,比如电力,一般情况下电网未延伸至他国,所以电力往往也属于不可贸易品。在互联网发展和全球化日益深化的条件下,一些不可贸易货品变得可外包、可贸易,但多数服务业仍不可贸易。从这个角度说,汇率给出了可贸易货品和非贸易货品之间的总体比价。对此,可简化理解为,当本币相对低估时,经济资源(各生产要素)会向可贸易行业倾斜,其回报和收入均相对较高而具有更大的相对吸引力;相反,当本币相对高估时,可贸易行业的相对吸引力较弱,使得更多的生产要素流向不可贸易行业,也就是说服务业的收入和回报相对较高。因此,汇率反映了可贸易货品和不可贸易货品的比价关系

增值税和营业税,现在服务行业全国大部分地区正处于营业税改增值税。而改革原因在文章中:

一是导致了服务业和工业企业的不平等竞争,制约了服务业的专业化分工。例如,当企业需要生产性服务时,如果工业企业用“大而全”、“小而全”的方式自包这种服务,则该服务的中间投入品成本可以抵扣增值税,出口时也可以退税;但如果从服务业企业购买这种服务,由于服务业企业只能提供营业税发票,采购企业就无法享受增值税抵扣和出口退税。这本身是对服务专业的一种扭曲甚或歧视,没有体现公平原则,同时也导致企业在服务需求方面仍然追求“大而全”、“小而全”,进一步影响到资源的优化配置。

二是服务业的营业税类似于过去的产品税,往往重复计征,因此一些低附加值、小型专业化服务业企业难于初创。比如,想设立一个初期附加值只有3%的服务业小企业,如果要交5%的营业税,就无法设立和生存,而在增值税体制下则不存在这个问题。

三是在出口退税方面导致服务业外包出口受到歧视和不公平竞争。外包服务往往也用了不少外购的设备、投入品和其他企业提供的服务,但却不能享受出口退税,影响服务业外包的出口竞争力。

四是工业企业实行增值税、服务业实行营业税或者部分实行营业税,还可能导致增值税发票体系的严密性出现漏洞。从理论上说,增值税发票体系本身非常严密,环环相扣,有较好的交叉检查特性,但两种税制混合实施就容易产生漏洞,影响增值税体系的完整性和严密性。其一是交叉检查链条会有中断现象;其二是会出现一部分不能用于抵扣和退税的游离性增值税发票。

可以看到,其实为什么之后的改革停滞,是和服务业的发展有关,发达地区服务业对GDP的贡献已经上升,而全国来看也是出于快速增加的态势,在可以预计的将来会超过第二产业。于是产业发言人自然更希望享受到更好的税率。而以前应该是由于话语权的原因没有被重视。而这一次全国性的开始改革对服务业应该是一大利好。这也是在金融危机之后,工厂型企业的发展受限,终于迈步进入产业转型的结果之一。

Haml comments:

 / comments here will be translated to html comments

output will be:

 <!-- comments here will be translated to html comments

and this will be sent to client side.

 -# this comment will be just ignore by processor

will output nothing

But if you are in some script block, like

:javascript

You'll find that both two above are not working, you have to use js comments, otherwise, those comments will embeded in js block. If you really want those comments to be removed after processing, you can always use:

#{ #here is ruby comments!  // remember newline here
}

做学问要在不疑处有疑,做人要在有疑处不疑。——胡适

For position:absolute element in IE7, if the background-color is none or transparent, the mouse events (like 'click', 'mouseenter',ect) will be triggered in the element that behind front one. Like a penetrability effection.

so make sure the absolute element and its children has a fixed background.

javascript只是mozilla自己维护的一个ECMAScript实现版本,但是现在大家在浏览器里做的都叫javascript,实际上google, ie, safari里面用的都不是javascript. emm.... 真是个神奇的事情

有些地方,蛋炒饭叫木须饭,按字来说,该是木樨饭。木樨者桂花,旧北京太监多,气有人笑人无,最恨人说鸡蛋二字。所以,饭菜用到鸡蛋,都讳说是桂花。比如著名的“桂花皮炸”,其实就是猪皮浇了蛋液来炸。

Good Way to Build Flex Project in Unix Platform

Usually, we develop flex projects in eclipse and when things come to deployment, it's not easy to integrate the flex project's build process into antbuild, especially, when you have modules, libs,rsls,etc. Now if you are using flex build 4 or later, then you can try following steps, see details

Run a command line build using Flash Builder compiler settings

In Flash Builder, select Project > Properties > Flex Compiler In Additional Compiler Arguments, specify the following argument: -dump-config pathname, where pathname specifies the absolute path to a file on your system. Apply the changes in the Project window. The compiler settings are written to the specified file. Remove the -dump-config argument after you have verified that the file has been written. Modify the configuration settings as necessary. In your build script, run the compiler so it includes the saved compiler settings: mxmlc -load-config pathname

Then you can easily call task in you antbuild file with the output config with sightly modification.

note snippets

在octopress里面自己写theme的时候调试sass很不方便,在config.rb中改掉compass的输出参数就好了

output_styles = :compressed

output_styles = :expended

这样生成的css就会带有debug信息,可以知道这些style都是在哪个文件中定义的了。

From this distant vantage point, the Earth might not seem of any particular interest. But for us, it's different. Consider again that dot. That's here. That's home. That's us. On it everyone you love, everyone you know, everyone you ever heard of, every human being who ever was, lived out their lives. The aggregate of our joy and suffering, thousands of confident religions, ideologies, and economic doctrines, every hunter and forager, every hero and coward, every creator and destroyer of civilization, every king and peasant, every young couple in love, every mother and father, hopeful child, inventor and explorer, every teacher of morals, every corrupt politician, every "superstar," every "supreme leader," every saint and sinner in the history of our species lived there – on a mote of dust suspended in a sunbeam.

The Earth is a very small stage in a vast cosmic arena. Think of the rivers of blood spilled by all those generals and emperors so that in glory and triumph they could become the momentary masters of a fraction of a dot. Think of the endless cruelties visited by the inhabitants of one corner of this pixel on the scarcely distinguishable inhabitants of some other corner. How frequent their misunderstandings, how eager they are to kill one another, how fervent their hatreds. Our posturings, our imagined self-importance, the delusion that we have some privileged position in the universe, are challenged by this point of pale light. Our planet is a lonely speck in the great enveloping cosmic dark. In our obscurity – in all this vastness – there is no hint that help will come from elsewhere to save us from ourselves.

The Earth is the only world known, so far, to harbor life. There is nowhere else, at least in the near future, to which our species could migrate. Visit, yes. Settle, not yet. Like it or not, for the moment, the Earth is where we make our stand. It has been said that astronomy is a humbling and character-building experience. There is perhaps no better demonstration of the folly of human conceits than this distant image of our tiny world. To me, it underscores our responsibility to deal more kindly with one another and to preserve and cherish the pale blue dot, the only home we've ever known.

Testing States vs. Testing Interactions

tags: Testing, 测试,单元测试

Testing States 测试状态

Testing state是说在做单元测试时主要测试方法是否返回了正确的结果,也就是不管其中的call方式和逻辑怎样,最终的状态是否正确;而程序实际上是数据在一系列的状态之间切换的。这也是我,相信也是大家,用的最多的方式。

Testing Interaction 测试交互

Testing interaction是说你测试时主要检测是不是调用了一定的方法传递了一定的参数,有时候测试一个integration的class的时候很实用,因为数据和状态的修改都是在整合的接口中进行的,所以这里只需要知道调用是否正确,不同的classes,interfaces之间是否按正确的方式组合。

在goolge testing blog中,提到第二中测试有着更好的code coverage,但是确不哦能保证正确性。这也是为什么我们大部分情况都实用第一种Testing state。

Choice

那么我们什么时候要去选择实用test interactions呢?一般来说,如果除了结果之外,代码还会产生其他的side effects的时候,我们应该考虑test interactions;当然你也可以去在之后对所有可能产生的side effects进行result verify,但是那样会花费更多的精力。代码也不那么简洁易懂。

还有的时候去测试一些组合的比如composition, facade模式下的一些classes,这些类自身并不关注result,而他们的正确性在于他们是否合理的调用了其封装的类的方法,结果的正确性应该是隐式的:如果封装的classes/interfaces结果正确,那么在正确的步序下,这个class的结果也是正确的。

另外,就是在测试UI的时候,因为UI并不在乎逻辑数据是否正确,这不是UI的职责;在乎的对于相应的事件,无论是用户触发的还是系统广播的,都给予了正确的相应,这些相应也是由一系列的调用来完成的。

基地 The Foundation

交流 为什么我们需要交流,沟通能够减少什么 个性 一个有着谎言的世界是有着缓冲的世界,无限度的交流并不是一个系统的最优选择 进化 进化是无意的还是有意的,试错机制到底应当如何运行 创造 民主与交流会毁灭创造 阈值 个体与群体之间的区分是怎样的,如何在其中把握好度

历史 从集权到民主,从自由主义到共产,我们在怎么寻找一个可能平衡的世界,或者永远是一个不稳定的摇摆系统

see on stackoverflow

Force webkit redraw the html element

Taken from here: How can I force WebKit to redraw/repaint to propagate style changes?

sel.style.display='none';
sel.offsetHeight; // no need to store this anywhere, the reference is enough
sel.style.display='block';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment