Archive for the ‘*nix’ Category

comment out/affect mulitple lines in vi

Sunday, December 11th, 2011

Ever wanted to comment out multiple lines of code while writing shell scripts in vi, but didn’t want to pound your keyboard for half an hour doing it?

(I#Escape j.j.j.j. = carpal tunnel)

Here’s the nerdy way to do it:

:.,+N-1 s/^/#/g

Where N-1 is the number of lines minus one that you want to comment out, and s/^/#/g is the regular expression (the pattern between the first two slashes is what you want to replace, in this case the beginning of the line, and the pattern between the last two slashes is what you want to replace it with).

For example, if you’re a bad coder like me and want to comment out 500 lines of code, you would do:

:.,+499 s/^/#/g

linux-3.1.x power regression issues i915 core-i5,i7

Saturday, November 5th, 2011

there’s been a lot of talk about the power regression issues with the linux-3.x kernel on the new intel sandy bridge core i3,5,7 chipsets.

after spending several hours with this issue on a new thinkpad x220 laptop, i’ll share a solution thanks to the peeps over at #fedora-qa

***UPDATE – Kernel patch now available at LKML – https://lkml.org/lkml/2011/11/10/467 (i’ll report my results with this when I get a chance to build the patch rpm, i’ll post) As of now I’m still having issues with the iwlagn module.

fyi , i’m running fedora 16 RC5 x86_64 but these kernel parameters apply to any distro

you’ll want to pass the following parameters at runtime or at boot, however you like :

pcie_aspm=force power_save=3 i915.i915_enable_fbc=1 i915.i915_enable_rc6=1 i915.lvds_downclock=1

then generate a new grub2 (or 1.xx) config file and reinstall grub to your mba on the disk.

my results were pretty good. idle 70% lcd brightness from 16W to 7.5W average and 5.76W baseline. I’ve yet to tell but it seems at about 16 hour battery life.

you’ll also want irqbalance installed to take best advantage of power management balance, distribution and usage over the processors

finally, i use this bash script at runtime so further fine tune my acpi power usage

#!/bin/bash
echo 1 > /sys/module/snd_hda_intel/parameters/power_save

for i in /sys/class/scsi_host/host?/link_power_management_policy; do
echo min_power > $i
done

for i in /sys/bus/usb/devices/*/power/autosuspend; do
echo 1 > $i
done

for i in /sys/bus/{pci,i2c}/devices/*/power/control; do
echo auto > $i
done

echo 1 > /sys/devices/system/cpu/sched_mc_power_savings

echo 5 > /proc/sys/vm/laptop_mode
echo 0 > /proc/sys/kernel/nmi_watchdog
#echo Y > /sys/module/snd_ac97_codec/parameters/power_save
echo 1 > /sys/devices/system/cpu/sched_mc_power_savings
echo ondemand > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
echo 1500 > /proc/sys/vm/dirty_writeback_centisecs
echo 60 > /proc/sys/vm/dirty_ratio
echo 20 > /proc/sys/vm/dirty_background_ratio
echo 1500 > /proc/sys/vm/dirty_expire_centisecs
for i in /sys/bus/usb/devices/*/power/autosuspend; do echo 1 > $i; done
# those sysctl’s are only available if you have an AHCI compatible SATA
# controler and use kernel > 2.6.24-rc2 (or use Kristen ALPM patchset) :
echo min_power > /sys/class/scsi_host/host0/link_power_management_policy
echo min_power > /sys/class/scsi_host/host1/link_power_management_policy
echo 1 > /sys/module/snd_hda_intel/parameters/power_save
echo Y > /sys/module/snd_hda_intel/parameters/power_save_controller
ifconfig em1 down
ifconfig virbr0 down
/etc/init.d/libvirtd stop
rmmod bluetooth
hdparm -B 1 -S 12 /dev/sda > /dev/null
echo 1 > /proc/sys/vm/swappiness
service atd stop &> /dev/null
service cron stop &> /dev/null
service anacron stop &> /dev/null

Want to monitor your power usage with dstat? Try this

dstat -t -c –power –top-cpu –top-io –top-bio –top-latency –top-cputime –power –battery-remain 10

dealing with a sd2f file

Monday, August 15th, 2011

it took me a while to find out (on google) how to deal with a sd2f audio file. I figured I’d share the solution with others

I wanted to listen to a sd2f audio while. Further investigation revealed this is a ‘Toast’ File for Mac. I don’t run Mac OS, I run Linux

1- Download + Install audacity
– yum install -y audacity
– apt-get install audacity
2. Open the file
– Point File -> Import Raw Data
3. Export the file
– Point, File -> Export
– Select your audio export format of choice.
– Done.

php-fpm /nGINX on CentOS-5.6-RELEASE

Friday, June 17th, 2011

We’ve skeeet enterprise baby … Want to be on your way to a load balanced lightning fast cached-up wordpress server with very little resources? Check up on this!

We dig RedHat, package names are standard and not as confusing as Debian/Ubuntu. This new standard world is new to us. Ridin` with the King!

yum install openssl-devel curl-devel curl libjpeg-devel libjpeg libpng libmcrypt mysql++-devel freetype-devel freetype t1lib-devel t1lib t1utils libc-client-devel libc-client bzip2-devel bzip2-libs libevent-devel libevent gd-devel gd-progs gd libxml2-devel libxml2 expat-devel expat sqlite-devel sqlite libjpeg-devel libpng-devel libmcrypt-devel
mysql-devel gcc pcre-devel redhat-lsb-graphics libexif ImageMagick

Now follow rest of directions here: . You will need to build libmemcached from source, however. I will post further instructions later for all inquiring minds.

But for sho` , if you are running x_86_64 you will need to use the –with-libdir=lib64 when you configure php, other-wise you haz problems with libmysqlclient (script won’t know where to find mySQL)

adapter missing in exported vm?

Friday, June 11th, 2010

I’m adding this to my checklist when exporting a virtual machine via virtualbox.

on the guest image,

  1. become superuser
  2. echo “” > /etc/udev/rules.d/70-persistent-net.rules
  3. shutdown -r now
  4. open up the 70 persistent net rules again. change eth1 to eth0
  5. shutdown -h now
  6. go ahead and export (VBoxManage export $image_name -o $image_name.ovf)

For me, this saved a lot of asprin when importing VM on a new machine. This permits udev to assign the first available eth adpater to your machines virtual mac address.

setup a webserver with nginx fcgi for debian/ubuntu

Sunday, June 7th, 2009

this was the BEST guide i’ve found EVER for setting up nginx with FCGI, postfix, wordpress, rewrites, and securing your installation…. it was also based on an install for a linode slice… ( i also use linode )

thanks a lot to guvnr he really put a lot of work into this…

great thorough tutorial

Set Up Unmanaged VPS (4 Newbies) – Part 1: VPS (Virtual Private Server) vs Shared vs Dedicated