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

Christopher Dale

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

Using notify-send with IRSSI

Requires libnotify, have fun!

use strict;
use vars qw($VERSION %IRSSI);

use Irssi;
$VERSION = '0.0.3';
%IRSSI = (
        authors     => 'Chrelad',
        contact     => '[email protected]',
        name        => 'notify',
        description => 'Display a pop-up alert for different events.',
        url         => 'http://google.com',
        license     => 'GNU General Public License',
        changed     => '$Date: 2007-02-07 12:00:00 +0100 (Thu, 7 Feb 2008) $'
);

#--------------------------------------------------------------------
# Created by Chrelad
# Feb 7, 2008
#--------------------------------------------------------------------

#--------------------------------------------------------------------
# The notify function for public message
#--------------------------------------------------------------------

sub pub_msg {
        my ($server,$msg,$nick,$address,$target) = @_;
        `notify-send -t 8000 "${target} : ${nick}" "${msg}"`;
}

#--------------------------------------------------------------------
# Irssi::signal_add_last / Irssi::command_bind
#--------------------------------------------------------------------

Irssi::signal_add_last("message public", "pub_msg");
#- end

Play sound for certain events in IRSSI

Perl script to allow sounds to be played for different events in IRSSI

Just keep adding handlers to IRSSI's pools pointing to different functions for different events or whatever you want.

use strict;
use vars qw($VERSION %IRSSI);

use Irssi;
$VERSION = '0.0.3';
%IRSSI = (
        authors     => 'Chrelad',
        contact     => '[email protected]',
        name        => 'alert',
        description => 'Play sounds for different events in IRSSI.',
        url         => 'http://google.com',
        license     => 'GNU General Public License',
        changed     => '$Date: 2007-02-07 12:00:00 +0100 (Thu, 7 Feb 2008) $'
);

#--------------------------------------------------------------------
# Created by Chrelad
# Feb 7, 2008
#--------------------------------------------------------------------

#--------------------------------------------------------------------
# The sound playing function for public message
#--------------------------------------------------------------------

sub pub_msg {
        my ($server,$msg,$nick,$address,$target) = @_;
        `mplayer -quiet ~/file.mp3 > /dev/null`;
}

#--------------------------------------------------------------------
# Irssi::signal_add_last / Irssi::command_bind
#--------------------------------------------------------------------

Irssi::signal_add_last("message public", "pub_msg");
#- end

Compressing a directory with rar on Linux

I've been struggling to get this to work for so long that when I finally got it going I had to throw it up here so I wouldn't lose it.
rar a -m5 -R output.rar /etc/

This will create a max compression (not taking into account dictionary sizes and the like) archive of the entire etc directory.

Fix orphaned users in MSSQL

Thanks to CodeProject for this code

Run this in the Query Analyzer (make sure the right database is selected first).

sp_change_users_login 'auto_fix', 'UserName'

Attach a screen before chrooting into your linux from scratch minimal system

This snippet is not so much a snippet as a tip. It's goal is to make your Linux from Scratch experience easier by allowing you the freedom of being able to attach and detach to a screen session from your host computer. Of course you would go through the book and change the chroot command to suit your needs, but just bear in mind that the chroot command you will use may be different from the one I use.

By using screen, you can start a lengthy compile and then detach, go about your business and re-attach another time. I use it primarily when I have to start a compilation from one computer, then later from another machine located somewhere else. Combined with SSH, this can be real handy.

desktop ~ # screen -S clfs
desktop ~ # chroot "${CLFS}" /tools/bin/env -i \
>     HOME=/root TERM="${TERM}" PS1='\u:\w\$ ' \
>     PATH=/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin \
>     /tools/bin/bash --login +h
root:/#


At any time, you can hit ctrl+a+d to detach. Then if you want to re-attach just type screen -r clfs and whamo, your right back where you left off.

Thanks again to ChrisS67 for helping me with my GCC problem (or me forgetting to install findutils) ;)

Disconnect Windows 2000 RDP session from command line

I use SSH to gain access to my Windows 2000 command line, so that will be reflected in the below steps.


Step #1: Connect to the server if you are not sitting at it
ssh username@win2000server -i privatekey

Step #2: Find out which sessions are currently active
query session

 SESSIONNAME       USERNAME                 ID  STATE   TYPE        DEVICE
>console                                     0  Conn    wdcon
 rdp-tcp                                 65536  Listen  rdpwd
 rdp-tcp#7         fakeuser                  1  Active  rdpwd

Step #3: We want to kill the connection with an ID of 1 (we can tell by the username and that it is active)
tsdiscon 1 /v

Disconnecting sessionID 1 from sessionname RDP-Tcp#7

That's it :) Easy eh?

Reset identity seed for a table

This SQL query will reset an identity seed to the specified value.

Thanks to this site for the answer:

