Never been to TextSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

About this user

Jason Hoffman http://textdrive.com/

« Newer Snippets
Older Snippets »
26 total  XML / RSS feed 

Grandma's Banana Bread

1.5 cups of sugar
1 cup of crisco
2.5 cups of flour
2 tsp baking soda
6 bananas (ripe, a little brown)
4 eggs


mix crisco and sugar, then mix eggs into it, then banana.

sift baking soda and flour together and fold it into the mix above.

put it in whatever you want to cook it (little loaf pans for example).

bake at 350 degree farenheit until the top is a bit brown.

Killing an outta whack webmin

ps ax | grep webmin | kill -9 `awk '{print $1}'`

Chained SSL certs in lighttpd

ssl.ca-file = "/usr/local/openssl/certs/chain.ca.crt"
ssl.pemfile = "/usr/local/openssl/certs/server.pem"

Mod_PHP that co-exists with PHP-CGI-FCGI

This is how you do the mod_php version of php-cgi-fcgi that co-exists quite nicely.

Do this one after the cgi-fcgi because what'll do is move the PHP-CLI into /usr/local/bin/php

You do need to have installed apache2.

Libxml also has to be there in /usr/local/ or if you are on Mac's Tiger, you can change the path to /usr and that should do ya.

./configure --enable-memory-limit --with-layout=GNU --with-config-file-scan-dir=/usr/local/etc/php --disable-all --enable-libxml --with-libxml-dir=/usr/local --enable-spl --with-regex=php --with-apxs2=/usr/local/apache2/sbin/apxs --prefix=/usr/local

Minimal extension-less build of PHP-CGI-FCGI

But what you do is add the --with-config-file-scan-dir where you add an extra extensions.ini file that dynamically loads different php extensions that you compile separately.

You will need to have compiled and installed libxml into /usr/local/ or if you are on Mac's Tiger, you can change the path to /usr and that should do ya.

./configure --enable-memory-limit --with-layout=GNU --with-config-file-scan-dir=/usr/local/etc/php --disable-all --enable-libxml --with-libxml-dir=/usr/local --enable-spl --with-regex=php --disable-cli --enable-force-cgi-redirect --enable-fastcgi


And you don't want to leave that /usr/local/bin/php binary sitting there because it's cgi-fcgi, you're going to replace it with php-cli

mv /usr/local/bin/php /usr/local/bin/php-fcgi


/usr/local/bin/php-fcgi is then the binary you use for all PHP CGI and FCGI.

SVNnotify post-commit hook

For example, the post-commit hook for the repository named "repos"
pacific# cat /home/svn/repos/hooks/post-commit


is

#!/bin/sh
REPOS="$1"
REV="$2"
/usr/local/bin/svnnotify -r $REV -C -d -H HTML::ColorDiff -p $REPOS -t staff@lists.textdrive.com --from jason@textdrive.com --reply-to staff@lists.textdrive.com

rip calendar attachments from an email (in ruby)

See here for context.

I did this for undees

#!/usr/local/bin/ruby
$: << '/home/username/usr/local/lib/ruby/site_ruby/1.8'
require 'tmail'

s = $stdin.read
mail = TMail::Mail.parse s
mail.parts.each do |part|
  if 'text/calendar' == part.content_type
    t = part.body
    t.gsub!(/=[\r\n]+/, '')
    t.gsub!(/=(\w\w)/) {$1.hex.chr}
    
    outPath = '/home/username/path/to/Calendar.ics'
    File.open outPath, 'w' do |f|
      f.write t
    end
    File.chmod 0664, outPath    
  end
end

Paula Deen's southern fried chicken recipe

I love the Paula Deen's fried chicken recipe but I'm always having to look up the URL:

3 eggs 
1/3 cup water 
About 1 cup hot red pepper sauce (recommended: Texas Pete) 
2 cups self-rising flour 
1 teaspoon pepper 
House seasoning, recipe follows 
1 (1 to 2 1/2-pound) chicken, cut into pieces 
Oil, for frying, preferably peanut oil
In a medium size bowl, beat the eggs with the water. Add enough hot sauce so the egg mixture is bright orange. In another bowl, combine the flour and pepper. Season the chicken with the house seasoning. Dip the seasoned chicken in the egg, and then coat well in the flour mixture. 
Heat the oil to 350 degrees F in a deep pot. Do not fill the pot more than 1/2 full with oil.
Fry the chicken in the oil until brown and crisp. Dark meat takes longer then white meat. It should take dark meat about 13 to 14 minutes, white meat around 8 to 10 minutes.

House Seasoning: 
1 cup salt 
1/4 cup black pepper 
1/4 cup garlic powder
Mix ingredients together and store in an airtight container for up to 6 months.

Forcing an SVN export to overwrite a directory

You can run --force to make an SVN export overwrite a folder rather than write into it

cd /usr/local/etc/
svn export --force --username user@textdrive.com --password apassword https://svn.textdrive.com/repos/setup/usr/local/etc/apache2

Mixed example of mod_deflate configuration for httpd.conf

<IfModule mod_deflate.c>
SetOutputFilter DEFLATE
SetInputFilter DEFLATE
#the two above compress everything unless excluded below
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.(?:exe|t?gz|zip|bz2|sit|rar)$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.pdf$ no-gzip dont-vary              
SetEnvIfNoCase Request_URI \.avi$ no-gzip dont-vary             
SetEnvIfNoCase Request_URI \.mov$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.mp3$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.mp4$ no-gzip dont-vary     
SetEnvIfNoCase Request_URI \.rm$ no-gzip dont-vary      
SetEnvIfNoCase Request_URI \.plist$ no-gzip dont-vary   
# Below is an example where you get rid of what's above and you explicity compress
AddOutputFilterByType DEFLATE application/x-httpd-php application/x-httpd-fastphp application/x-httpd-eruby text/html 
DeflateFilterNote ratio
DeflateCompressionLevel 9
IfModule>

