Monday, December 15, 2008
Easy remove duplicates from table (database platform neutral)
WHERE "id" NOT IN
(SELECT MAX("dt"."id")
FROM table_name As dt
GROUP BY "dt"."field_that_records_have_duplicate_info_in", "dt"."another_field_that_records_have_duplicate_info_in");
Sunday, December 14, 2008
serve static files from the media folder using the django runserver command
SO I checked the documenation located at: http://docs.djangoproject.com/en/dev/howto/static-files/
and it walks you through how to setup the Django development script to serve files from the media folder using a secret "serve" view built into Django.
to turn it on you just drop in the route for it in the URLconf (ie urls.py) config file into the urlpatterns array:
urlpatterns = patterns('',
(r'^site_media/(?P
{'document_root': settings.STATIC_DOC_ROOT}),
)
the above example uses a custom static variable from the settings.py file. If your going to do that make sure you import settings.py at the top your urls.py.
from django.conf import settingsAn even smarter way to do things is to only serve static files when you are in debug (dev) mode by including the followling logic to check for debug=true around your route definition:
...
(r'^site_media/(?P.*)$', 'django.views.static.serve',
{'document_root': settings.STATIC_DOC_ROOT}),
if settings.DEBUG:
urlpatterns += patterns('',
(r'^media/(?P
{'document_root': settings.DEV_MEDIA_ROOT, 'show_indexes': True}),
)
That's pretty much it, except that you need to remember that if your going to use /media/ as the directory to serve your static files from to also change the name of the media folder that the Admin scaffolding defaults to. I started out with the scaffolding media path set to /media/ and it was not letting the route defined above execute. Took me forever to figure out that the two media folders were conflicting. SO in you settings.py make sure that ADMIN_MEDIA_PREFIX is set to something other than /media/ maybe something like:
ADMIN_MEDIA_PREFIX = '/admin_media/'
Django 1.x and tinyMCE
The current production release of django (1.0.2) at the time of this article is using the django newforms library for the admin scaffolding. I think at somepoint leading right up to the 1.0 major release there was two ways of customizing this newforms admin scaffolding. One involved including a special Admin class inside of all of your model classes
ex:
(from models.py)
class StaffBio(models.Model):
name = models.CharField("Name", maxlength=128,db_index=True)
position = models.CharField("Position", maxlength=128,db_index=True)
bio = models.TextField("Biography")
fote = ImageField("Photo", null=True,
blank=True, upload_to="E:/home/dev/storage/StaffBio/fote")
pageorder = models.IntegerField("Appearance on bio page",
choices=SITEORDER_CHOICES, db_index=True)
jobcat = models.CharField(maxlength=1,
choices=JOBCAT_CHOICES, db_index=True, default='P')
def __repr__(self):
return self.name
class Meta:
ordering = ['name', 'jobcat', 'status']
verbose_name = "Staff Bio"
class Admin:
fields = (
('Content', {'fields': ('name','position','bio','fote', 'jobcat', 'pageorder')}),
)
list_display = ( 'name', 'jobcat' )
list_filter = ['status', 'jobcat']
search_fields = ['name']
js = ['tiny_mce/tiny_mce.js', 'js/textareas.js']
and the other (currently best practice way) of doing it involved creating a new special configuration file called admin.py and putting it in the same directory as your models.py
ex:
(from admin.py)
from mew.cms.models import ArtistsInResidencePage
from django.contrib import admin
class ArtistsInResidencePageAdmin(admin.ModelAdmin):
class Media:
js = ('tiny_mce/tiny_mce.js', 'textarea.js')
admin.site.register(ArtistsInResidencePage, ArtistsInResidencePageAdmin)
so to get tiny mce to work, upload it to your media folder and then create new classes inside your admin.py file called ModelNameAdmin then register both the original model and it's Admin counterpart witha call do admin.site.register(ModelName, ModelNameAdmin)
remember that the location of the .js files is relative to the /media/ folder meaning that whatever you put in for the two values here: js = ('tiny_mce/tiny_mce.js', 'textarea.js') will have the word /media/ prepended to it.
Tuesday, December 9, 2008
Tuesday, December 2, 2008
delete all files that match a filename in the current directory recursively
Tuesday, November 18, 2008
creating allias ip addresses on redhat
network-scripts/ifcfg-eth0:0
# cp /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-
scripts/ifcfg-eth0:0
Open file /etc/sysconfig/network-scripts/ifcfg-eth0:0 using vi text
editor:
# vi /etc/sysconfig/network-scripts/ifcfg-eth0:0
Find entry that read as follows:
DEVICE=eth0
Replace with:
DEVICE=eth0:0
Find entry that read as follows:
IPADDR=xxx.xxx.xxx.xxx
Replace it with your actual IP address:
IPADDR=192.168.1.7
At the end your file should like as follows:
DEVICE=eth0:0
IPADDR=192.168.1.7
NETMASK=255.255.255.0
NETWORK=192.168.1.0
ONBOOT=yes
NAME=eth0:0
Open file /etc/sysconfig/network-scripts/ifcfg-eth0 and make sure file
does not have a GATEWAY= entry:
# vi /etc/sysconfig/network-scripts/ifcfg-eth0
Find the entry that read as follows:
GATEWAY=your-ip
Remove or comment it out by prefixing # (hash) :
# GATEWAY=192.168.1.254
Save the file. Add the GATEWAY= to your /etc/sysconfig/network:
# vi /etc/sysconfig/network
Append or modify GATEWAY entry:
GATEWAY=192.168.1.254
Save the file. Reboot the system or run the following command:
# ifup eth0:0
OR
# service network restart
Tuesday, September 23, 2008
Interesting Hosting Services
http://www.gogrid.com/
Monday, September 22, 2008
massive regex to convert comma delimited file to xml of known dtd
"$1","$2","$3","$4","$5","$6","$7","$8","$9","$10","$11","$12","$13","$14","$15","$16","$17","$18","$19","$20","$21","$22","$23","$24","$25","$26","$27","$28"
<event>
<event_id>$1</event_id>
<title1>$2</title1>
<discipline>$3</discipline>
<parent_teacher>$4</parent_teacher>
<start_date>$5</start_date>
<end_date>$6</end_date>
<date_label>$7</date_label>
<org_id>$8</org_id>
<org_name>$9</org_name>
<description>$10</description>
<grade_level>$11</grade_level>
<prog_type>$12</prog_type>
<hours>$13</hours>
<length>$14</length>
<max_group_size>$15</max_group_size>
<res_lead_time>$16</res_lead_time>
<fees>$17</fees>
<contact>$18</contact>
<languages>$19</languages>
<free_p>$20</free_p>
<show_p>$21</show_p>
<writeup_p>$22</writeup_p>
<featured_p>$23</featured_p>
<comments>$24</comments>
<creation_date>$25</creation_date>
<creation_user>$26</creation_user>
<edit_date>$27</edit_date>
<edit_user>$28</edit_user>
</event>
Get rid of everything but what is in between two tags
leaves behind <name>blah >
(it's not perfect but it will help you widdle down large xml files to just the nodes you want!)
((?!<name>.*</name>|Name>.*</name>|ame>.*|me>.*|e>.*|>.*|.*).)*
Safari doesn't like spacer gifs before consecutive floated unordered lists
The current version of Safari for PPC chips is 2.0.4 build 419.3 (and possibly previous versions) does not like having <img tags followed by consecutive <ul tags. The behavior is strange it actualy will display the first and last of the consectutive <ul tags correctly but any that are in between them get floated to the top left of the <div containing them.
Check it out:
<DIV xmlns:exsl="http://exslt.org/common" xmlns:isutil="com.infusedsolutions.template.xsl" id="related_content">
<IMG border="0" height="1" width="1" alt="Related Content" src="/staticfiles/NGS/NGKids/SiteAssets/img/spacer.gif">
<UL>
<LI class="cat_name">Activity</LI>
<LI>
<A href="/Activities/Recipes/Treat-your-pet">
<IMG border="0" height="50" width="75" alt="Illustration shows a cartoon boy rolling out dough while a cartoon cat watches." src="/staticfiles/NGS/Shared/StaticFiles/NGKids/Image/treatyourpet-NGK1298-mi.jpg">
</A>
<A href="/Activities/Recipes/Treat-your-pet">Treat Your Pet</A>
</LI>
<LI>
<A href="/Activities/PhotoFillins/Photomusicaldog?vgnextfmt=alternate">
<IMG border="0" height="50" width="75" alt="What's the dog thinking?" src="/staticfiles">
</A>
<A href="/Activities/PhotoFillins/Photomusicaldog?vgnextfmt=alternate">Photo Fill-Ins: Musical Dog</A>
</LI>
</UL>
<UL>
<LI class="cat_name"> Stories </LI>
<LI>
<A href="/Stories/AnimalsNature/Balloonpoppingdog">
<IMG border="0" height="50" width="75" alt="Anastasia is a balloon-popping dog!" src="/staticfiles/NGS/Shared/StaticFiles/NGKids/Image/balloon-dog-mi.jpg">
</A>
<A href="/Stories/AnimalsNature/Balloonpoppingdog">Balloon-Popping Dog: Anastasia, Jack Russell Terrier</A>
</LI>
</UL>
<UL>
<LI class="cat_name"> Related Web Links </LI>
<LI>
<A target="_blank" href="http://www.dogpsychologycenter.com">Dog Whisperer Cesar Millan Dog Psychology Center</A>
</LI>
<LI>
<A target="_blank" href="http://www9.nationalgeographic.com/channel/dogwhisperer/index.html">Dog Whisperer Web Site</A>
</LI>
<LI>
<A target="_blank" href="http://www9.nationalgeographic.com/channel/dogwhisperer/video_preview_1.html">Dog Whisperer Videos</A>
</LI>
</UL>
</DIV>
Trigger to mimic MySQL "last modified" datatype in Oracle
ALTER TABLE YOUR_TABLE ADD (LAST_MODIFIED DATE);
CREATE OR REPLACE
TRIGGER YOUR_TABLE_BEFORE_INS_UPD BEFORE INSERT OR UPDATE
ON YOUR_TABLE
FOR EACH ROW
DECLARE CURRENT_TIME DATE;
BEGIN
CURRENT_TIME := SYSDATE;
:new.last_modified := CURRENT_TIME;
END;
To start up everything Oracle
$ . oraenv
$ sqlplus “/ as sysdba”
SQL> startup
SQL> exit
$ lsnrctl
LSNRCTL> start
LSNRCTL> exit
$ cd $ORACLE_HOME/bin
./emctl start dbconsole
Shut down everything Oracle:
$ . oraenv
$ sqlplus “/ as sysdba”
SQL> shutdown immediate
SQL> exit
$ lsnrctl
LSNRCTL> stop
LSNRCTL> exit
$ cd $ORACLE_HOME/bin
./emctl stop dbconsole
Start VNC on Mac via SSH
sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -activate -configure -clientopts -setvnclegacy -vnclegacy yes -setvncpw -vncpw [NEW PASSWORD]-restart -agent
Exporting from oracle 9i on nt4 domain caveat number 2 (NTRights.exe)
In order to get an oracle export out of oracle 9i on an nt4 domain you need to create an oracle user that corresponds to a windows domain user who has administrative rights and also the right to "logon as a batch script" boy did this ever throw me for a loop. Fortunately after a few hours of google searches I came across the following documentation... looks like windows administration isn't all point and click! I imagine you need to do this on 2000/2003 still as this documentation is for those flavors. I can attest to the fact that it does work on nt4.(I pulled this from: http://www.ss64.com/nt/ntrights.html)
(Microsoft mentions it here http://support.microsoft.com/kb/315276)
NTRIGHTS.exe (Resource Kit, 2000/2003)
Edit user account Privileges.
Syntax
NTRIGHTS +r Right -u UserOrGroup [-m \\Computer] [-e Entry]
NTRIGHTS -r Right -u UserOrGroup [-m \\Computer] [-e Entry]
Key:
+/-r Right Grant or revoke one of the rights listed below.
-u UserOrGroup Who the rights are to be granted or revoked to.
-m \\Computer The computer (machine) on which to perform the operation.
The default is the local computer.
-e Entry Add a text string 'Entry' to the computer's event log.
Below are the Privileges that can be granted or revoked.
All are case-sensitive.
Privilege Meaning
SeAssignPrimaryTokenPrivilege Replace a process level token
SeAuditPrivilege Generate security audits
SeBackupPrivilege Back up files and directories
SeBatchLogonRight Log on as a batch job
...
Reversi search through the command history in bash shell
At the empty prompt, hit Ctrl + r then type something then hit Ctrl + r to step through previous commands containing that text.
piggy back port forward through intermediary box
This will take port 2222 on your local host and terminate it at 22 on ultimate_destination_host_ip via
your ssh tunnel to intermediary_host_ip
ssh -L 2222:ultimate_destination_host_ip:22 intermediary_host_ip -l username_common_to_both_hosts
php based ORMs
Doctrine (available as symfony plugin)
Propell (currently used by symfony)
adodb_active_record:
http://phplens.com/lens/adodb/docs-active-record.htm
javascript delicious tagging bookmarklet
Works best in mozilla based browsers but it has been known to work in IE and safari. Make sure to drop in your delicious username and password before you bookmark it.
javascript:void(delicious=open('https://username:password@api.del.icio.us/v1/posts/add?description='+encodeURIComponent(document.title)+'&tags='+prompt%20('Tags:','')+'&url='+encodeURIComponent(location.href),'delicious','toolbar=no,width=500,height=150'),%20setTimeout('delicious.close()',5000))
Enterprise search appliances/software
lucene with nutchgoogle enterprise
isys web
thunderstone
vivismo velocity
mondosearch
exalead:one
x1 enterprise
ibm omnifind yahoo edition
Flashing my Gateway Desktop
10. When the computer shuts down, it may appear to take a longer period of time to restart and it may beep 10 times during the restart process. This is considered normal and a part of the BIOS update process.
11. In the Intel(r) Express BIOS Update dialog box, it states that the Express BIOS update has completed successfully. Click OK.
12. On the first start-up after the BIOS update has completed, it is possible to receive a Checksum error message. This is caused by some BIOS parameters not being set at the default values. Reset BIOS options to default values (F9) and save and exit (F10) the BIOS Setup.
If the computer reboots and I can't get back to the bios screen again. try pulling the battery and shorting the battery contacts to ground. I imagine that just mean touch the batter contacts while touching the case.
find and replace recursively in all files
find ./httpdocs/template-modules/ -type f -exec sed -i 's/beta.refinery29.com/ww2.refinery29.com\//g' {} \;
here is one to replace directory paths:
find ./httpdocs/templates/ -type f -exec sed -i 's/\/var\/www\/vhosts\/refinery29.com\/subdomains\/beta\/httpdocs\//\/var\/www\/vhosts\/refinery29.com\/httpdocs\//g' {} \;
google search terms to find open security cameras
inurl:”ViewerFrame?Mode=
intitle:Axis 2400 video server
inurl:/view.shtml
intitle:”Live View / - AXIS” | inurl:view/view.shtml^
inurl:ViewerFrame?Mode=
inurl:ViewerFrame?Mode=Refresh
inurl:axis-cgi/jpg
inurl:axis-cgi/mjpg (motion-JPEG)
inurl:view/indexFrame.shtml
inurl:view/index.shtml
inurl:view/view.shtml
liveapplet
intitle:”live view” intitle:axis
intitle:liveapplet
allintitle:”Network Camera NetworkCamera”
intitle:axis intitle:”video server”
intitle:liveapplet inurl:LvAppl
intitle:”EvoCam” inurl:”webcam.html”
intitle:”Live NetSnap Cam-Server feed”
intitle:”Live View / - AXIS”
intitle:”Live View / - AXIS 206M”
intitle:”Live View / - AXIS 206W”
intitle:”Live View / - AXIS 210″
inurl:indexFrame.shtml Axis
inurl:”MultiCameraFrame?Mode=Motion”
intitle:start inurl:cgistart
intitle:”WJ-NT104 Main Page”
intext:”MOBOTIX M1″ intext:”Open Menu”
intext:”MOBOTIX M10″ intext:”Open Menu”
intext:”MOBOTIX D10″ intext:”Open Menu”
intitle:snc-z20 inurl:home/
intitle:snc-cs3 inurl:home/
intitle:snc-rz30 inurl:home/
intitle:”sony network camera snc-p1″
intitle:”sony network camera snc-m1″
site:.viewnetcam.com -www.viewnetcam.com
intitle:”Toshiba Network Camera” user login
intitle:”netcam live image”
intitle:”i-Catcher Console - Web Monitor”
Best SVN folder structures
for a project that has no sub projects:
/path/to/repos/projectname/trunk
/path/to/repos/projectname/tags
/path/to/repos/projectname/branches
for a project with multiple sub projects:
/path/to/repos/projectname/trunk/subprojectname1
/path/to/repos/projectname/trunk/subprojectname2
I am not sure that it is completely necessary to have the subprojectname folders under both tags and branches however.
nice folder structure for virtual hosts and subdomains under neath them
the vhosts are held in the vhosts folder of your primary repository of web sites (aka /var/www, /usr/local/apache2/htdocs, ~Home/Sites, etc.)
/path/to/www/vhosts/vhostname.com/httpdocs
/path/to/www/vhosts/vhostname.com/httpsdocs
/path/to/www/vhosts/vhostname.com/cgi-bin
the subdomains are located in a subdomains folder of the original vhost:
/path/to/www/vhosts/vhostname.com/subdomains/subdomainname/httpdocs
/path/to/www/vhosts/vhostname.com/subdomains/subdomainname/httpsdocs
/path/to/www/vhosts/vhostname.com/subdomains/subdomainname/cgi-bin
creating new svn repos and adding new project
Start by using svnadmin to create the repository somwhere that make sense. Most times if your just putting it on your workstation you should just put it in your home directory. If you want other users to have access to the repository put it somewhere globally accessible like /usr/local/subversion/repos
$ svnadmin create /usr/local/subversion/repos
then once the repository has been created you will want to add your current project to it.
go into the directory that holds the files you want to put into the repository.
$ cd /path/to/project/directory
then import the files into the repository making sure to use a similar path structure like below including the projectname and trunk and possibly a subproject name if your project has multiple subprojects. If not you can omit that part.
$ svn import ./ file:///usr/local/subversion/repos/projectname/trunk/subprojectname -m 'Initial import of projectname subprojectname'
now that that has been done you still need to get a working copy of the files on your local machine so delete all the files in the current directory.
$ svn checkout file:///usr/local/subversion/repos/projectname/trunk/subprojectname -m 'Initial import of projectname subprojectname'
now you will have a copy of all of the files you imported recreated within the folder you just deleted them from but this time their versions will be tracked and you can do things like:
svn status (to check what you have changed in your working copy)
svn update (to get all new files from the repository)
svn add filename (to add new files into the repository)
svn commit (to update the repository with all the changes from your working copy)
Install and setup mysql 5 with ports
MySql 5 Server
sudo port install mysql5 +server
sudo chown -R mysql:mysql /opt/local/var/db/mysql5
sudo -u mysql /opt/local/lib/mysql5/bin/mysql_install_db --user=mysql
ln -s /opt/local/var/run/mysql5/mysqld.sock /tmp/mysql.sock
Ruby’s gems installation
sudo env ARCHFLAGS="-arch i386" gem install mysql -- --with-mysql-include=/opt/local/include/mysql5 --with-mysql-lib=/opt/local/lib/mysql5 --with-mysql-config=/opt/local/lib/mysql5/bin/mysql_config
Start MySql server
sudo -u mysql /opt/local/lib/mysql5/bin/mysqld_safe &
Stop MySql server
/opt/local/bin/mysqladmin5 -u root shutdown
It’s a good idea to create alias for you, here’s mine:
alias mysql_start='sudo -u mysql /opt/local/bin/mysqld_safe5 &'
alias mysql_stop='/opt/local/bin/mysqladmin5 -u root shutdown'
And remeber: mysql.socks lives on /opt/local/var/run/mysql5 as mysqld.socks
/opt/local/var/run/mysql5/mysqld.sock