Skip to content

Instantly share code, notes, and snippets.

@redtower
redtower / google-analytics-trackingcode.js
Created January 13, 2011 14:10
Google Analyticsのトラッキングコード
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-********-*']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
@redtower
redtower / perlbrew.zshrc
Created January 13, 2011 14:36
perlbrewの設定ファイルを読み込む
if [ -e ~/perl5/perlbrew/etc/bashrc ] ; then
source ~/perl5/perlbrew/etc/bashrc
fi%
@redtower
redtower / checkparam-1.sh
Created January 13, 2011 14:45
シェルスクリプトでのコマンドラインオプションの処理
#!/bin/sh
while getopts ab:c: opt
do
case $opt in
a)
flga=1
;;
b)
flgb=1
@redtower
redtower / bar.pl
Created January 13, 2011 14:51
プログレスバーを出力する
#!/usr/bin/perl
$max = '30';
$len = '50';
@arey = ('|', '/', '-', '\\', '');
for ($num = 0;$num<=$max;$num++) {
local $| = 1;
$percent = int(($num/$max)*100);
$print = "["."%-"."$len"."s"."] "."%d%%"."\r";
$bar = '*' x int(($percent/100)*$len);
$ diff -c /usr/local/share/perl/5.10.0/XML/Atom/Client.pm /tmp/Client.pm
*** /usr/local/share/perl/5.10.0/XML/Atom/Client.pm 2009-08-03 15:06:36.000000000 +0900
--- /tmp/Client.pm 2009-04-24 17:34:23.000000000 +0900
***************
*** 228,236 ****
sub new {
my($class, $client) = @_;
my $ua = $class->SUPER::new;
-
- $ua->env_proxy;
@redtower
redtower / formv.sh
Created January 13, 2011 14:55
ファイル名一括変換コマンド
# ファイル名一括変換コマンド
function formv {
if [ $# -lt 2 ]; then
echo 'usage: formv s/pat1/pat2/ file ..';
else
s=$1; shift;
for i in "$@";
do
j=`echo "$i" | sed "$s"`;
echo "$i -> $j";
@redtower
redtower / pathogen.vimrc
Created January 13, 2011 14:57
pathogen.vimの.vimrcへの設定内容
filetype off
" pathogen.vimによってbundle配下のpluginをpathに加える
call pathogen#runtime_append_all_bundles()
call pathogen#helptags()
set helpfile=$VIMRUNTIME/doc/help.txt
" ファイルタイプ判定をon
filetype plugin on
@redtower
redtower / getopts.pl
Created January 13, 2011 15:00
複数の値を取るオプションを扱う
#!/usr/bin/env perl
use strict;
use warnings;
use Getopt::Long;
my @opt;
GetOptions("opt=s{,}" => \@opt);
foreach my $val ( @opt ){
@redtower
redtower / bitflg.c
Created January 13, 2011 15:01
ビットフラグ
#include <stdio.h>
enum {
NON = 0x00,
RED = 0x01,
BLUE = 0x02,
GREEN = 0x04,
} flg = NON;
void view();
@redtower
redtower / input_password.pl
Created January 13, 2011 15:03
パスワードを入力する
sub input_password() {
my $pass;
while (!$pass) {
print "Password --> ";
system "stty -echo";
chomp($pass = <STDIN>);
print "\n";
system "stty echo";
}