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 / get-query-param-by-name.js
Created May 12, 2017 13:56
Gets param value of query string by name using Javascript
/**
* Gets param value of query string by name
* @param name
* @param url
* @returns {*}
*/
function getQueryParamByName(name, url)
{
if (!url) url = window.location.href;
name = name.replace(/[\[\]]/g, "\\$&");
@egulhan
egulhan / validate-date-format.php
Last active November 3, 2016 19:51
Validate date(or date time) format using PHP
<?php
$date = '2012-01-01 12:12:12';
$r = validateDateFormat($date);
var_dump($r);
/**
* Validates date(or date time) format
* @param $date
@egulhan
egulhan / singleton-class.js
Created April 25, 2016 14:08
How to write a class with Singleton Design Pattern in Javascript
// source: http://robdodson.me/javascript-design-patterns-singleton/
var mySingleton = (function () {
// Instance stores a reference to the Singleton
var instance;
function init() {
// Singleton
@egulhan
egulhan / add-user-to-sudo-group.sh
Created April 18, 2016 15:03
How to add an user to sudo group
sudo adduser <username> sudo
@egulhan
egulhan / file-perms-info-hex-to-text.php
Created March 16, 2016 13:37
Convert file perms. hex to text info
<?php
$perms = fileperms($target_path);
if (($perms & 0xC000) == 0xC000)
{
// Socket
$info = 's';
@egulhan
egulhan / create-and-send-form-on-the-fly.js
Created September 18, 2015 09:55
How-to create form on the fly and send via POST method by using JQuery
$(function(){
// create form on the fly
var $new_form = $('<form>', {
'action': '<?php echo BASE_URL; ?>/operation/reset_member_password',
'method': 'POST',
'target': '_top'
}).append(jQuery('<input>', {
'name': 'member_id',
'value': member_id,
'type': 'hidden'
@egulhan
egulhan / select-text.js
Created September 18, 2015 09:51
How-to select text of element using javascript
/**
* Select text of element by element id
* @param element
*/
function selectText(elementId)
{
var
doc = document,
text = doc.getElementById(elementId),
range,
@egulhan
egulhan / function.isWeekend.php
Created August 18, 2015 09:10
Determine to check if it is weekend or not
<?php
function isWeekend($date) {
return (date('N', strtotime($date)) >= 6);
}
?>
@egulhan
egulhan / mysql-insert-from-select.sql
Created June 12, 2015 14:40
Example of insert query from select query (including substr function using)
INSERT INTO tbl_media_files_tmf(entity_type_id,entity_id,file_name,media_type,sort_order,status,created_date,update_date)
SELECT CONCAT("37"),entity_id,CONCAT(substring_index(file_name,'.',1),'_mobile.jpg'),media_type,sort_order,status,created_date,update_date FROM tbl_media_files_tmf where entity_type_id=29;
@egulhan
egulhan / jquery.plugin.only-numeric-input.js
Created May 15, 2015 13:06
Jquery plugin for only numeric input
/* Only number input fields */
jQuery.fn.ForceNumericOnly =
function()
{
return this.each(function()
{
$(this).keydown(function(e)
{
var key = e.charCode || e.keyCode || 0;
// allow backspace, tab, delete, enter, arrows, numbers and keypad numbers ONLY