Skip to content

Instantly share code, notes, and snippets.

View cocoabox's full-sized avatar

cocoabox cocoabox

View GitHub Profile
#!/bin/bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
ATV="$DIR/atv"
ATV_URL="$DIR/atv-airplay-url"
TMP_DIR="/tmp/play-$RANDOM"
HTTP_SERVER="/usr/local/bin/http-server"
NPM="/usr/local/bin/npm"
if [[ ! -f "$1" ]]; then
javascript:void(function(){function e(e){let i="",o="",t="";return e>3600&&(e-=3600*(i=Math.floor(e/3600)),i=`${i} hrs`),e>60&&(e-=60*(o=Math.floor(e/60)),o=`${o} min`),e&&(t=`${e} sec`),[i,o,t].join(" ").trim()}function i(){window.__close_timer.timer&&window.clearInterval(window.__close_timer.timer),window.__close_timer.timer="",window.__close_timer.active=!1,window.__close_timer.sec=0,window.__close_timer.title=""}if(void 0===window.__close_timer&&(window.__close_timer={}),window.__close_timer.active){let o=e(window.__close_timer.sec);return window.confirm(`%E2%8F%B2 :${o}\n%F0%9F%9A%AB%E2%8F%B2?`)?(document.title=window.__close_timer.title,void i()):void 0}let o="10m",t=document.querySelector("video");if(t){o=e(Math.floor(t.duration-t.currentTime)+5)}let _=window.prompt("%E2%8F%B2%F0%9F%92%A4 %E2%86%92%E2%9D%8C",o).trim();if(!_)return;let r=_.toLowerCase().match(/^(([0-9\.]+)\s*(hours|hour|hrs|hr|h))?\s*(([0-9\.]+)\s*(minute|minute|mins|min|m))?\s*(([0-9\.]+)\s*(seconds|second|secs|sec|s))?$/),n=0;r[2]&&(n
@cocoabox
cocoabox / close-timer.js
Last active April 4, 2020 10:14
close timer bookmarklet
void(function(){
function sec2time_str(sec) {
let h='';
let m='';
let s='';
if (sec > 3600) {
h = Math.floor(sec / 3600);
sec -= 3600*h;
h = `${h} hrs`;
}
@cocoabox
cocoabox / cocoa-twitter-hide-annoying-tweets.js
Last active March 29, 2020 09:10
cocoa-twitter-hide-annoying-tweets.js
// ==UserScript==
// @name cocoa hide twitter annoying "Liked by XX" and "Promoted tweets"
// @namespace cocoabox.twitter.hide_promoted
// @description cocoa hide twitter annoying "Liked by XX" and "Promoted tweets
// @include https://twitter.com/*
// @version 1.0.0
// @run-at document-start
// @grant none
// ==/UserScript==
(function(){
@cocoabox
cocoabox / fuck-video.js
Created March 14, 2020 08:32
bookmarklet that removes annoying video from websites (please minify before use)
( function () {
let words = 'player vid';
words = window.prompt('block what?',words);
words = words.split(' ').map(n=>n.trim());
if (typeof window.__fuckTimer__ !== 'undefined') return;
const del = function(node) {
if (!node) return;
node.parentNode.removeChild(node);
@cocoabox
cocoabox / rakuten-box.js
Created February 20, 2020 10:40
楽天ページの要らない情報を飛ばしたい!
javascript:(function(document){ function init() { if (! document.__has_yellowfade__) { let node = document.createElement('style'); node.innerHTML = ` @keyframes yellowfade { from { background: yellow; } to { background: transparent; } } .yellowfade-box { animation-name: yellowfade; animation-duration: 2s; }`; document.body.appendChild(node); document.__has_yellowfade__ = true; } } function hilite(selector, want_focus) { let elem = document.querySelector(selector); if (! elem) return; if (want_focus) { elem.scrollIntoView(); } elem.classList.add('yellowfade-box'); setTimeout(function(){ elem.classList.remove('yellowfade-box'); }, 2000); } init(); hilite('#offers', true); hilite('#rakutenLimitedId_aroundCart');})(window.document);
@cocoabox
cocoabox / savings.js
Last active December 26, 2019 19:15
savings.js
/*
--input.txt--
13 5 5
900 600 700 600 2000 2300 1600 500 2800 1500 1900 2200 2500
--EOF--
*/
process.stdin.resume();
process.stdin.setEncoding('utf8');
const LOG=true;
var stdin = '';
@cocoabox
cocoabox / max-subarray-sum.php
Last active December 16, 2019 09:25
max subarray sum
<?php
//
// approach
// for any array A0, A1,.. Ai-1, Ai, Ai+1, ... An
//
// to find max sum up to Ai, life is very easy if we already know
// max sum up to A[i-1], in particular, max sum up to Ai is :
//
// bigger value among (
// MaxSum(A0,A1,..An-1) + Ai, // continue adding Ai to the current sum
@cocoabox
cocoabox / find_intersection.php
Created December 16, 2019 07:11
矩形の重なりを求めるプログラム
<?php
class Range {
public $begin;
public $end;
function __construct($begin, $end) {
$this->begin = $begin;
$this->end = $end;
}
function __toString() {
@cocoabox
cocoabox / to-mp4-baseline.sh
Created November 29, 2019 09:25
to-mp4-baseline.sh
# .bashrc
# =======
to-mp4-baseline ()
{
if [ -z "$2" ]; then
OUT="$1.mp4";
else
OUT="$2";
fi;
if [ -f "$OUT" ]; then