Skip to content

Instantly share code, notes, and snippets.

@BusyJay
BusyJay / oj_reader.rs
Last active September 17, 2016 17:07
Rust stdin helper snippets for ojer
use std::io::{self, BufReader, Read, Stdin, Bytes};
use std::fmt::Debug;
use std::str::FromStr;
/// A stdin helper to deal with normal oj input.
pub struct OjReader<R> {
bs: Bytes<BufReader<R>>,
}
pub fn from_stdin() -> OjReader<Stdin> {
@BusyJay
BusyJay / auto_collect.js
Last active October 3, 2016 10:57
Collect small tv in bilibili automatically
// to use this script, you should allow popups on live.bilibili.com.
function collect(url, times, w, cb) {
var img = w.document.querySelector(".small-tv-draw").querySelector(".draw-img");
if (img.length == 0) {
console.error("page " + url + " not loaded, there should be a bug.");
w.close();
cb();
} else {
img.click();
console.info(url + " is collected");
@BusyJay
BusyJay / rautossh.rs
Created March 14, 2020 13:13
A script that restart failed ssh connection automatically.
use std::os::windows::process::CommandExt;
use std::process::{self, Command, Stdio};
use std::time::{Duration, Instant};
use std::{env, thread};
fn main() {
let mut args: Vec<_> = env::args().collect();
if let Some(idx) = args.iter().position(|x| x == "--detach") {
args.remove(idx);
if let Err(e) = Command::new(&args[0])
@BusyJay
BusyJay / CountMyWork.go
Last active December 26, 2023 07:16
An easy script to count your work on Github.
package main
import (
"bytes"
"encoding/json"
"flag"
"fmt"
"io/ioutil"
"log"
"net/http"