Skip to content

Instantly share code, notes, and snippets.

View varemenos's full-sized avatar

Adonis Kakoulidis varemenos

View GitHub Profile
@varemenos
varemenos / current_url.js
Created March 19, 2012 05:11
jQuery - Check For Current Url
if(window.location.pathname === 'index.php'){
// do something
}
@varemenos
varemenos / compact.php
Created March 17, 2012 16:30
PHP - Compact Variables into an Array
<?php
$name = 'James';
$surname = 'Pond';
$job = 'Failure';
$temp = array('name', 'surname');
$result1 = compact($temp, 'job');
$result2 = compact($temp[0], $temp[1], 'job');
@varemenos
varemenos / array_unique.php
Created March 17, 2012 16:20
PHP - Array Unique
<?php
$a = array(
'1' => 'one',
'one' => 'one',
'2' => 'two'
);
var_dump($a);
var_dump(array_unique($a));
@varemenos
varemenos / array_values.php
Created March 17, 2012 16:13
PHP - Array Keys to Values
<?php
$a = array(
'x' => 'X',
'xx' => 'XX',
'xxx' => 'XXX'
);
var_dump(array_keys($a));
// RESULTS
@varemenos
varemenos / stack.php
Created March 17, 2012 16:05
PHP - Array as Stack
<?php
$a = array();
for ($i=0; $i < 3; $i++) {
array_push($a, $i);
var_dump($a);
}
for ($i=0; $i < 3; $i++) {
array_pop($a);
@varemenos
varemenos / array_map.php
Created March 17, 2012 15:57
PHP - Array Map Function
<?php
$a = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
$new_a = array_map('square', $a);
var_dump($a, $new_a);
function square($temp){
return ($temp * $temp);
}
@varemenos
varemenos / list_function.php
Created March 17, 2012 15:39
PHP - List Function
<?php
$temp = array('one', 'two', 'three', 'four');
list($one, $two, $three, $four) = $temp;
var_dump($temp);
var_dump($one, $two, $three, $four);
// RESULTS
/*
@varemenos
varemenos / sample_object.php
Created March 16, 2012 06:42
PHP - Sample Object
<?php
// CONTINUE:
// CLASSES & OBJECTS - http://php.net/manual/en/language.oop5.php
// BASICS (TUTORIAL) - http://www.php.net/manual/en/language.oop5.basic.php
// CONSTRUCTORS - http://www.php.net/manual/en/language.oop5.decon.php
// new class
class Foo{
// constructor
@varemenos
varemenos / title2excerpt.php
Created March 16, 2012 04:20
PHP - Title to Excerpt Convertion
<?php
// sample title
$title = "the, *t.ru/e ;h'or']ror} (2)3!@ # $ % ^ & (* )^ ) _+-0(*)*%(&!^";
// find and replace any whitespace characters with underscores
$excerpt = preg_replace('/\s/', '_', $title);
// find an replace any none alphanumeric or underscore characters with any empty string ''
$excerpt = preg_replace('/[^a-zA-Z0-9_]/', '', $excerpt);
// while there is a '__' string inside the string, keep replacing the '__' with '_'
while (strpos($excerpt, '__') !== false){
@varemenos
varemenos / exec_time.php
Created March 11, 2012 03:30
PHP - Exec time calculation
<?
// start{
// exec time
$start_time = (float) array_sum(explode(' ', microtime()));
// }
// config file {
// developer mode on/off
define('DEV_MODE', true);