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

Sasha http://nothing-less.net

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

Linking to Stylesheets

http://eedocs.pmachine.com/templates/globals/stylesheet.html

<link rel="stylesheet" type="text/css" media="all" href="{stylesheet=static/style}" />

<link media="screen" type="text/css" href="{stylesheet=static/style}" />


RARing files on Mac OSX 10.4

1) Download the application called RAR at

http://files3.rarlab.com/rar/rarosx-3.5.1.tar.gz

2) decompress that file and there'll be a folder called "rar".

3) in that folder there's a file called "rar" (with no quotes or extension)

4) In Finder, go to Go > Go To Folder, and type in "/bin".

5) drag the FILE called "rar" in to that bin folder. It will ask you for your password, so go type it in and continue.

6) open the terminal and go to the directory that has the file or files you want to rar.

7A) once in the folder housing the files you want to rar, type this:

rar a FileName.rar


7B) Alternatively, you can specify which file or folder inside the folder you're in, you want to rar:

rar a FileName.rar originalfilename.whatever


8) to make a multi file rar archive, type the following instead of the above and replace where you see "####" with the file size you want each part to be, in kilobytes (kb).

rar a -v#### FileName.rar originalfilename.whatever


Search for terms in Domlogs

for files in /usr/local/apache/domlogs/*; do grep "wget" $files; done;


-OR-

cd /usr/local/apache/domlogs
grep wget *
grep lynx *
grep curl *


Replace wget with other file names/terms you might want to search for.

If that takes too long, try doing it one by one:

grep wget a*
grep wget b*
grep wget c*
grep wget d*
grep wget e*
grep wget f*
grep wget g*
grep wget h*
grep wget i*
grep wget j*
grep wget k*
grep wget l*
grep wget m*
grep wget n*
grep wget o*
grep wget p*
grep wget q*
grep wget r*
grep wget s*
grep wget t*
grep wget v*
grep wget w*
grep wget x*
grep wget y*
grep wget z*


Alternatively, if you get an error like "Argument list too long":

for i in `ls /usr/local/apache/domlogs|grep -v 'bytes_log'`; do echo "checking on $i" && grep wget /usr/local/apache/domlogs/$i && grep lynx /usr/local/apache/domlogs/$i && grep curl /usr/local/apache/domlogs/$i; done > /root/grep-domlogs-results.txt
Then simply take a look at this file /root/grep-domlogs-results.txt

Random Number

$randomnumber= rand(1,10);


Replace 1 and 10 with the range you want to pick a number between.

clear default text onClick - restore if nothing entered

From ScriptyGoddess:
http://www.scriptygoddess.com/archives/2005/11/15/clear-default-text-onclick-restore-if-nothing-entered/

In your document's head:
<script type="text/javascript">
function clickclear(thisfield, defaulttext) {
if (thisfield.value == defaulttext) {
thisfield.value = "";
}
}
function clickrecall(thisfield, defaulttext) {
if (thisfield.value == "") {
thisfield.value = defaulttext;
}
}
script>


The actual form field:
<input type="text" name="myfield" onclick="clickclear(this, 'default text')" onblur="clickrecall(this,'default text')" />

Snippets Plugin

Coding to use for the Expression Engine Snippets Plugin:

In the actual pages:
{exp:snippets template="static/index"}
{page_title}Site: {title}{/page_title}
{page_section}journal{/page_section}
{/exp:snippets}


In the header include (static/index in this case):
%page_title%
%page_section%

$fof_title="%nl_title%";
$fof_section="%nl_section%";
?>


Define them as variables in PHP for easy if/else statements. :)

Looking up recent dictionary attacks

grep "dictionary attack" /var/log/exim_mainlog

Looking into DOS and DDOS Attacks

http://etechsupport.net/forum/showthread.php?t=434

top -d2
netstat -nap | grep SYN | wc -l
netstat -nap | less


If there are many httpd processes showing up after step 1, you might be under attack. If you get high numbers for the second one, you are almost definitely under attack. Use the third one to see the IP addresses, and then ban them from the server:

iptables -A INPUT -s ip.address -j DROP


Also try the following for fixing stuff:
cd /dev/shm
ls


And delete anything that's not supposed to be there.

locate bindz
locate botnet.txt
locate dc
locate ex0.pl
locate kaiten
locate r0nin
locate udp.pl
locate ...
lsof | grep .,
locate mybot

Ban IPs from a server

iptables -A INPUT -s ip.address -j DROP

How to tail logs

tail -200 /var/log/exim_mainlog
tail -200 /usr/local/apache/logs/error_log


To watch the log get updated in real time:
tail -f /var/log/messages 

Search & Replace

update tablename set field = replace(field,'search_for_this','replace_with_this');

Sims 2 File Limit Fix

sudo sysctl -w kern.maxfiles=22000
sudo sysctl -w kern.maxfilesperproc=20000


Type this into Terminal in Mac OSX to fix the file size limit for The Sims 2, allowing you to have more than 5000 downloads.

Display Current Year

Useful for example for automatic copyright notices:

&copy; Copyright 2004 - <?php echo date("Y") ?>

Date In The Future

<?php
 $nextmonth = mktime(0, 0, 0, date("m")+1, 1, date("Y"));
 echo date("F", $nextmonth);
 ?>

Total Number of Entries for one Weblog

{exp:stats weblog="weblog1"}{total_entries}{/exp:stats}

Entry Date

{entry_date format="%F %d, %Y"}
{edit_date format="%F %d, %Y"}


More formatting options:
http://eedocs.pmachine.com/templates/weblog/variables.html#date_variables
http://eedocs.pmachine.com/templates/date_variable_formatting.html

Display In 2-Column Table

The below can be applied to MT, EE, etc, and will display the content in a 2 column table. The EE tags below are just an example, it will work equally well if you replace it with MT, Wordpress, etc, tags.

 $set_table="0"; ?>

<table cellpadding="5" border="0">
{exp:gallery:categories gallery="{gallery_name}"}
 
$fs_table = $set_table +1;
if ($set_table == "1") {echo"";} ?>


Insert other tags here.


 if ($set_table == "2") {echo"";  $set_table="0";} ?>
{/exp:gallery:categories}
</table>

Get Today's Date & Time

$today = date("F j, Y");


http://www.php.net/manual/en/function.date.php

Use PHP Inside EE Entries

You'll need the following plugins:
Allow EE Code: http://www.pmachine.com/plugins/allow-eecode/
Allow PHP: http://loweblog.com/archive/2005/06/03/ee-allow-php-plugin/

Set text formatting for the field you want to use this on to "None" (Admin > Weblog Administration > Custom Weblog Fields).

Change your template by adding the Allow EE tags around the field:

{exp:allow_eecode}{body}{/exp:allow_eecode}


Now you can use PHP inside your entries like this:

<p>Bla bla regular entry textp>

{exp:allowphp}
echo "This will be processed as PHP.";
{/exp:allowphp}

Strip A String using explode

http://www.php.net/manual/en/function.explode.php

In this example, I need to strip the page's current URL to take off anything that follows a ? in that URL.

 
$fs_refer= $_SERVER ['REQUEST_URI'];

$fs_refer = explode("?", $fs_refer);
echo "$fs_refer[0] is now a URL without ?.
"; echo "$fs_refer[1] is the bit that used to follow the ?."; ?>
« Newer Snippets
Older Snippets »
52 total  XML / RSS feed