Tag Archive for programming

Howto list all the file extension types in an SVN log dump

svn log -v > myrepo.log

perl -ne 'print qq{$1
} if m{^s+.*(.[^.s]w+)$}' myrepo.log | sort | uniq -c | sort -r

source

It’s that Simple……

In order to understand HASH and DOUBLE HASH concept in SAS you need to know about two different ranges of variables:

1) Numbered list:

When a set of variables have the same prefix, and the rest of the name is a consecutive set of numbers, we can use a single dash (-) to refer to an entire range. Some exs.. are�.

VAR1 VAR2 VAR3 VAR4 VAR5

Shortcut list you can use to access all 5 variables is VAR1-VAR5

COL1 COL2 COL3 COL4 COL5 COL6 COL7

Shortcut list you can use to access all 7 variables is COL1-COL7

source

SAS programming errors we make….. can be deadly sometimes

The errors I will list here will be very few in number. They are errors that you will likely make at some time if you do not remain alert. These errors could have serious consequences so that is why I have described them as "deadly errors".

source

Load images after the web page is loaded

<html>
<head>
<script type="text/javascript">
<!--
function getImage(pExistingImageID, pImageURL){
var img = document.createElement('img');
img.onload = function (evt) {
document.getElementById(pExistingImageID).src=this.src;
document.getElementById(pExistingImageID).width=this.width;
document.getElementById(pExistingImageID).height=this.height;
}
img.src = pImageURL;
return false;
}
//-->
</script>
<title>Remote Image 5</title>
</head>

<body>
<p><a href="#" onclick="return getImage('placeHolder','/images/rdivilbiss.jpg');">Get Remote Image</a></p>
<p><img id="placeHolder" border="0" src="/images/placeHolder.jpg"></p>
</body>
</html>

source

how to make sure that the table is using InnoDB

dataSource {
pooled = true
driverClassName = "com.mysql.jdbc.Driver"
username = "wysmedia"
password = "password"
dialect = org.hibernate.dialect.MySQLInnoDBDialect
}

source

Sorting MySQL data in a GRID

<?php
//basic mysql connection, you'd want to use a DB class or something
$connect = @mysql_connect("localhost","username","password") or die("Could not connect to server.");
$db = @mysql_select_db("database") or die(mysql_error());
$query = "SELECT * FROM table";
$result = @mysql_query($query) or die("Could not execute query");
$check = mysql_num_rows($result);
if ($check == 0) {
echo "Table is empty.";
} else {
?>
<table>
<?php
$i = 1;
while ($row = mysql_fetch_array($result)) {
if ($i == 1) {
?>
<tr>
<?php
}
?>
<td><?php echo $row['column']; ?></td>
<?php
if ($i == 7) { /* here we have 7 columns per row, if you want 10 columns just change this value to 10 instead of 7 */
$i = 0;
?>
</tr>
<?php
}
$i++;
}
?>
</tr>
</table>
<?php
}
?>

source

Joining two tables

<?php
//DB connection
$query = "SELECT table1.*, table2.* FROM table1 LEFT JOIN table2 ON table1.column = table2.column";
?>

source

Delete Repeated Numbers

#include<stdio.h>

int deleteRepeatedNumbers(int list[], int size)
{
if(size < 1)
return 0;
int newLength = 1;
for(int i = 1; i < size; i++)
if(list[i-1] != list[i])
list[newLength++] = list[i];
return newLength;
}

int main()
{
int sortedArray[] = {1, 1, 1, 1, 2, 3, 4, 4, 5, 5, 6, 6 ,6 ,6, 11};
printf("%d", deleteRepeatedNumbers(sortedArray, 15));
return 0;
}

source

Programming Notes

<?php

// TODO:		Enter some task that needs to be done.
// FIXME:		Enter some bug that needs to be fixed.
// FIXME(BugNumber):	Reference a bug number for FIXME.
// CHANGED:		Once finished with TODO, replacement with CHANGED is recommended.
// NOTE:		Enter a simple note.
// OPTIMIZE:		A TODO specifically for optimization notes.
// IMPROVE:		A TODO specifically for improvement notes.

// Examples:

// TODO: Add in a update script.
// FIXME: Bug in update script (cannot download new file).
// FIXME(81239): Bug in update script (cannot download new file).
// CHANGED: Added update script.
// NOTE: The update script is still a bit buggy.
// OPTIMIZE: Update download speed.
// IMPROVE: Make the UI a bit better for update script.

?>

source

User input validation and security / general security in PHP and programming in general

Regarding user input (e.g. web forms, but pretty much any possible user input):

Check the length of the input to verify that it is less than your max (always set some sort of maximum) and greater than zero.

In PHP with MySQL, use the function "mysql_real_escape_string" when interacting with the database (db).

Always clean your output (to prevent XSS, or Cross-Site Scripting):
In PHP, you can use the functions "htmlentities" for textual output and "urlencode" for URI's.

Never accept user input for filenames! Write your own filename, perhaps based on pre-cleaned user input, but preferably just an alphanumeric name of your choice (which can be stored in the db for reference). And before you write the file, use the PHP functions "basename" and "realpath" (i.e. basename(realpath($filename)) ) in order to establish exactly where the file would end up if you do write it as is. Also very important: before creating the file, use the PHP function "umask," i.e. umask(077), so that files have their permissions locked down before they are created. This prevents someone from accessing the file before you have time to manually change the permissions.

Whenever a user logs in, use the PHP function "session_regenerate_id" to prevent fraudulent access to their account or a session-fixation attack.

More to come... Please post your own.

source