Skip to content

Instantly share code, notes, and snippets.

View mutoo's full-sized avatar

Lingjia Liu mutoo

View GitHub Profile
@mutoo
mutoo / fibonacci-50000000
Created March 14, 2020 21:32
the answer of the fibonacci[50000000]
This file has been truncated, but you can view the full file.
4602713413433154453264452332101823124660178999927878775099623274628544000826084520729275137386306313610970039542134019169094479911539667758765706548388262709395910401447414275192972397095100372901062558411172027994823308339118707411212899705108784191046990030246902890430162768476917897544323686963363526638329586402598537684995297467531450584152322402629527753056672068582799976452955077140364435633611627743030006882994464389706629103466042439399187818912431754020828466328554047723057801189261674789207224541262917263083945860320625674536625026002950952262398064897919271988481419068961330802400103216397852978258771045078666755642257479872208814339437518538616439414227876160324202838202693667701117389124410449965409845122982315624918113650650381630365765220616683628335407025058495890159377056162851945512758383382009140042967905216072731650772908134476998576255535178729325770930240128556117231001128605001837891938772915337002956920498855579997481972474558715755099585396947510028754873131439722605891277408245136842
@mutoo
mutoo / icon-font-loader.js
Last active February 3, 2020 03:51
the icon-font-loader that parses the key/value pairs from the font style.css into an array
const { getOptions } = require('loader-utils');
const validateOptions = require('schema-utils');
const css = require('css');
const schema = require('./options.json');
/**
* This loader parses the key/value pairs from the font style.css into an array
*/
module.exports = function loader(source) {
const options = getOptions(this) || {};
@mutoo
mutoo / data.json
Last active January 30, 2020 11:50
a demo of using stream json for big data.
{
"a": {
"b": [
{
"id": 301940,
"slug": "ef4f2422125f",
"nickname": "说",
"avatar_source": "asdfsd",
"total_likes_count": 28553,
"total_wordage": 1373341,
@mutoo
mutoo / tags-conflict-reportor.js
Created December 27, 2019 13:11
Report the tags conflict in your posts. Just put this script in the /scrips/ folder, and it would ran everytime the post being edited.
hexo.extend.generator.register('posts', function(locals) {
const tagMap = {};
// first pass collect all tags in lower cases
const posts = locals.posts;
posts.forEach(post => {
post.tags.forEach(({ name }) => {
const lowercase = name.toLowerCase();
if (!tagMap[lowercase]) tagMap[lowercase] = {};
tagMap[lowercase][name] = (tagMap[lowercase][name] || 0) + 1;
});
@mutoo
mutoo / useSagaRequest.jsx
Created December 13, 2019 13:13
a promise bridge between react component and redux-saga.
// react.js
const SagaRequestDemo = () => {
const sagaRequest = useSagaRequest();
const loadUser = () => {
sagaRequest.dispatch(fetchUser({ id: 'mutoo' }))
.then((data) => {
console.log(`fetch user success: ${data}`);
})
.catch((err) => {
@mutoo
mutoo / wechat-reading-spider-poc.js
Last active December 12, 2019 04:10
The wechat reading using canvas to render the text to prevent text copying, but there is a way to bypass it.
(()=>{
// hijack the fillText function to collect characters info
const c2d = CanvasRenderingContext2D.prototype;
const data = [];
const oldFillText = c2d.fillText;
c2d.fillText = function() {
const [char,x,y] = arguments;
data.push({
char,
x,
@mutoo
mutoo / wechat-reading-spider.js
Last active December 11, 2019 12:29
test composing text on wechat reading page.
Array.prototype.slice.call(document.querySelectorAll('span[data-wr-id]')).sort((a,b)=>{
if (a.offsetTop != b.offsetTop) {
return a.offsetTop - b.offsetTop
} else {
return a.offsetLeft - b.offsetLeft;
}
}
).map((s)=>s.innerText).join('');
// test on this page

Keybase proof

I hereby claim:

  • I am mutoo on github.
  • I am mutoo (https://keybase.io/mutoo) on keybase.
  • I have a public key ASDbSW7pFHQ_32gL81HZ2l21cLR5IJKLjaWbREfUi7ZcbAo

To claim this, I am signing this object:

@mutoo
mutoo / roses-are-red.js
Last active September 10, 2019 00:05
Roses are red, violets are blue. Unexpected token { at line 32.
// inspired by https://twitter.com/nixcraft/status/1162020669242003456
console.log('Roses are red, violets are blue.');
// ooooooooo.
// `888 `Y88.
// 888 .d88' .ooooo. .oooo.o .ooooo. .oooo.o .oooo. oooo d8b .ooooo.
// 888ooo88P' d88' `88b d88( "8 d88' `88b d88( "8 `P )88b `888""8P d88' `88b
// 888`88b. 888 888 `"Y88b. 888ooo888 `"Y88b. .oP"888 888 888ooo888
// 888 `88b. 888 888 o. )88b 888 .o o. )88b d8( 888 888 888 .o
@mutoo
mutoo / no-if.py
Last active January 12, 2019 13:09
# define an exception for flow control
class ELSE(Exception): pass
# since we cannot write: `condition or raise ELSE()` => (syntax error)
# we need to define a func to raise an exception
def THEN():
raise ELSE()
# define our IF to make it looks intuitive
def IF(condition):