Skip to content

Instantly share code, notes, and snippets.

@hail2u
hail2u / megaupload-dd.user.js
Created October 11, 2009 14:57
MEGAUPLOAD downloader
// ==UserScript==
// @name MEGAUPLOAD direct downloader
// @namespace http://hail2u.net/
// @include http://www.megaupload.com/?d=*
// ==/UserScript==
window.location.href = window.location.href.replace(/\/\?d=/, "/mgr_dl.php?d=");
@hail2u
hail2u / index.js
Last active July 12, 2020 10:25
Hail2uの雑記記事をソースにランダムなアルファベットや数字がちょくちょく混ざる日本語のテキスト・データを作るスクリプト
// node index.js --count=5 --format=html --type=paragraph
// --count: 1-32 (default; 5)
// --format: html, txt (default)
// --type: list, paragraph (default)
import fs from "fs";
import minimist from "minimist";
const select = (data) => data[Math.floor(Math.random() * data.length)];
  • foo
    • bar
      • baz
        • qux
          • quux
            • quuz
              • corge
                • grault
                  • garply
  • waldo
@hail2u
hail2u / inline-css.js
Last active May 8, 2020 06:05
HTMLファイルを渡すと、参照しているCSSファイルを読み、必要なルールだけインライン化するやつ
// $ node inline-css.js <path-to-html-file>
import fs from "fs/promises";
import jsdom from "jsdom";
import postcss from "postcss";
const { JSDOM } = jsdom;
const hasNode = (document, selector) => {
if (selector.includes(":")) {
const to8Chunks = (previous, current, index) => {
const remainder = index % 8;
if (!previous[remainder]) {
previous.push([]);
}
previous[remainder].push(current);
return previous;
};
# show Git branch name with some informations
# normal: ~/git/foo (master)
# something to commit: ~/git/foo (master*)
# not pushed to origin: ~/git/foo (master!)
# something to commit and not pushed to origin: ~/git/foo (master*!)
# Git: get branch status
function git_get_branch_status {
local STATUS=`git status 2> /dev/null | tail -n1`
[[ ${STATUS} != "nothing to commit (working directory clean)" ]] && echo -ne "*"
@hail2u
hail2u / list-unused-custom-properties.js
Created August 29, 2019 05:31
List unused custom properties
// list unused custom properties
// $ node list-unused-custom-properties.js <FILENAME>
const fs = require("fs");
const postcss = require("postcss");
const css = postcss.parse(fs.readFileSync(process.argv[2], "utf8"));
const customProperties = {};
css.walkDecls(decl => {
if (decl.prop.startsWith("--")) {
@hail2u
hail2u / data.json
Last active August 27, 2019 10:23
mustache.js v3.0.2 and partial indentation
{}
@hail2u
hail2u / file0.txt
Created July 27, 2012 13:59
NodeでHTMLの数値文字参照変換ツールを書く ref: http://qiita.com/items/020d89f9b6fdfcfad8b2
#!/usr/bin/env node
var fs = require('fs');
var fd = process.stdin.fd;
var length = fs.fstatSync(fd).size;
var input = fs.readSync(fd, length)[0];
var escape = escapeHTML(input);
console.log(escape);
@hail2u
hail2u / file3.txt
Created August 4, 2013 11:56
Handlebars.jsでSSIライクなインクルードを行うヘルパー関数 ref: http://qiita.com/hail2u/items/ea68e89355d25d357ee3
$ node include-helper.js test,tmpl
<p>apple is sweet and red.</p>
<p>orange is sweet and orange.</p>
<p>grape is sweet and purple.</p>