Skip to content

Instantly share code, notes, and snippets.

View treffynnon's full-sized avatar
🧟

Simon Holywell treffynnon

🧟
View GitHub Profile
@treffynnon
treffynnon / cron1.bat
Created February 4, 2010 15:19
Windows: Scheduled tasks example
schtasks /Create /RU username /RP password /SC MINUTE /MO 5 /TN taskname /TR "C:\Program Files\wget\wget.exe http://www.webaddress.com/script.php --spider"
@treffynnon
treffynnon / cron2.bat
Created February 4, 2010 15:19
Windows: Scheduled tasks example
schtasks /Create /RU username /RP password /SC MONTHLY /MO 2 /TN taskname /TR "C:\Program Files\wget\wget.exe http://www.webaddress.com/script.php --spider"
@treffynnon
treffynnon / exec-tasks-php.php
Created February 4, 2010 15:19
PHP: Scheduled tasks executed from PHP
<?php
exec('schtasks /Delete /TN taskname /F');
exec('schtasks /Create /RU username /RP password /SC MINUTE /MO 2 /TN taskname /TR “C:\Program Files\wget\wget.exe --header=TASK_KEY:my-secret-key –U my-agent http://www.webaddress.com/script.php -r');
?>
@treffynnon
treffynnon / secure-php-cron.php
Created February 4, 2010 15:19
PHP: Detecting a valid request via a pass key set in a header
<?php
if('my-agent' !== $_SERVER['HTTP_USER_AGENT'] or
$_SERVER['SERVER_ADDR'] !== $_SERVER['REMOTE_ADDR'] or
!isset($_SERVER['HTTP_TASK_KEY']) or
empty($_SERVER['HTTP_TASK_KEY']) or
'my-secret-key' !== $_SERVER['HTTP_TASK_KEY']) {
print 'You do not have permission to execute this script!';
exit();
}
print 'Executing operation.';
@treffynnon
treffynnon / localhost-virtualhost.xml
Created February 4, 2010 15:19
Apache2: Virtual host example
<VirtualHost *:80>
ServerAdmin name@domain.com
DocumentRoot c:\xampp\htdocs
ServerName localhost
</VirtualHost>
@treffynnon
treffynnon / virtualhost.xml
Created February 4, 2010 15:19
Apache2: Virtual host example
<VirtualHost *:80>
ServerAdmin name@domain.com
DocumentRoot c:\xampp\simonholywell.com\pub
ServerName simonholywell.localhost
<Directory c:\xampp\simonholywell.com\pub>
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
@treffynnon
treffynnon / primary-keys.sql
Created February 4, 2010 15:19
T-SQL: Reset the primary keys
BEGIN TRANSACTION
GO
CREATE TABLE dbo.Tmp_admin_accounts
(
account_id int NOT NULL IDENTITY (1, 1),
username varchar(20) NOT NULL,
passhash char(40) NOT NULL
) ON [PRIMARY]
GO
SET IDENTITY_INSERT dbo.Tmp_admin_accounts ON
@treffynnon
treffynnon / table-list.php
Created February 4, 2010 15:19
Convert MySQL tables to T-SQL
<?php
$conn = mysql_connect('host','user','pass');
mysql_select_db('database',$conn);
$SQL = "SHOW TABLES;";
$result = mysql_query($SQL, $conn);
while($row = mysql_fetch_array($result))
print "SELECT * INTO SQLServerDBName.dbo.{$row[0]}<br />
FROM openquery(MySQL, 'SELECT * FROM `{$row[0]}`');<br />
";
@treffynnon
treffynnon / mysql-link.sql
Created February 4, 2010 15:19
Setup the MySQL ODBC connection
@treffynnon
treffynnon / crypt.php
Created February 4, 2010 15:19
SHA1 crypt functions for ADODB
<?php
class SHA1Crypt{
function keyED($txt,$encrypt_key)
{
$encrypt_key = sha1($encrypt_key);
$ctr=0;
$tmp = "";
for ($i=0;$i<strlen($txt);$i++){
if ($ctr==strlen($encrypt_key)) $ctr=0;
$tmp.= substr($txt,$i,1) ^ substr($encrypt_key,$ctr,1);