Skip to content

Instantly share code, notes, and snippets.

View egulhan's full-sized avatar
Here we go again...

Erman Gülhan egulhan

Here we go again...
View GitHub Profile
@egulhan
egulhan / function.trim_all.php
Last active August 29, 2015 14:20
Trim all white-space characters using PHP
<?php
//
// source: http://pageconfig.com/post/remove-undesired-characters-with-trim_all-php
//
function trim_all( $str , $what = NULL , $with = ' ' )
{
if( $what === NULL )
{
// Character Decimal Use
@egulhan
egulhan / reverse-function-via-jquery.js
Created April 30, 2015 09:07
How to use javascript reverse function after seleting elements by using jquery
// @source: http://stackoverflow.com/a/5386150
jQuery.fn.reverse = [].reverse;
$('jquery-selectors-go-here').reverse().each(function () {
//business as usual goes here
});
@egulhan
egulhan / sort-elements.js
Created April 29, 2015 08:05
How-to sort elements in HTML using Javascript
// @source: http://stackoverflow.com/questions/20693593/sort-select-options-by-value-attribute-using-jquery
var selectList = $('#featuredSelectField option');
selectList.sort(function(a,b){
a = a.value;
b = b.value;
return a-b;
@egulhan
egulhan / sorted-items-with-in-operator.sql
Created April 15, 2015 12:10
Get sorted items while using IN operator
select *
from items
where item_id in (1,3,5,7,2,4,6,8)
order by field(item_id, 1,3,5,7,2,4,6,8)
@egulhan
egulhan / function.is-json-encoded.php
Created April 14, 2015 09:16
Determine if string is json encoded or not using PHP
<?php
function isJsonEncoded($str)
{
json_decode($str);
return json_last_error() == JSON_ERROR_NONE ? true : false;
}
?>
@egulhan
egulhan / function.reindex-array-recursive.php
Created April 10, 2015 08:25
Function which reindexes arrays for the given object in recursive way
<?php
/**
* Reindexes arrays for the given object in recursive way
* @param $obj
* @return array
*/
function reindex_array_recursive($obj)
{
if(is_array($obj) && !is_array_assoc($obj))
@egulhan
egulhan / function.is-array-assoc.php
Created April 10, 2015 08:24
Function which checks if an array is associative or not
<?php
/**
* Checks if the array is associative or not
* @param $array
* @return bool
*/
function is_array_assoc($array)
{
return (bool)count(array_filter(array_keys($array),'is_string'));
@egulhan
egulhan / send-submit-button-value.js
Created March 26, 2015 06:30
Post form with submit button value using Ajax
$("#mySubmit").click(function() {
var formData = $(this).closest('form').serializeArray();
formData.push({ name: this.name, value: this.value });
//now use formData, it includes the submit button
});
@egulhan
egulhan / function.sort_ranged_numbers.php
Last active August 29, 2015 14:17
Sort ranged numbers using PHP
<?php
// Helper function
/**
* Sorts ranged numbers
* @param $a
* @param $b
* @return int
*/
@egulhan
egulhan / array-unique.js
Created February 17, 2015 18:49
Unique function for Javascript (which returns result unlike Jquery unique function)
function unique(array){
return $.grep(array,function(el,index){
return index == $.inArray(el,array);
});
}