Commits

Xu Xiaodong committed 3e24837

add some little utils

Comments (0)

Files changed (14)

 #!/bin/sh
 #
-# author:    Xu Xiaodong <xxdlhy@gmail.com>
-# modified:  2011 Apr 19
+# name     : bar, status bar for dwm
+# author   : Xu Xiaodong <xxdlhy@gmail.com>
+# license  : MIT
+# created  : 2009 May 8
+# modified : 2012 May 27
 #
 
-#-- font --#
+# Configuration
+FNT='-artwiz-nu-medium-r-normal--11-110-75-75-p-90-iso8859-1' # font
+BG='#1e2320'                                                  # background
+FG='#999999'                                                  # forground
+XPOS=488                                                      # x
+YPOS=0                                                        # y
+DH=13                                                         # height
+DA=r                                                          # alignment
 
-FNT='-artwiz-nu-medium-r-normal--11-110-75-75-p-90-iso8859-1'
-
-#-- background --#
-
-BG='#1e2320'
-
-#-- forground --#
-
-FG='#999999'
-
-#-- x --#
-
-XPOS=720
-
-#-- y --#
-
-YPOS=0
-
-#-- height --#
-
-DH=13
-
-#-- alignment --#
-
-DA=r
-
+# Output
 conky | dzen2 -bg $BG -fg $FG -x $XPOS -y $YPOS -ta $DA -h $DH -p -e '' -fn $FNT
 #!/usr/bin/env perl
 #
-# name:      check_client_pro, check properties of a client
-# author:    Xu Xiaodong <xxdlhy@gmail.com>
-# license:   GPL
-# created:   2011 Apr 18
-# modified:  2011 Apr 28
+# name     : check_client_pro, check properties of a client
+# author   : Xu Xiaodong <xxdlhy@gmail.com>
+# license  : GPL
+# created  : 2011 Apr 18
+# modified : 2012 May 22
 #
 
-use Modern::Perl;
+use strict;
+use warnings;
 use autodie;
 
 my ( $instance, $class, $title ) = ('') x 3;
 
 open my ($in_fh), '-|', 'xprop';
 while (<$in_fh>) {
-    ( $instance, $class ) = split /", "/, $1 if /^WM_CLASS.*?"(.*)"/;
-    $title = $1 if /^WM_NAME.*"(.*)"/;
+  ( $instance, $class ) = split /", "/, $1 if /^WM_CLASS.*?"(.*)"/;
+  $title = $1 if /^WM_NAME.*"(.*)"/;
 }
 close $in_fh;
 
+#!/bin/sh
+
+
+cd /boot
+for f in *gentoo; do
+	cp -v $f ${f}-old
+done
 # author:    Xu Xiaodong <xxdlhy@gmail.com>
 # license:   GPL
 # created:   2011 Nov 17
-# modified:  2011 Nov 17
+# modified:  2012 Mar 22
 #
 
 use strict;
   }
 
   $title =~ s/&amp;/and/g;
+  $title =~ s/\s/_/g;
+  $title =~ s/://g;
+  $title =~ s/,.*$//g;
+  $title = lc $title;
 
   return $title;
 }

kindlegen

Binary file modified.
+#!/bin/sh
+
+ls -dlt --color=auto .[!.]?*
+#!/bin/sh
+#
+# name     : mountereader, mount ereader
+# author   : Xu Xiaodong <xxdlhy@gmail.com>
+# license  : MIT
+# created  : 2010 Oct 15
+# modified : 2012 May 12
+#
+
+DEV=$1
+DIR=/mnt/ereader
+
+if [ ! -d $DIR ]; then
+  mkdir -p $DIR
+fi
+
+mount -t vfat /dev/$DEV $DIR -o uid=1000,gid=100,utf8,dmask=027,fmask=137

mountkindle

-#!/bin/sh
-#
-# author:    Xu Xiaodong <xxdlhy@gmail.com>
-# modified:  2011 Nov 05
-#
-
-DEV=$1
-DIR=/mnt/kindle
-
-if [ ! -d $DIR ]; then
-  mkdir -p $DIR
-fi
-
-mount -t vfat /dev/$DEV $DIR -o uid=1000,gid=100,utf8,dmask=027,fmask=137
+#!/usr/bin/env ruby
+
+require 'fileutils'
+
+def remove(path)
+  system "git rm --cached #{path}"
+
+  files = [".git/config", ".gitmodules"]
+  files.each { |file| system "git config -f #{file} --remove-section submodule.#{path}"}
+
+  FileUtils.rmtree(path)
+end
+
+if ARGV.empty?
+  puts "Usage: $0 <path>"
+else
+  ARGV.each { |path| remove(path) }
+end
+#!/bin/sh 
+#
+# name:      rotate_pic
+# author:    Xu Xiaodong <xxdlhy@gmail.com>
+# license:   GPL
+# created:   2012 Mar 03
+# modified:  2012 Mar 03
+#
+
+DEGREES=90
+
+convert -rotate "$DEGREES" "$@"
+
+# vim: ai:et:ts=2:sw=2:sts=2:tw=78:ft=sh
 # author:    Xu Xiaodong <xxdlhy@gmail.com>
 # license:   GPL
 # created:   2011 Mar 25
