Skip to content

Instantly share code, notes, and snippets.

View 5iDS's full-sized avatar
💭
@ease with the Source

Max 5iDS

💭
@ease with the Source
View GitHub Profile
@5iDS
5iDS / JSszz...
Created May 1, 2013 20:04
JS Sleep function
function jszz(s){
s=s*1000;
var a=true;
var n=new Date();
var w;
var sMS=n.getTime();
while(a){
w=new Date();
wMS=w.getTime();
if(wMS-sMS>s) a=false;
@5iDS
5iDS / gist:5639245
Created May 23, 2013 20:37
Counting String Characters
function smartShorten($charset='utf-8', $str, $maxlength = 140, $max_cut_len = 10) {
$len = iconv_strlen($str, $charset);
if ($len > $maxlength) {
$str = iconv_substr($str, 0, $maxlength, $charset);
$prev_space_pos = iconv_strrpos($str, ' ', $charset);
if ( ($maxlength-$prev_space_pos) < $max_cut_len) {
$str = iconv_substr($str, 0, $prev_space_pos, $charset);
}
@5iDS
5iDS / wpdb-transactions
Created June 30, 2013 22:37
MySQL database transaction, using the WordPress database object $wpdb. When you render a page in WordPress (front end or admin area), the $wpdb database object has already been initialised and opened up a connection to the database. Therefore we can recycle this database connection for our own needs. The $wpdb object saves the database handle as…
<?php
global $wpdb;
// @ prefix used to suppress errors, but you should do your own
// error checking by checking return values from each mysql_query()
// Start Transaction
@mysql_query("BEGIN", $wpdb->dbh);
// Do some expensive/related queries here
<?php
function check_Str_len($string) {
echo stripslashes($string).'<br />';
echo strlen( stripslashes($string) ).'<br />';
}
check_Str_len('843175010');
?>
@5iDS
5iDS / wpdb-stored-procedures.php
Created July 5, 2013 11:09
Search for : ( file wd-db.php ) and replace with the following
<?php
function query( $query ) {
if ( ! $this->ready )
return false;
if ( strpos($query, "CALL") === false )
{
$this->dbh = mysql_connect( $this->dbhost, $this->dbuser, $this->dbpassword, true );
$this->set_charset( $this->dbh );
$this->ready = true;
@5iDS
5iDS / _log.php
Created July 22, 2013 13:33
Centralize all log calls to use this function. will call a print_r on arrays and objects passed to the function for simple debugging.
if(!function_exists('_log')){
function _log( $message ) {
if( WP_DEBUG === true ){
if( is_array( $message ) || is_object( $message ) ){
error_log( print_r( $message, true ) );
} else {
error_log( $message );
}
}
}
@5iDS
5iDS / async_social_scripts.js
Created July 22, 2013 18:30
Loading Social Scripts Async.
(function social_async (d) {
var js,
ref = d.getElementsByTagName("head")[0];
js = d.createElement("script");
js.defer = true;
js.async = true;
js.type = "text/javascript";
var social_async_one = {
@5iDS
5iDS / clickatell_send_sms.php
Created July 30, 2013 00:26
Clickatell HTTP API Class
/*--------------------------------------------------*/
/* SMS CLICKATELL
*
* Http API
*
* @param string user
* @param string password
* @param int api_id
* @param int/"array" to (cellphone number) / "","",""
* @param string text (sms message)
@5iDS
5iDS / IIS URL Rewrite
Created September 18, 2013 02:51
IIS REWRITE NON-WWW TO WWW
<rewrite>
<rules>
<rule name="Redirect domain.com to www" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
<conditions>
<add input="{HTTP_HOST}" pattern="domain.com" />
</conditions>
<action type="Redirect" url="http://www.domain.com/{R:0}" />
</rule>
</rules>
@5iDS
5iDS / IIS GZIP - web.config
Created September 18, 2013 03:13
enable GZIP compression through Web.config file
<system.webServer>
<httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files">
<scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll"/>
<dynamicTypes>
<add mimeType="text/*" enabled="true"/>
<add mimeType="message/*" enabled="true"/>
<add mimeType="application/javascript" enabled="true"/>
<add mimeType="*/*" enabled="false"/>
</dynamicTypes>
<staticTypes>