Skip to content

Instantly share code, notes, and snippets.

View maple3142's full-sized avatar

maple maple3142

View GitHub Profile
@maple3142
maple3142 / example.js
Created September 8, 2017 12:38
require from unpkg in browser (need jquery)
//require single module
require('vue').then(function(Vue){
//do something
})
//require multiple module
require(['jquery','lodash','lowdb']).then(function([$,_,low]){
//do something
})
#include<iostream>
using namespace std;
int sum(int a,int b){
return (a+b)*(b-a+1)/2;
}
int main(void){
ios::sync_with_stdio(false);
int n;
while(cin>>n){
@maple3142
maple3142 / ad.json
Created December 16, 2017 02:03
bahamut fake ad api
{ "banner": {}, "native_major": { "Android__": [] }, "native_minor": { "Android__": [], "iOS__": [] } }
@maple3142
maple3142 / cache.py
Created January 21, 2018 05:29
function cache
from functools import wraps
def cached(fn):
name=fn.__name__
mycache={}
if not name in mycache:
mycache[name]={}
@wraps(fn)
def cachefn(*args,**kwargs):
key=(args,frozenset(kwargs))
if key in mycache[name]:
@maple3142
maple3142 / ad.json
Created February 5, 2018 08:18
fake bahamut ads api response
{"banner":{},"native_major":{"Android__":[],"iOS__":[]},"native_minor":{"Android__":[],"iOS__":[]}}
[
{
"id": "1",
"type": "大吉",
"poem": "七寶浮圖塔,高峰頂上安,眾人皆仰望,莫作等閒看",
"explain": "就像出現了用美麗寶石做成的佛塔般地,似乎會有非常好的事情。因為能改用放眼萬事的立場,可以得到周圍的人們的信賴吧。合乎正道的你的行為,能被很多人的認同及鼓勵。不用隨便的態度看事情,用正確的心思會招來更多的好的結果。",
"result": {
"願望": "會充分地實現吧。",
"疾病": "會治癒吧。",
"盼望的人": "會出現吧。",
[
{
"id": "1",
"type": "大吉",
"poem": "七寶浮圖塔,高峰頂上安,眾人皆仰望,莫作等閒看",
"explain": "就像出現了用美麗寶石做成的佛塔般地,似乎會有非常好的事情。因為能改用放眼萬事的立場,可以得到周圍的人們的信賴吧。合乎正道的你的行為,能被很多人的認同及鼓勵。不用隨便的態度看事情,用正確的心思會招來更多的好的結果。",
"result": {
"願望": "會充分地實現吧。",
"疾病": "會治癒吧。",
"盼望的人": "會出現吧。",
@maple3142
maple3142 / cvt.js
Created March 11, 2018 11:41
convert userscript's metablock to javascript object
const m=`
// @name 動畫瘋工具箱
// @namespace https://blog.maple3142.net/
// @version 0.4
// @description 取得動畫的 m3u8 網址,下載彈幕為 json,去除擋廣告的警告訊息
// @author maple3142
// @match https://ani.gamer.com.tw/animeVideo.php?sn=*
// @require https://cdn.jsdelivr.net/npm/m3u8-parser@4.2.0/dist/m3u8-parser.min.js
// @grant none
`
@maple3142
maple3142 / 螺旋矩陣.js
Created March 16, 2018 06:50
【問題】螺旋矩陣(有非C語言的解法嗎 https://forum.gamer.com.tw/C.php?bsn=60076&snA=4453621
const n=3
function c2da(n,m){
const ar=[]
for(let i=0;i<n;i++)ar[i]=[]
return ar
}
const ar=c2da(n+1,n+1)
const vis=c2da(n+1,n+1)
const X=[1,0,-1,0]
const Y=[0,-1,0,1]
(await Promise.all($('a').toArray().filter(x=>/^http.*\d{10}$/.test(x.textContent)).slice(1).map(r=>r.textContent.trim().replace('http:','https:')).map(x=>{
return Promise.all([fetch(x).then(x=>x.text()),fetch(x+'?pn=2').then(x=>x.text())])
}))).map(x=>{
if($(x[0]).find('.l_pager').text())return x.join('')
else return x[0]
}).map(x=>$(x).find('.d_post_content').toArray().reduce((d,x)=>{
const div=document.createElement('div')
div.innerHTML=x.innerHTML.replace(/<br>/g,'\n').replace(/&lt;/g,'<').replace(/&gt;/g,'>')
if(div.textContent.replace(/(\n| )/g,'').length>=50&&!div.textContent.includes('广告')&&!div.textContent.includes('免费'))return d+'\n'+div.textContent