Using HTTP conditions and url.access-deny to have Lighttpd block some user agents and referers

# deny access for Indy Library a Tester
$HTTP["useragent"] =~ "Indy" { url.access-deny = ( "" ) }
 
# deny access for a hydrocodone containing refer 
$HTTP["referer"] =~ "hydrocodone" { url.access-deny = ( "" ) }

Lighttpd proxy with Tracd specific example

$HTTP["host"] == "trac.textdrive.com" #the == is to exactly match
{
proxy.server = (
"" => (                               #this is for the root, can be a .extension in other uses
"trac" => (                           #just a name, your choice
"host" => "70.84.29.150", 
"port" => 9000 
           )
       )
                )
}

Upgrading a kernel

Install CVSup

cd /usr/ports/net/cvsup-without-gui
make install distclean


Make and populate the CVSup config file

touch /root/cvsup-stable-src.sup
echo '*default host=cvsup14.us.FreeBSD.org' >> /root/cvsup-stable-src.sup
echo '*default base=/var/db' >> /root/cvsup-stable-src.sup
echo '*default prefix=/usr' >> /root/cvsup-stable-src.sup
echo '*default release=cvs tag=RELENG_5' >> /root/cvsup-stable-src.sup
echo '*default delete use-rel-suffix compress' >> /root/cvsup-stable-src.sup
echo ' src-all' >> /root/cvsup-stable-src.sup


Update the /usr/src/ tree

cvsup /root/cvsup-stable-src.sup


Get rid of any old "worlds" and make a new one

rm -rf /usr/obj/usr
cd /usr/src/
make buildworld


Make changes to /usr/src/sys/i386/conf/GENERIC and name it was what you want.

Build the kernel, install the kernel, verify it and dot.old in /boot/, run mergemaster, and install the new world.

make buildkernel KERNCONF=GENERIC
make installkernel KERNCONF=GENERIC
mergemaster -p
make installworld
mergemaster
ls -l /boot/
shutdown -r now


Note, we often run in a securelevel of 1 and have immutable binaries in the system folders. You'll need to edit rc.conf.

nano /etc/rc.conf

kern_securelevel_enable="NO"
kern_securelevel="1"


Reboot
shutdown -r now


Then make things mutable

chflags noschg /bin/*
chflags noschg /sbin/*
chflags noschg /bin
chflags noschg /sbin
chflags noschg /usr/bin/*
chflags noschg /usr/sbin/*
chflags noschg /usr/bin
chflags noschg /usr/sbin

How to setup NTP on BSD

echo xntpd_enable=\"YES\" >> /etc/rc.conf
echo xntpd_program=\"/usr/sbin/ntpd\" >> /etc/rc.conf
echo xntpd_flags=\"-p /var/run/ntpd.pid\" >> /etc/rc.conf
ntpdate time.nist.gov
ntpdate time.nist.gov
mkdir /etc/ntp
touch /etc/ntp/drift

touch /etc/ntp.conf
echo server time.nist.gov >> /etc/ntp.conf
echo driftfile /etc/ntp/drift  >> /etc/ntp.conf
/etc/rc.d/ntpd start

Using pw to add a group and user in FreeBSD

Using "textdrive" as an example

pw groupadd textdrive
pw useradd textdrive -m -c "Main Textdrive account" -d /home/textdrive -s /bin/tcsh -G textdrive -k /usr/share/skel/


Then set the password:

passwd textdrive

Locking your Rails app to specific gem versions

To lock in a gem, you can modify your environments files, like how

config/environments.rb

has

# Require Rails gems.
require 'rubygems'
require_gem 'activerecord'
require_gem 'actionpack'
require_gem 'actionmailer'
require_gem 'rails'


Change it to the versions you are using, like

# Require Rails gems.
require 'rubygems'
require_gem 'activerecord', '<= 1.30'
require_gem 'actionpack', '<= 1.1.0'
require_gem 'actionmailer', '<= 0.5.0'
require_gem 'rails', '<= 0.9.1'

SSH tunneling for MySQL

No forking in background and verbose

ssh -2 -v -c blowfish -C -N user@servername.textdrive.com -L 3370/127.0.0.1/3306


Forking in background

ssh -2 -f -c blowfish -C -N user@servername.textdrive.com -L 3370/127.0.0.1/3306


Mod_security audit_log analysis

egrep 'Host:'  audit_log | sort | uniq -c | sort -rn | sed "s/mod_security-message\: Access denied with code 412\. //g" > 


egrep 'mod_security-message'  audit_log | sort | uniq -c | sort -rn  | mod_security-message-sort.txt


egrep "^HTTP/" audit_log | sed  "s/HTTP\/[01].[019] //g" | sort | uniq > HTTPcodes-audit.txt


Check out what's being used in the access_log headers

cat httpd-access.log | awk '{print $7}' | sort |  uniq -c | sort -rn | less

View processes, grep out by user and then kill all their PIDs

ps axu | grep user | kill -9 `awk{print $2}�`
« Newer Snippets
Older Snippets »
26 total  XML / RSS feed