http://www.thescripts.com/forum/thread657059.html

I know this works for MSSQL 2000 at least :)

DBCC CHECKIDENT('mytable', RESEED, 0) ;

Selecting different parts of a DATETIME with MSSQL

Thanks to this website for the information:

http://www.databasejournal.com/features/mssql/article.php/1442021

-- The syntax for pulling a certain part of a DATETIME is:
--
-- CONVERT(date_type[(length)],expression[,style])
--
-- The available styles are as follows:
--
-- NULL  Jun 24 2001 9:48PM
-- 1     06/24/01
-- 101   06/24/2001
-- 2     01.06.24
-- 104   24.06.2001
-- 108   21:48:00
-- 112   20010624
-- 121   2001-06-24 21:48:00.000

-- Some example usage:
SELECT CONVERT(DATETIME,GETDATE(),112) as date
-- Will output in YYYYMMDD format
SELECT CONVERT(DATETIME,client.birthday,101) as birthday
-- Will output in MM/DD/YYYY format

Selected items from a multiple select or checkboxes in VB.net

My co-worker found this code for VB.net that is used to access selected items from check boxes or multiple select boxes. If you've been wondering how to do this, this may help :)

The URL is http://dotnetjunkies.com/weblog/davetrux/archive/2003/11/14/3557.aspx

// The results of a mulitple-select list are also a NameValueCollection
Request.Form.GetValues(i)
// and the individual items are accessed like this:
Request.Form.GetValues(i)(j)

Limit equivelent for MSSQL

Props to this site for the answer:

http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=850&lngWId=5
// MySQL limit clause
SELECT emp_id,lname,fname FROM employee LIMIT 20,10

// MSSQL equivelent
select * from (
 select top 10 emp_id,lname,fname from (
    select top 30 emp_id,lname,fname
    from employee
   order by lname asc
 ) as newtbl order by lname desc
) as newtbl2 order by lname asc

"The main thing to remember is to deal with all your ORDER BY clauses and also to use the inner TOP as the sum of what you are looking for. In this example - 30 since you start at 20 and want 10 rows (20+10=30)."
_

OpenOffice.org 2.0 with GTK themes

In order to run OpenOffice 2.0 with GTK themes, you must first export an environment variable. This can be put in your bashrc or some other file that gets executed before OpenOffice.

Props to this site for the answer:

http://readlist.com/lists/lists.debian.org/debian-user/17/89593.html

#!/bin/bash
export OOO_FORCE_DESKTOP=Gnome
oowriter

VB.net Modified Preorder Tree Traversal

In order to utilize this, I would recommend reading the article located at sitepoint.com (Search google for modified preorder tree traversal). It took me quite some time and some help from a coworker to port this from PHP to VB.net. :D

Replace the application("sql").query("*") with your SQL code, I was inclined to write my own SQL class to make querying DB's easier, but you can do whatever you want.
record = application("sql").query("select * from categories order by lft asc")
dim output as new arraylist()
dim right as new arraylist()
do while not record.eof
  if right.count > 0
    do while right(right.count - 1) < record("rgt").value
      right.removeAt(right.count - 1)
      if right.count = 0 then exit do
    loop
  end if
  response.write(record("name").value & " is " & right.count & " levels deep in the tree..." & controlchars.cr)
  right.add(record("rgt").value)
  record.movenext
loop

SSH dynamic forward (Linux)

This command will create a dynamic forward from an SSH client to an SSH server. Basically what this does is allow you to use any local port (8080 in this example) as a proxy for any TCP application.

Feedback, suggestions and comments are all welcome!

# In the following example, we create a dynamic
# forward from port 8080 (client) to port 22 (host.net).

ssh -D 8080 username@host.net

# Now, we'll check out netstat to see what we
# have done.

netstat

# Active Internet connections (w/o servers)
# ...
# tcp 0 0 host.net:ssh client.com:60565 ESTABLISHED
# ...
#
# Awesome! Now we've got the connection. I'll add
# another post telling how to use this port as a
# socks proxy for any TCP application :)

Scripting schema updates in MSSQL #1

This SQL statement will alter a table only if a column in the table to be altered does NOT contain a column named 'FavoriteColorId'.

From: http://haacked.com/

IF NOT EXISTS
(
    SELECT * FROM [information_schema].[columns]
    WHERE    table_name   = 'Customer'
    AND      table_schema = 'dbo'
    AND      column_name  = 'FavoriteColorId'
)
BEGIN
    ALTER TABLE [dbo].[Customer]
    ADD FavoriteColorId int

Retrieve MSSQL table information

Retrieve tons of information (length, data type, name, etc.) of columns for a table. Works in (T|MS)SQL (all I've tested it in).

SELECT * FROM information_schema.columns WHERE table_name = 'Customers'
« Newer Snippets
Older Snippets »
15 total  XML / RSS feed