Skip to content

Instantly share code, notes, and snippets.

@sdiama
sdiama / jq-disableLinks.js
Last active October 20, 2016 04:07
Disable Links with jQuery
@sdiama
sdiama / clipboard.js
Created October 20, 2016 04:10
Accessing The Clipboard With JavaScript
var button = document.getElementById("copy-button"),
contentHolder = document.getElementById("content-holder");
button.addEventListener("click", function() {
// We will need a range object and a selection.var range = document.createRange(),
selection = window.getSelection();
// Clear selection from any previous data.
selection.removeAllRanges();
@sdiama
sdiama / highlight.php
Last active May 19, 2020 10:07
HighLight Specific Words in a Phrase
function highlight($sString, $aWords) {
if (!is_array ($aWords) || empty ($aWords) || !is_string ($sString)) {
return false;
}
$sWords = implode ('|', $aWords);
return preg_replace ('@\b('.$sWords.')\b@si', '<strong style="background-color:yellow">$1</strong>', $sString);
}
@sdiama
sdiama / generatePassword.php
Created October 28, 2016 07:48
AUTOMATIC PASSWORD CREATION
function generatePassword($length=9, $strength=0) {
$vowels = 'aeuy';
$consonants = 'bdghjmnpqrstvz';
if ($strength >= 1) {
$consonants .= 'BDGHJLMNPQRSTVWXZ';
}
if ($strength >= 2) {
$vowels .= "AEUY";
}
if ($strength >= 4) {
@sdiama
sdiama / compressCSS.php
Created October 28, 2016 07:48
COMPRESS MULTIPLE CSS FILES
header('Content-type: text/css');
ob_start("compress");
function compress($buffer) {
/* remove comments */
$buffer = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $buffer);
/* remove tabs, spaces, newlines, etc. */
$buffer = str_replace(array("\r\n", "\r", "\n", "\t", ' ', ' ', ' '), '', $buffer);
return $buffer;
}
@sdiama
sdiama / bootstrap-masonry-template.htm
Created November 10, 2016 02:56 — forked from justincarroll/bootstrap-masonry-template.htm
This is my template for using Masonry 3 with Bootstrap 3. For those of you who follow this gist a lot has changed since Bootstrap 2.
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Bootstrap Masonry Template</title>
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=PT+Sans+Caption:400,700">
@sdiama
sdiama / index.php
Created January 9, 2018 19:24 — forked from mloberg/index.php
Last.fm Simple PHP Class
<?php
include_once('lastfm.php');
$lastfm = new LastFm('your-api-key');
$params = array(
'user' => 'mloberg'
);
print_r($lastfm->call('user.getInfo', $params));
/*-------------------------------------------------+
| Get random line from file
+-------------------------------------------------*/
function getRandomLine($filename) {
$lines = file($filename);
return $lines[array_rand($lines)];
}
@sdiama
sdiama / dailybackup.sh
Created August 22, 2018 15:34
Backup of Web Server files and Mysql database
#!/bin/bash
today=`date +'%Y%m%d'`
cd /HOME_DIR
echo
echo Backing up Files of Server Config
echo ---------------------------------
zip -r my-server_config-$today.zip /etc/apache2/.
echo
@sdiama
sdiama / update_c9_to_php7.2.sh
Last active January 23, 2019 17:17
Upgrade Cloud9 (c9) to php v7.2
sudo apt update -y
sudo apt-get install python-software-properties -y
sudo add-apt-repository ppa:ondrej/php -y
sudo apt-get update -y
sudo apt-get install php7.2 php-pear php7.2-curl php7.2-dev php7.2-gd php7.2-mbstring php7.2-zip php7.2-mysql php7.2-xml
sudo mv /etc/apache2/envvars /etc/apache2/envvars.bak
sudo apt-get remove libapache2-mod-php5 -y
sudo apt-get install libapache2-mod-php7.2 -y