Skip to content

Instantly share code, notes, and snippets.

View hustcc's full-sized avatar
🎯
Focusing

hustcc hustcc

🎯
Focusing
View GitHub Profile
@hustcc
hustcc / jsdom-iframe-test.js
Created January 15, 2018 10:43 — forked from dijs/jsdom-iframe-test.js
Example of testing iframe messaging using jsdom
import { expect } from 'chai';
import jsdom from 'jsdom';
describe('JSDOM', () => {
it('should communicate with inner iframes', done => {
jsdom.env({
url: "http://bar.com/",
done (err, window) {
var frame = window.document.createElement('iframe');
window.document.body.appendChild(frame);
@hustcc
hustcc / emoji.md
Created May 11, 2016 04:35
emoji-preview

Emoji表情

将对应emoji表情的符号码复制后输入你的markdown文本即可显示emoji表情。 如:blush:,显示为:blush:

人物

syntax preview syntax preview syntax preview
:bowtie: :bowtie: :smile: 😄 :laughing: 😆
@hustcc
hustcc / ChangeToBig.js
Created January 19, 2017 05:38
金额大小写自动转换(代码来源于农行网银)
// 金额大小写自动转换
function ChangeToBig(value) {
if (value == null || value == "") {
//return "错误金额";
return "";
}
value = "" + value;
var intFen, i;
var canvas = document.getElementById('canv'),
ctx = canvas.getContext('2d'),
img = document.getElementById('image');
function grow(el) {
el.style.height = "10rem";
el.style.height = (el.scrollHeight)+"px";
}
var generate = function() {
parse = function(input) {
if (input instanceof Date) {
return input;
} else if (!isNaN(input)) {
return new Date(input);
} else if (/^\d+$/.test(input)) {
return new Date(parseInt(input, 10));
} else {
var s = (input || '').trim();
s = s.replace(/\.\d+/, ''); // remove milliseconds
@hustcc
hustcc / AnimationFrame.js
Last active May 23, 2016 02:59
AnimationFrame can be used to do tasks.
var frame_func = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || function(func) {
window.setTimeout(func, 1000 / 60);
};
//帧动画,做定时任务
//动画循环
if (!window.requestAnimationFrame) {
window.requestAnimationFrame = (window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.msRequestAnimationFrame ||
window.oRequestAnimationFrame ||
@hustcc
hustcc / htmlEntities.js
Created May 11, 2016 04:53
javascript 转义
function htmlEntities(str) {
return String(str)
.replace(/&/g, '&')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;');
}
@hustcc
hustcc / file_input.css
Created May 11, 2016 04:50
重写 file 控件样式
input[type="file"]{
-webkit-appearance: none;
text-align: left;
-webkit-rtl-ordering: left;
}
input[type="file"]::-webkit-file-upload-button{
-webkit-appearance: none;
float: right;
margin: 0 0 0 10px;
border: 1px solid #aaaaaa;
@hustcc
hustcc / headless browsers.md
Created April 20, 2016 07:24 — forked from evandrix/README.md
Headless web browsers

Here are a list of headless browsers that I know about:

  • [HtmlUnit][1] - Java. Custom browser engine. JavaScript support/DOM emulated. Open source.
  • [Ghost][2] - Python only. WebKit-based. Full JavaScript support. Open source.
  • [Twill][3] - Python/command line. Custom browser engine. No JavaScript. Open source.
  • [PhantomJS][4] - Command line/all platforms. WebKit-based. Full JavaScript support. Open source.
  • [Awesomium][5] - C++/.Net/all platforms. Chromium-based. Full JavaScript support. Commercial/free.
  • [SimpleBrowser][6] - .Net 4/C#. Custom browser engine. No JavaScript support. Open source.
  • [ZombieJS][7] - Node.js. Custom browser engine. JavaScript support/emulated DOM. Open source.
  • [EnvJS][8] - JavaScript via Java/Rhino. Custom browser engine. JavaScript support/emulated DOM. Open source.
// 颜色#FF00FF格式转为Array(255,0,255)
function color2rgb(color) {
var r = parseInt(color.substr(1, 2), 16);
var g = parseInt(color.substr(3, 2), 16);
var b = parseInt(color.substr(5, 2), 16);
return new Array(r, g, b);
}
// 颜色Array(255,0,255)格式转为#FF00FF
function rgb2color(rgb) {