Skip to content

Instantly share code, notes, and snippets.

@shmaltorhbooks
shmaltorhbooks / mail_log.php
Created June 3, 2013 19:10
Email error logs to yourself
<?php
// Our custom error handler
function nettuts_error_handler($number, $message, $file, $line, $vars){
$email = "
<p>An error ($number) occurred on line
<strong>$line</strong> and in the <strong>file: $file.</strong>
<p> $message </p>";
$email .= "<pre>" . print_r($vars, 1) . "</pre>";
@shmaltorhbooks
shmaltorhbooks / twitter.php
Created June 3, 2013 19:09
Get all tweets of a specific hashtag
function getTweets($hash_tag) {
$url = 'http://search.twitter.com/search.atom?q='.urlencode($hash_tag) ;
echo "<p>Connecting to <strong>$url</strong> ...</p>";
$ch = curl_init($url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, TRUE);
$xml = curl_exec ($ch);
curl_close ($ch);
//If you want to see the response from Twitter, uncomment this next part out:
@shmaltorhbooks
shmaltorhbooks / distance.php
Last active December 18, 2015 00:59
Calculate distance between two points
<?php
function getDistanceBetweenPointsNew($latitude1, $longitude1, $latitude2, $longitude2) {
$theta = $longitude1 - $longitude2;
$miles = (sin(deg2rad($latitude1)) * sin(deg2rad($latitude2))) + (cos(deg2rad($latitude1)) * cos(deg2rad($latitude2)) * cos(deg2rad($theta)));
$miles = acos($miles);
$miles = rad2deg($miles);
$miles = $miles * 60 * 1.1515;
$feet = $miles * 5280;
$yards = $feet / 3;
@shmaltorhbooks
shmaltorhbooks / sanitize.php
Created June 3, 2013 19:07
Sanitize database inputs When inserting data in your database, you have to be really careful about SQL injections and other attempts to insert malicious data into the db. The function below is probably the most complete and efficient way to sanitize a string before using it with your database.
function cleanInput($input) {
$search = array(
'@<script[^>]*?>.*?</script>@si', // Strip out javascript
'@<[\/\!]*?[^<>]*?>@si', // Strip out HTML tags
'@<style[^>]*?>.*?</style>@siU', // Strip style tags properly
'@<![\s\S]*?--[ \t\n\r]*>@' // Strip multi-line comments
);
$output = preg_replace($search, '', $input);
@shmaltorhbooks
shmaltorhbooks / create.sql
Created May 15, 2013 09:21
create database with utf8, create new user and grant access to db;
CREATE DATABASE dbname DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;
GRANT ALL PRIVILEGES ON dbname>.* TO 'new_user'@'localhost'
IDENTIFIED BY 'pswd' WITH GRANT OPTION;
@shmaltorhbooks
shmaltorhbooks / parent.php
Last active December 17, 2015 06:49 — forked from ephrin/parent.php
Call method from parent class with unknown arguments length
<?php
class Demo extends ParentClass
{
function demoParent(...$arguments)
{
// some overrided logic
return (new \ReflectionClass(get_class($this)))
->getParentClass()
->getMethod(__METHOD__)
@shmaltorhbooks
shmaltorhbooks / remove.sh
Created May 10, 2013 11:29
remove .svn recursively
rm -rf `find . -type d -name .svn`
@shmaltorhbooks
shmaltorhbooks / permissions.sh
Created May 10, 2013 11:27
644 to files 755 to folders
find ./ -type f -exec chmod 644 {} \;
find ./ -type d -exec chmod 755 {} \;
yum remove selinux-policy evolution -y;
wget http://archive.fedoraproject.org/pub/archive/fedora/linux/releases/12/Everything/x86_64/os/Packages/mysql-gui-common-5.0r14-1.fc12.x86_64.rpm http://archive.fedoraproject.org/pub/archive/fedora/linux/releases/12/Everything/x86_64/os/Packages/mysql-gui-tools-5.0r14-1.fc12.x86_64.rpm http://archive.fedoraproject.org/pub/archive/fedora/linux/releases/12/Everything/x86_64/os/Packages/mysql-query-browser-5.0r14-1.fc12.x86_64.rpm http://archive.fedoraproject.org/pub/archive/fedora/linux/releases/12/Everything/x86_64/os/Packages/mysql-administrator-5.0r14-1.fc12.x86_64.rpm;
rpm -ihv ./*.rpm
yum install libXv-1.0.5-1.fc13.i686 libXScrnSaver-1.2.0-1.fc12.i686 qt-4.6.3-8.fc13.i686 qt-x11-4.6.3-8.fc13.i686 -y;
yum install skype -y;
yum install cowsay -y;
yum install mc -y;
@shmaltorhbooks
shmaltorhbooks / replace.sql
Last active December 17, 2015 04:58
find and replace CR
SELECT * FROM auto4.model WHERE `name` like '%\n';
UPDATE auto3.model m SET name=REPLACE(name, '\n', '')