-# modified:  2011 Apr 28
+# modified:  2013 Jul 24
 #
 
-use Modern::Perl;
+use strict;
+use warnings;
+
 use Image::Magick;
 
 sub _create_img {
 }
 
 sub run {
-    #my ( $width, $file ) = @ARGV;
-    my $width = 480;
-    my ($file) = @ARGV;
+    my ( $width, $file ) = @ARGV;
+    #my $width = 350;
+    #my ($file) = @ARGV;
 
     #die "Usage: $0 <width> <infile>\n" if @ARGV < 2;
     die "Usage: $0 <infile>\n" if @ARGV < 1;
+#!/usr/bin/env ruby
+# coding: utf-8
+#
+# name:      code/utils/unpack.rb
+# author:    Xu Xiaodong <xxdlhy@gmail.com>
+# license:   GPL
+# created:   2011 Dec 05
+# modified:  2011 Dec 05
+#
+
+zips = Dir['*.zip']
+zips.each do |zip|
+  system("unzip -q #{zip}")
+  zip_name = File.basename(zip, '.zip')
+  imgs = Dir['[12b]*.png']
+  imgs.each do |img|
+    img_name = zip_name + '.' + File.basename(img)
+    File.rename(img, img_name)
+  end
+end
+
+# vim: ai:et:ts=2:sw=2:sts=2:tw=78:ft=ruby
 #!/usr/bin/env perl
 #
-# name:      uptime
-# author:    Xu Xiaodong <xxdlhy@gmail.com>
-# license:   GPL
-# created:   2011 Apr  9
-# modified:  2011 Nov 17
+# name     : uptime, uptime for tmux
+# author   : Xu Xiaodong <xxdlhy@gmail.com>
+# license  : MIT
+# created  : 2011 Apr  9
+# modified : 2012 May 11
 #
 
 use strict;
 use warnings;
+use feature qw(say);
+use autodie;
+use Date::Calc qw(Time_to_Date);
 
-use feature qw(say);
-
-use Date::Calc qw(Time_to_Date);
-use autodie;
-
-open my ($in_fh), '<', '/proc/uptime';
-
+# Read current time
+open my ($in_fh), "<", "/proc/uptime";
 my $time = int( ( split / /, <$in_fh> )[0] );
-
 close $in_fh;
 
-my ( $hour, $min, $sec ) = ( Time_to_Date($time) )[ 3 .. 5 ];
-
-if ( $hour > 0 ) {
+# Convert time to second, minute, hour, and day
+my ( $day, $hour, $min, $sec ) = ( Time_to_Date($time) )[ 2 .. 5 ];
+if ( $day > 0 ) {
+  $day--;
+  say "${day}d ${hour}h ${min}m ${sec}s";
+}
+elsif ( $hour > 0 ) {
   say "${hour}h ${min}m ${sec}s";
 }
-elsif ($min > 0) {
+elsif ( $min > 0 ) {
   say "${min}m ${sec}s";
 }
 else {
 # Script for using ViM as a PAGER.
 # Based on Bram's less.sh.
 # Perlified by Magnus Woldrich.
+# Added Ruby support by Xu Xiaodong.
 
 # Removed unwanted 'features' in the original vimpager, including:
 # · python support
 linux=1
 
 less_vim() {
-  /usr/bin/vim -R -X --noplugins \
-    -c 'let no_plugin_maps=1'      \
-    -c 'set scrolloff=999'         \
-    -c 'set foldlevel=999'         \
-    -c 'runtime! macros/less.vim'  \
+  /usr/bin/vim -R -X \
+    -c 'let no_plugin_maps=1'     \
+    -c 'set scrolloff=999'        \
+    -c 'set foldlevel=999'        \
+    -c 'runtime! macros/less.vim' \
     -c 'set cc=0 tw=78 cursorline nonu norelativenumber nolist cmdheight=1' \
     "$@"
 }
   /bin/ps -p $1 -o ppid=
 }
 
-# Check if called from man, perldoc or pydoc
-if do_ps | grep -q '\man\|godoc\|perl\(doc\)\?\([0-9.]*\)\?\\>'; then
+# Check if called from man, rdoc or perldoc
+if do_ps | grep -q '\man\|ri\|perl\(doc\)\?\([0-9.]*\)\?\\>'; then
   proc=$$
   while next_parent=`ppid $proc` && [ $next_parent != 1 ]; do
     if pproc $next_parent | grep -q 'man\>'; then
       cat $file | sed -e 's/\[[^m]*m//g' | sed -e 's/.//g' | less_vim -c 'set ft=man' -; exit
+    elif pproc $next_parent | grep -q 'ri'; then
+      cat $file | sed -e 's/.//g' | less_vim -c 'set ft=rdoc' -; exit
     elif pproc $next_parent | grep -q 'perl\(doc\)\?\([0-9.]*\)\?\>'; then
       cat $file | sed -e 's/.//g' | less_vim -c 'set ft=perldoc' -; exit
-    elif pproc $next_parent | grep -q 'godoc'; then
-      cat $file | sed -e 's/.//g' | less_vim -c 'set ft=go' -; exit
     fi
     proc=$next_parent
   done