Skip to content

Instantly share code, notes, and snippets.

View tracend's full-sized avatar
🎯
Focusing

✌ Makis Tracend tracend

🎯
Focusing
View GitHub Profile
@tracend
tracend / gist:912308
Created April 10, 2011 12:40
DirectInput keyboard scan codes
/****************************************************************************
*
* DirectInput keyboard scan codes
*
****************************************************************************/
#define DIK_ESCAPE 0x01
#define DIK_1 0x02
#define DIK_2 0x03
#define DIK_3 0x04
#define DIK_4 0x05
@tracend
tracend / gist:912345
Created April 10, 2011 13:38
AS3: Geometry notes
//calculate degrees
//the angle the circle is in relation to the center point
degrees = Math.round(radians*180/Math.PI);
//Calculcate Radians
//Radians specify an angle by measuring the length around the path of the circle.
radians = Math.atan2((mc.y), (mc.x));
// Category: This is a free-form string used to categorise your events.
// Action: Another free-form string which represents the type of event, ex. “killed” and “game_start”.
// Label: This is an optional string parameter to the action.
// Value: This is an optional fractional number parameter to the action.
Application.ExternalCall("pageTracker._trackEvent", new object[] { category, action, label, value} );
@tracend
tracend / fb-user-liked-page.js
Created April 20, 2011 02:29
Facebook JS-SDK: Check if the user has liked a page
FB.api({ method: 'pages.isFan', page_id: '{PAGE_ID}' }, function(response) {
if (response) {
alert("user has liked the page");
} else {
alert("user has not liked the page");
}
});
@tracend
tracend / stop_sql_injection.php
Created April 20, 2011 22:22
PHP: Prevent SQL Injection
$sql = safeInput("UPDATE table_name SET field_one='%s', field_two='%s' WHERE id='%s'", $input);
function safeInput($string, $args){
foreach( $input as $key => $value ){
// 'clean' the input
$args[$key] = mysql_real_escape_string($value);
}
// add the statement as the first element of the array
$args[0] = $string;
var myTimer:Timer = new Timer(5000,1);
myTimer.addEventListener(TimerEvent.TIMER, timerFunction);
function timerFunction(event:TimerEvent):void
{
trace(“Timer function executed”);
}
myTimer.start();
@tracend
tracend / common_db.php
Created May 10, 2011 05:40
PHP: Simple MySQL Database Connection
<?php
// Database credentials
define("DB_USER", "**************************");
define("DB_PASS", "**************************");
$staging = (strpos($_SERVER['REQUEST_URI'], "/dev/") !== false);
$localhost = (strpos($_SERVER['SERVER_NAME'], "localhost") !== false);
define("IS_STAGING", $staging);
@tracend
tracend / validation.php
Created May 10, 2011 05:42
PHP: Simple form validation of common elements
<?php
$data = '';
$errmsg = ''; // error message
$valid = false; // validation flag
$flag = array();
$flag_class = ' class="formErrorInput"';
// main logic
@tracend
tracend / send_email.php
Created May 10, 2011 05:43
PHP: Barebones email submission
<?php
function sendEmail($message){
global $data;
$email = $data['email'];
$name = $data['fname'];
// getting the email copy
@tracend
tracend / passwords.php
Created May 10, 2011 05:52
PHP: Encryption / decryption of passwords
<?php
function encryptPassword($value){
if(!$value){return false;}
$text = $value;
$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
$crypttext = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, SECRET_KEY, $text, MCRYPT_MODE_ECB, $iv);
return trim(base64_encode($crypttext)); //encode for cookie
}