Skip to content

Instantly share code, notes, and snippets.

View xhinking's full-sized avatar

Wang xhinking

  • HangZhou
  • 04:54 (UTC +08:00)
View GitHub Profile
@xhinking
xhinking / .block
Created May 25, 2016 05:18 — forked from tonyhschu/.block
Small Scroll-linked Animation Demo
scrolling: yes
public func Init<Type>(value: Type, @noescape block: (object: Type) -> Void) -> Type {
block(object: value)
return value
}
let fade = Init(CABasicAnimation(keyPath: "opacity")) {
$0.duration = NSTimeInterval(duration)
$0.fromValue = fromOpacity
$0.toValue = toOpacity
$0.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
body::after {
content: "";
background: url(../fake-bg.png) center -1px no-repeat;
opacity: 0.3;
top: 0;
left: 0;
bottom: 0;
right: 0;
position: absolute;
z-index: -1;
@xhinking
xhinking / README.md
Created November 20, 2015 01:22 — forked from micahstubbs/README.md
programmatic control of a d3 brush - specify zoom

Forked from timelyportfolio's bl.ock which in turn forked Mike Bostock's focus+context zoom gist to demonstrate how we can drive a d3 brush with code.

anybody know how to brush with code in #d3js?

— klr (@timelyportfolio) September 10, 2014
<script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script>

So timelyportfolio found this discussion, but he could not find an example demonstrating the steps proposed by Athan Reines.

For auto-redraw so that the focus of a 1D brush matches the graphed domain, you need to do as fol
@xhinking
xhinking / umeng-style.css
Last active September 6, 2015 08:26
Umeng New Style
body {
height: auto;
min-height: 100%;
margin: 0;
padding: 0;
font-family: 'Helvetica Neue', "Hiragino Sans GB","Microsoft YaHei",sans-serif;
font-size: 14px;
-webkit-font-smoothing: antialiased;
}
@xhinking
xhinking / index.js
Created December 26, 2014 06:21
Determine if the given hex color is light or dark. Helpful to determining foreground color against a background color.
// https://github.com/scottcorgan/contrast
var hexToRgb = require('hex-to-rgb');
module.exports = function contrast (hex) {
var rgb = hexToRgb(hex);
var o = Math.round(((parseInt(rgb[0]) * 299) + (parseInt(rgb[1]) * 587) + (parseInt(rgb[2]) * 114)) /1000);
return (o <= 180) ? 'dark' : 'light';
};
// MWWebSnapshot
//
// Created by Jim McGowan on 08/09/2010.
// Copyright 2010 Jim McGowan. All rights reserved.
//
// This code is made available under the BSD license.
// Please see the accompanying license.txt file
// or view the license online at http://www.malkinware.com/developer/License.txt
//
//
@xhinking
xhinking / print_filter.js
Created March 4, 2014 07:25
Crossfilter & dc filter printer source: codeproject
function print_filter(filter) {
var f=eval(filter);
if (typeof(f.length) != "undefined") {}else{}
if (typeof(f.top) != "undefined") {f=f.top(Infinity);}else{}
if (typeof(f.dimension) != "undefined") {f=f.dimension(function(d) { return "";}).top(Infinity);}else{}
console.log(filter+"("+f.length+") = "+JSON.stringify(f).replace("[","[\n\t").replace(/}\,/g,"},\n\t").replace("]","\n]"));
}
// jshint devel: true
// make a copy of each `console` methods and adds them
// to the global object so that you can call `log('foobar')`
// instead of the verbose `console.log('foobar')`
// DO NOT USE IT IN PRODUCTION MODE
// @623HS
(function(global) {
'use strict';
var name, value;