Skip to content

Instantly share code, notes, and snippets.

# -*- coding: gbk -*-
from __future__ import with_statement
import codecs
from datetime import datetime
from datetime import timedelta
from os import linesep
import cPickle
#import ClientCookie
from urllib2 import urlopen
@louy2
louy2 / dragToDownload.js
Last active August 29, 2015 14:10
A naive tampermonkey script enabling "drag to download" direct links. #user.js
// ==UserScript==
// @name Drag To Download
// @namespace
// @version 0.1
// @description Drag direct links to files to computer.
// @author Lou Yufan
// @match http://*/*
// @match https://*/*
// @grant none
// ==/UserScript==
@louy2
louy2 / Vagrantfile
Created December 31, 2015 07:23
Vagrantfile for a Ubuntu box bridging an OpenVPN via Shadowsocks
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(2) do |config|
config.vm.box = "ubuntu/trusty64"
config.vm.network "public_network", bridge: "<name of network interface>"
config.vm.provision "shell", inline: <<-INSTALL
@louy2
louy2 / ando16.go
Last active March 9, 2016 06:02
「眼帯」ゲットチャレンジ! https://paiza.jp/poh/ando (go) | 恋愛SLG: プログラミングで彼女をつくる|paizaオンラインハッカソン7
package main
import (
"fmt"
"os"
"log"
"strings"
"bufio"
"strconv"
)
func parseBookList (bookListStr string) []int {
@louy2
louy2 / ando17.go
Last active March 9, 2016 07:12
「縞ニーソセット」ゲットチャレンジ!https://paiza.jp/poh/ando | 恋愛SLG: プログラミングで彼女をつくる|paizaオンラインハッカソン7
package main
import (
"fmt"
"os"
"log"
"strconv"
"bufio"
)
func parseStdin() (int, int) {
stdin := bufio.NewScanner(os.Stdin)
@louy2
louy2 / ando11.go
Created March 9, 2016 09:59
「めがね」ゲットチャレンジ!https://paiza.jp/poh/ando | 恋愛SLG: プログラミングで彼女をつくる|paizaオンラインハッカソン7
package main
import (
"fmt"
"os"
"bufio"
"strconv"
)
func parseStdin() {
stdin := bufio.NewScanner(os.Stdin)
stdin.Scan()
@louy2
louy2 / installBluraySupport.cmd
Last active March 10, 2016 09:24
Install Blu-ray support for VLC media player on Windows
:: Name: installBluraySupport.cmd
:: Purpose: Install Blu-ray support for VLC media player on Windows
:: Usage: 1. Install VLC media player https://www.videolan.org/vlc/download-windows.html
:: * Install 64-bit version for 64-bit system, or this script doesn't work
:: 2. Download corresponding files from http://vlc-aacs.whoknowsmy.name/
:: 3. Put them under the same folder as this script
:: 4. Execute the script
@echo off
if not exist %PROGRAMDATA%\aacs (
@louy2
louy2 / Explanation.md
Last active March 31, 2016 15:39
`defer` from Go (Golang) to C -- in [Emulating "defer" in C, with Clang or GCC+Blocks](http://fdiv.net/2015/10/08/emulating-defer-c-clang-or-gccblocks) by [smokris](http://fdiv.net/users/smokris)

How does the magic work? Starting from the last line:

  1. __attribute__((cleanup(…))) — an extension to the C language, provided by GCC and Clang. When a variable is tagged with this attribute, the specified function is invoked when the variable leaves scope.
  2. void (^…)(void) = ^{ … } — C Blocks, an extension to the C language, provided by Clang or GCC with Apple’s Blocks patch. Allows you to define inline, anonymous functions. In this case, I’m taking the block that’s expected to appear after the defer macro and assigning it to a local variable.
  3. a##b — merge two strings into a single token. By combining defer_scopevar_ with the __COUNTER__, I get a unique variable name.
  4. void defer_cleanup(void (^*b)(void)) { (*b)(); } — a C function that takes a block as its parameter. I pass this function to __attribute__((cleanup(…))), and it gets invoked when the variable (defined in step #2) leaves scope. When the function is invoked, it just calls the block that was passed to it. (This indirection
/*
* Copyright (C) 2010, Google Inc.
* and other copyright owners as documented in JGit's IP log.
*
* This program and the accompanying materials are made available
* under the terms of the Eclipse Distribution License v1.0 which
* accompanies this distribution, is reproduced below, and is
* available at http://www.eclipse.org/org/documents/edl-v10.php
*
* All rights reserved.
function titleCase(str) {
return str.toLowerCase().replace(/(^[a-z]| [a-z])/g, function(match) {
return match.toUpperCase();
});
}