Skip to content

Instantly share code, notes, and snippets.

@moccos
moccos / download_rename.pl
Created November 10, 2012 21:12
[Perl] Rename downloaded file like "file(1).zip"
#!/usr/bin/perl
while(1) {
foreach(<*(1)*>) {
next if (/\.crdownload$/);
/(\S+)\s?\(\d\)(\.[^\.]+)?$/;
$new_name = "$1$2";
if (rename($_, $new_name)) { print "$_ -> $new_name\n"; }
#else { print STDERR "failed to rename: $_"; }
}
sleep(1);
@moccos
moccos / sane_opera.ahk
Created February 2, 2013 02:00
[AHK] AutoHotKey script to "fix" Opera's strange keyboard shortcuts.
#IfWinActive ahk_class OperaWindowClass
{
^k::Send {F8} ; Search
^Tab::Send ^{F6} ; Next tab
^PgUp::Send ^{F6}
^+Tab::Send ^+{F6} ; Prev tab
^PgDn::Send ^+{F6}
}
@moccos
moccos / find.pl
Last active March 11, 2020 00:55
[Perl] GNU find wrapper to set -regextype.
#!/usr/bin/perl
use strict;
my $idx = 0;
my @preopt = ("-H", "-L", "-P");
my $command = "find";
my $regex_type = " -regextype posix-egrep";
# check @preopt
for (; $idx <= $#ARGV; $idx++) {
@moccos
moccos / PartakeTitleCollector.js
Last active December 13, 2015 17:19
[Chrome] PartakeTitleCorrector:
document.title = "PARTAKE: " + document.body.getElementsByTagName("h1")[0].innerText;
// binary is here: http://www.moccos.info/_files/13/PartakeTitleCorrector.zip
@moccos
moccos / first.fs
Last active December 13, 2015 19:59
My first F# code. F#談話室(2) http://www.zusaar.com/event/491059 で約90分使って書いたもの。
open System
open System.Drawing
open System.Windows.Forms
// Configuration
let nGrid = 12
let gridSize = 30
let stoneSize = gridSize - 2
let fieldMargin = 10
let fieldEdgeMax = fieldMargin + nGrid * gridSize
@moccos
moccos / input.py
Created February 19, 2013 15:42
2/18 第1回 Jubatusハンズオン http://partake.in/events/cf1df52e-9e4e-45e0-b3ec-e64a9674bab9 で遊んだコード断片
host = '127.0.0.1'
port = 9199
name = 'test'
import jubatus
from jubatus.classifier.types import datum
client = jubatus.Classifier(host, port)
train_data = [
@moccos
moccos / open_link.js
Created February 23, 2013 21:27
HTMLFormElementで開くタブを変える。
@moccos
moccos / open_link_window.js
Last active December 14, 2015 03:29
HTMLFormElementを使って、新しいウィンドウで開く。
@moccos
moccos / option_early_return.fs
Last active December 16, 2015 18:39
F# computation expression practice.
type OptionReturnBuilder() =
member __.Bind(opt, expr) = opt |> function
| Some x -> Some x
| None -> expr opt
member __.Return(x) = x
member __.ReturnFrom(x) = x
member __.Delay(f): option<_> = f ()
let optionr = OptionReturnBuilder()
@moccos
moccos / WindowsConsoleTest.cpp
Last active December 22, 2015 12:39
Windows console output test. Some functions fail when the stdout is redirected to a file.
#include <stdio.h>
#include <tchar.h>
#include <Windows.h>
#include <wincon.h>
int _tmain(int argc, _TCHAR* argv[])
{
TCHAR *lbuf = L"I love beef!\n";
CHAR *buf = "I love pork!\n";
HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);