Skip to content

Instantly share code, notes, and snippets.

View camt's full-sized avatar

Cameron camt

  • Tru-Test
  • Auckland, New Zealand
View GitHub Profile
@camt
camt / irrevocable.html
Created January 31, 2012 00:14
A simple little trick for confirming with a user before they undertake an action on your web page. When the user clicks the link, they will hit a pop up box, displaying the confirmation message and two buttons. If they click yes the link is followed and t
<a href="irrevocable-action.php?doitnow=yes" onclick="return confirm('Are you really, really, really sure you want to do this?')">Do It!!</a>
@camt
camt / mailto.html
Created January 24, 2012 19:14
JS creation of mailto link - avoids scrapers and bots
<script>
document.write("<a href='mailto:" + 'moc.elpmaxe@em'.split("").reverse().join("") + "'>email</a>");
</script>
@camt
camt / ByteToString.cs
Created January 22, 2012 08:23
algorithm for aesthetically converting bytes to strings
public static string b2s(byte b) {
string result = Convert.ToString(b, 2);
while(result.Length < 8 ) result = "0" + result;
return result;
}
@camt
camt / internalize.php
Created January 22, 2012 08:22
External redirects from your site trigger web-bots in different ways. If you want to hide them from the web-bots, and have all links on you site point internally, this script is a simple way to do so. You can either run it through a database, which makes
<?php
if(isset($_REQUEST['rd'])) {
$new = $_REQUEST['rd'];
// DB access
include("db.php");
$sql = "SELECT rdURL FROM rd WHERE rdName='".$new." LIMIT 1';";
$result = mysql_query($sql);
mysql_close($conn);
if($result) {
$row = mysql_fetch_array($result);
@camt
camt / castToInt.js
Created January 22, 2012 08:20
casting to integers in JavaScript
val = (numberA / numberB) | 0;
@camt
camt / whitespace.js
Created January 22, 2012 08:19
trimming white space in JS easily
function trim(str, chars) {
return ltrim(rtrim(str, chars), chars);
}
function ltrim(str, chars) {
chars = chars || "\\s";
return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
function rtrim(str, chars) {
chars = chars || "\\s";
return str.replace(new RegExp("[" + chars + "]+$", "g"), "");