Skip to content

Instantly share code, notes, and snippets.

View luin's full-sized avatar
😄
Focusing

Zihua Li luin

😄
Focusing
View GitHub Profile
<div class="container">
<div class="background"></div>
<div class="content">
<div class="logo">
<img
src="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iODgiIGhlaWdodD0iNDAiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PHBhdGggZD0iTTc4LjA1IDE1LjE3M2MtNy4yNTEtLjI3NS05LjU3NyA2Ljc5NS05LjU3NyA2Ljc5NS0uMTM3LTIuOTUyLjA2OS00Ljg3NC4wNjktNC44NzQuNDEtLjI3NCA2LjU2Ni0yLjY3NyA2LjkwOC0xMC45ODIuMTM3LTQuNTMtMy42MjUtNy4xMzktOC4wMDMtNS42OTctMS42NDEgNy41NS0zLjIxNSAxNy44NDctMS44NDcgMjguNjIzLS4yNzMuODI0LTIuNzM1IDYuODY0LTUuNDAzIDYuODY0LTMuNjI2IDAtNC4yNDEtNy40ODItNC4xMDQtMTIuMzU1LjgyLTEuNzg1IDIuNTMtNi4wNCAxLjA5NC03Ljc1Ny0uNjg0LS44OTItMi4wNTItMS4wMy00LjEwNC0uNjE3IDAgLjQ4LS4xMzcgMy43MDYtLjEzNyAzLjcwNnMtMS43NzgtMy4zNjMtNi4xNTYtMy4zNjNjLTYuMjkyIDAtMTAuMzk2IDYuMTA5LTEwLjM5NiAxMi40OTMgMCAxLjAzLjA2OCAxLjkyMS4xMzYgMi44MTRsLjA2OS4wNjgtLjA2OS4wNjljLTEuNzEgMy4xNTgtMy4yODMgNC43MzYtNS4zMzUgNC43MzYtNC40NDYgMC00Ljk5My02Ljg2NC00Ljk5My02Ljg2NCA0LjE3Mi00Ljk0MiA2LjQzLTExLjg3NSA2LjQzLTE5LjQyNSAwLTYuMjQ3LTIuNzM2LTEwLjg0Ni04LjM0NS04Lj
@luin
luin / debugScrolling.js
Last active August 2, 2023 10:58
Scripts for debugging unexpected scrolling
function debugScrolling() {
/* eslint-disable func-names, no-debugger, no-console, prefer-rest-params */
const fnOnScroll = function(reason) {
console.log(reason);
debugger;
};
// scrollIntoView, scrollIntoViewIfNeeded, scrollTo
const scrollMethods = [
'scrollIntoView',
'scrollIntoViewIfNeeded',
@luin
luin / 2.x
Last active February 20, 2016 08:08
result of process.memoryUsage()
ioredis git:2.x ❯ node testgc.js ✭
{ rss: 39206912, heapTotal: 18550784, heapUsed: 10817576 }
{ rss: 42131456, heapTotal: 28858112, heapUsed: 14043976 }
{ rss: 45133824, heapTotal: 29890048, heapUsed: 17801240 }
{ rss: 48730112, heapTotal: 30921984, heapUsed: 16971152 }
{ rss: 52207616, heapTotal: 30921984, heapUsed: 20462008 }
{ rss: 55001088, heapTotal: 34017792, heapUsed: 20058632 }
{ rss: 55132160, heapTotal: 34017792, heapUsed: 23546144 }
{ rss: 58257408, heapTotal: 52592640, heapUsed: 23160232 }
{ rss: 59060224, heapTotal: 52592640, heapUsed: 26676264 }
@luin
luin / redis-test.js
Last active December 1, 2021 02:01 — forked from elyas-bhy/redis-test.js
Redis potential bug replication
var redis = require('redis');
var options = {
host: '127.0.0.1',
port: '6379'
};
var publisher = redis.createClient(options);
var subscriber = redis.createClient(options);
function sub(message) {
s1, s2 and s3 are operations in the server, and c1, c2 are operations performed on the client.
s1 s2 s3
c1 c2
1. transform(c1, s1) = (c1', s1') => c1 s1' = s1 c1'
2. transform(c1', s2) = (c1'', s2') => c1' s2' = s2 c1''
3. transform(c1'', s3) = (c1''', s3') => c1'' s3' = s3 c1'''
@luin
luin / promise.js
Created July 21, 2013 10:08
Make express res.json support promise
// Let express support "Promise"
app.use(function(req, res, next) {
var oldResJson = res.json;
res.json = function(promise) {
if (promise &&
typeof promise === 'object' &&
typeof promise.success === 'function') {
promise.success(function(fetchedObj) {
if (fetchedObj) {
oldResJson.call(res, fetchedObj);
@luin
luin / unCurrying.js
Created May 28, 2013 12:50
JavaScript反柯里化
Function.prototype.unCurrying = function () {
var self = this;
return function () {
var args = Array.prototype.slice.call(arguments);
return self.apply(args[0], args.slice(1));
};
};
var foo = [];
var push = Array.prototype.push.unCurrying();
@luin
luin / gist:5124550
Created March 9, 2013 15:39
a simple pool library for nodejs.
var Pool = function (poolSize, taskHandler) {
this.poolSize = poolSize;
this.taskHandler = taskHandler;
this.free = poolSize;
this.offlineTasks = [];
};
Pool.prototype.check = function () {
if (this.offlineTasks.length > 0 && this.free > 0) {
angular.module('projectServices', [])
.factory 'User', ->
@authenticated = false
@name = null
isAuthenticated: => @authenticated
getName: => @name
login: (username, password, callback) =>
$.post '/login',
{username: username, password: password},
((data) =>
@luin
luin / iterators.js
Created January 24, 2013 15:24
Implementing iterators in JavaScript
function iterators (list) {
var index = 0;
return function () {
return list[index++];
}
}
var v;
var str = "hello world!";