Skip to content

Instantly share code, notes, and snippets.

@rockydd
rockydd / click.js
Created July 27, 2018 03:36
get single-click double-click and triple-click with rxjs
//https://stackoverflow.com/questions/37310640/rxjs-buffer-how-to-group-multi-click-events-as-stream/51547034#51547034
const btn = document.querySelector('#btn');
const click$ = Rx.Observable.fromEvent(btn, "click");
const trigger$ =
click$.exhaustMap(r =>
click$
.take(2)
.last()
.race(click$
// inputTask :: String -> String -> Task
const name = 'dong';
most.periodic(1000).take(25)
.scan( (x,y) => x + 1, 0)
.map( x => name[x%4])
.observe(console.log);
<?xml version="1.0" encoding="UTF-8" ?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file source-language="en" datatype="plaintext" original="ng2.template">
<body>
<trans-unit id="introductionHeader" datatype="html">
<source>
Hello i18n!
</source>
<target>
Bonjour i18n !
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD
define(['jquery'], factory);
} else if (typeof exports === 'object') {
// Node, CommonJS-like
module.exports = factory(require('jquery'));
} else {
// Browser globals (root is window)
root.returnExports = factory(root.jQuery);
@rockydd
rockydd / nubToBytes
Last active August 29, 2015 14:20 — forked from anonymous/nubToBytes
Object.defineProperty(Number.prototype,'fileSize',{value:function(a,b,c,d){
if(this == 0){
return "0.0 B";
}else if(this < 0.001){
return this.toExponential(1) + " B";
}else if(this < 1){
return this.toLocaleString() + " B";
}
return (a=a?[1e3,'k','B']:[1024,'K','iB'],b=Math,c=b.log,
@rockydd
rockydd / gist:1079904
Created July 13, 2011 07:53
customize control
<?xml version="1.0" encoding="utf-8"?>
<mx:VBox xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" initialize="loadPage()" borderStyle="solid" styleName="container">
<fx:Script>
<![CDATA[
import mx.containers.HBox;
import mx.controls.Alert;
import mx.controls.Image;
@rockydd
rockydd / gist:840621
Created February 23, 2011 16:11
Chart Sample; columnchart, vertical axis label function
<fx:Script>
<![CDATA[
private function labelPhaseEffortVertical(labelValue:Object, previousLabelValue:Object, axis:AxisBase):String
{
return labelValue + "Hrs";
}
]]>
</fx:Script>
@rockydd
rockydd / gist:825433
Created February 14, 2011 03:12
pie chart sample. with showDataEffect
<mx:PieChart x="92" y="200" id="pieTeamEffort" dataProvider="{teamEffort}" showDataTips="true">
<mx:series>
<mx:PieSeries displayName="Effort" field="effort" nameField="name">
<mx:showDataEffect>
<mx:SeriesInterpolate duration="1000"/>
</mx:showDataEffect>
</mx:PieSeries>
</mx:series>
</mx:PieChart>
# h = [["a", 100], ["c", 300], ["d", 400]] 怎么转化成 {"c" => 300, "a" => 100, "d" => 400, "c" => 300 }这样一个hash
h.flatten!
Hash[*h]
require 'net/http'
require 'rexml/document'
# Web search for "madonna"
url = 'http://api.search.yahoo.com/WebSearchService/V1/webSearch?appid=YahooDemo&query=madonna&results=2'
# get the XML data as a string
xml_data = Net::HTTP.get_response(URI.parse(url)).body
# extract event information