Skip to content

Instantly share code, notes, and snippets.

🏀
On the way.

Zerui Hu alex1504

🏀
On the way.
Block or report user

Report or block alex1504

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@alex1504
alex1504 / node-and-npm-in-30-seconds.sh
Created Sep 11, 2017 — forked from isaacs/node-and-npm-in-30-seconds.sh
Use one of these techniques to install node and npm without having to sudo. Discussed in more detail at http://joyeur.com/2010/12/10/installing-node-and-npm/ Note: npm >=0.3 is *safer* when using sudo.
View node-and-npm-in-30-seconds.sh
echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
. ~/.bashrc
mkdir ~/local
mkdir ~/node-latest-install
cd ~/node-latest-install
curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1
./configure --prefix=~/local
make install # ok, fine, this step probably takes more than 30 seconds...
curl https://www.npmjs.org/install.sh | sh
@alex1504
alex1504 / media-query.md
Last active Sep 6, 2017
移动端媒体查询
View media-query.md
/* Smartphones (portrait and landscape) ----------- */
@media only screen and (min-device-width : 320px) and (max-device-width : 480px) {
/* Styles */
}

/* Smartphones (landscape) ----------- */
@media only screen and (min-width : 321px) {
/* Styles */
}
@alex1504
alex1504 / transform.md
Created Aug 22, 2017
File、Blob、dataUrl、canvas之间的转换
View transform.md

File对象转换为dataURL、 Blob对象转换为dataURL

file对象继承自blob,转换方式相同

function readBlobAsDataURL(blob, callback) {
    var reader = new FileReader();
    reader.onload = function(e) {callback(e.target.result);};
    reader.readAsDataURL(blob);
}
//example:
readBlobAsDataURL(blob, function (dataurl){
@alex1504
alex1504 / bower.json
Last active Jul 31, 2017
基于generator-webapp 3.0.0;修复无法输出js的问题;增加sprite生成;增加跨域代理
View bower.json
{
"name": "zhangyudih5",
"private": true,
"dependencies": {
"swiper": "^3.4.2",
"vue": "^2.4.2",
"lib-flexible": "*",
"weui": "^1.1.2",
"axios": "^0.16.2"
},
@alex1504
alex1504 / detect-img-light.js
Created Jul 19, 2017
js判断图片的明亮度
View detect-img-light.js
/* This function will convert each color to gray scale and return average of all pixels, so final value will be between 0 (darkest) and 255 (brightest) */
function getImageLightness(imageSrc,callback) {
var img = document.createElement("img");
img.src = imageSrc;
img.style.display = "none";
document.body.appendChild(img);
var colorSum = 0;
img.onload = function() {
View You-don't-need-jQuery.md

You Don't Need jQuery Build Status

前端发展很快,现代浏览器原生 API 已经足够好用。我们并不需要为了操作 DOM、Event 等再学习一下 jQuery 的 API。同时由于 React、Angular、Vue 等框架的流行,直接操作 DOM 不再是好的模式,jQuery 使用场景大大减少。本项目总结了大部分 jQuery API 替代的方法,暂时只支持 IE10+ 以上浏览器。

目录

  1. Translations
  2. Query Selector
  3. CSS & Style
  4. DOM Manipulation
@alex1504
alex1504 / renderPdfByBase64.js
Last active Mar 29, 2018
Render all pages to html file by pdf.js
View renderPdfByBase64.js
function renderPdfByBase64(base64Data) {
var currPage = 1; // 当前页面
var numPages = 0; // 总页数,由getDocument后获取
var thePDF = null;
var pdfData = base64ToUint8Array(base64Data);
PDFJS.getDocument(pdfData).then(function(pdf) {
thePDF = pdf;
numPages = pdf.numPages;
pdf.getPage(1).then(handlePages);
});
@alex1504
alex1504 / gulpfile.js
Last active Sep 15, 2018
使用gulp解决前端本地跨域请求代理
View gulpfile.js
var gulp = require('gulp');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var autoprefixer = require('gulp-autoprefixer');
var useref = require('gulp-useref');
var connect = require('gulp-connect');
var proxyMiddleware = require('http-proxy-middleware');
// 跨域代理 将localhost:8088/api 映射到 https://api.shujumohe.com/ 代理src目录
@alex1504
alex1504 / jquery-pop-options.js
Last active Jun 22, 2017
jQuery options pop
View jquery-pop-options.js
$.extend({
popOptions: function(params) {
var defaults = {
title: "标题",
options: [{
name: "选项一",
onClick: function() {}
},
{
name: "选项二",
@alex1504
alex1504 / gulpfile-1.js
Last active Jun 22, 2017
1、gulp重命名及精灵图生成 2、css、js压缩合并
View gulpfile-1.js
var gulp = require('gulp');
var concat = require('gulp-concat');
var cleancss = require('gulp-clean-css');
var uglify = require('gulp-uglify');
var autoprefixer = require('gulp-autoprefixer');
gulp.task('css',function(){
return gulp.src('css/*.css')
.pipe(concat('style.min.css'))
You can’t perform that action at this time.