Skip to content

Instantly share code, notes, and snippets.

@HakurouKen
HakurouKen / bilibili-404s.js
Last active July 29, 2018 08:56
Download bilibili 404 images.
const fs = require('fs');
const path = require('path');
const request = require('superagent');
const mkdirp = require('mkdirp');
async function getMetas() {
const response = await request.get('https://www.bilibili.com/activity/web/view/data/31');
const { body } = response;
if (body.code === 0) {
return body.data.list;
@HakurouKen
HakurouKen / event-listener.js
Created October 19, 2017 09:54
A simple wrapper for event-listener to support ancient browsers.
let passiveSupported = false;
try {
// platform that doesn't support `addEventListener` or `Object.defineProperty`, obviously doesn't support `passive`.
let options = Object.defineProperty({}, 'passive', {
get: function() {
passiveSupported = true;
}
});
window.addEventListener('test-passive', null, options);
} catch (err) {}
// codes from https://github.com/madrobby/zepto/blob/601372ac4e3f98d502c707bf841589fbc48a3a7d/src/ajax.js#L344-L37
// serialize the form data for `Content-Type: application/x-www-form-urlencoded`
//
// Usage Example:
// ```javascript
// const YOUR_DATA = {foo: "bar", some: "baz"}
// fetch('/api/result', {
// method: 'POST',
// headers: {
// 'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8'
@HakurouKen
HakurouKen / Vector2.js
Created August 4, 2016 03:01
A 2-dimensional vector in javascript.
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
define([], factory);
} else if (typeof module === 'object' && module.exports) {
module.exports = factory();
} else {
root.Vector2 = factory();
}
}(this, function () {
function Vector2(x,y){
@HakurouKen
HakurouKen / bilibili-p-movie.py
Last active August 10, 2017 14:25
download bilibili p-movie gif.
#! /usr/bin/python
# -*- coding: utf-8 -*-
import requests
import os
URL = 'http://www.bilibili.com/index/index-icon.json'
def get():
resp = requests.get(URL)
@HakurouKen
HakurouKen / pixiv.py
Created April 7, 2016 11:52
Get pixiv original picture by id without login.
import requests
import re
from pyquery import PyQuery
from urllib2 import HTTPError
import os
class Picture():
'''
Get picture(s) from image page.
@Note: HTML changed after login.
@HakurouKen
HakurouKen / xkcd.py
Created January 24, 2016 16:16
get xkcd comic
import urllib,urllib2,json
import re
import os
import logging
from HTMLParser import HTMLParser
class HTMLStripper(HTMLParser):
'''
strip html tags
Solution from: http://stackoverflow.com/questions/753052/strip-html-from-strings-in-python#answer-925630
@HakurouKen
HakurouKen / bing-daily-wallpaper.py
Last active January 4, 2016 14:47
get bing daily wallpaper.
#! /usr/bin/python
# -*- coding: utf-8 -*-
import urllib,urllib2
import time
import json
import os
import re
import sys
@HakurouKen
HakurouKen / NeteaseMusicSigner.py
Last active August 8, 2017 14:48
A netease-music daily sign in program.
# -*- coding: utf-8 -*-
import urllib,urllib2
import json
import logging
class NeteaseMusicSigner(object):
'''
netease music signer
'''
@HakurouKen
HakurouKen / random.js
Created December 1, 2015 11:55
A simple javascript random library.
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
define([], factory);
} else if (typeof exports === 'object') {
module.exports = factory();
} else {
root['strHash'] = factory();
}
}(this, function () {