Skip to content

Instantly share code, notes, and snippets.

View apphp's full-sized avatar

Samuel Akopyan apphp

View GitHub Profile
@apphp
apphp / gist:8631342
Created January 26, 2014 11:27
Creating and Parsing JSON Data in PHP
<?php
// This code demonstrates how to create and parse the JSON data format of using array of PHP.
// It's a very simple code, that allows you to perform this task.
// source: http://www.apphp.com/index.php?snippet=php-create-and-parse-json-data
$json_data = array(
'id'=>1,'name'=>'jackson','country'=>'usa','office'=>array('google','oracle')
);
echo json_encode
($json_data);
@apphp
apphp / gist:8631352
Created January 26, 2014 11:28
Validate IP address in PHP
<?php
$ip_address = '127.0.0.1';
if(preg_match('/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/', $ip_address)){
echo 'IP address is valid!';
}else{
echo 'IP address is NOT valid!';
}
?>
@apphp
apphp / gist:8645882
Created January 27, 2014 09:54
How To Define Class Private Members in JavaScript
// Class member encapsulation in JavaScript is very important thing and may be implemented with easy.
// To define private property or method just use var before the definition or this.,
// if you need to give a public access to property or method.
// source: http://www.apphp.com/index.php?snippet=javascript-define-class-private-memebrs
<script language="javascript">
FormValidator = function(){
// private data member (property)
var _digits = "0123456789";
@apphp
apphp / gist:8645895
Created January 27, 2014 09:56
Converting a text input to a select with JavaScript
// Sometimes you need the page dimanically changes a texbox with a dropdown box.
// On the example below we show you how to perform this work.
// source: http://www.apphp.com/index.php?snippet=javascript-converting-text-input-to-select
<div id="buy-buttons">
<label>Quantity:</label>
<input name="txtQuantity" id="txtQuantity" type="text" value="1" />
<input type="submit" name="btnAddToCart" value="Add To Cart" id="btnAddToCart" />
</div>
@apphp
apphp / gist:8666167
Created January 28, 2014 11:35
Animated Tooltip with CSS
/*
This example shows you how to create custom tooltips, using just a pure CSS. In this examples we use "transform" feature of the CSS3 and some other tricks. Also you may find additional tooltip class provided, to show you the way you may customize this code.
Source: http://www.apphp.com/index.php?snippet=css-pure-ccs3-animated-tooltip
*/
<style type="text/css">
.tooltip-container {
/* Forces tooltip to be relative to the element, not the page */
position:relative;
cursor:help;
}
@apphp
apphp / gist:8666173
Created January 28, 2014 11:36
Prevent Long URL's From Breaking Out with CSS
/*
This solution will help you to prevent many issues with your site, when you need to prevent long URL's from breaking out of container.
Source: http://www.apphp.com/index.php?snippet=css-breaking-out-long-urls
*/
<style type="text/css">
.break {
-ms-word-break: break-all;
word-break: break-all;
word-break: break-word;
-webkit-hyphens: auto;
@apphp
apphp / gist:8685066
Created January 29, 2014 10:13
Button With Line Breaks in HTML
To get buttom with line breaks you can use carriage return characters to break the line: &#x00A; or just <br> with a <button> tag:
Source: http://www.apphp.com/index.php?snippet=html-button-with-line-breaks
<!-- First way -->
<input type="button" value="This is&#x00A;a Really&#x00A;Tall&#x00A; Button">
<!-- Second way -->
<button>This is<br/>a Really<br/>Tall<br/>Button</button>
@apphp
apphp / gist:8685076
Created January 29, 2014 10:14
Comments in HTML
The <!-- --> syntax is the HTML comment. This is the way to add your own notes into the code which will not display when the HTML is rendered by the browser. It is also a good practice for web-developers to use the comment tags to "hide" scripts from browsers without support for it (so they don't show them as a plain text).
Source: http://www.apphp.com/index.php?snippet=html-comments-tag
<!-- This is a comment. Comments are not displayed in the browser. -->
<div id="header">
<p>Some text</p>
</div> <!-- END div-header -->
@apphp
apphp / gist:8765319
Created February 2, 2014 09:32
Find and Replace with MySQL
/* MySQL has a handy and simple string function REPLACE() that allows table data with the matching string to be replaced by new string. This is useful if there is need to search and replace a text string which affects many records or rows, such as change of address, company name, URL or spelling mistake.
Source: http://www.apphp.com/index.php?snippet=mysql-find-and-replace
*/
-- 1st example
UPDATE files SET filepath = REPLACE(filepath,'path/to/search','path/to/replace');
-- 2nd example
UPDATE customers SET address = REPLACE(address,'_CODE_',postcode);
@apphp
apphp / gist:8765344
Created February 2, 2014 09:34
Create a Database and Assign a User
/*
This is a very simple snippet about how to create a database 1st,
a user and then assign some privileges to the user to allow him/her to
perform some specific actions like insert, create, update, select etc.
Source: http://www.apphp.com/index.php?snippet=mysql-create-database-and-assign-user
*/
-- Create database, user and grant all privileges
CREATE DATABASE database_name;
CREATE USER 'user_name'@'localhost' IDENTIFIED BY 'password';