Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / 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 / number.php
Last active December 18, 2015 00:59
Add (th, st, nd, rd, th) to the end of a number
<?php
function ordinal($cdnl){
$test_c = abs($cdnl) % 10;
$ext = ((abs($cdnl) %100 < 21 && abs($cdnl) %100 > 4) ? 'th'
: (($test_c < 4) ? ($test_c < 3) ? ($test_c < 2) ? ($test_c < 1)
? 'th' : 'st' : 'nd' : 'rd' : 'th'));
return $cdnl.$ext;
}
@shmaltorhbooks
shmaltorhbooks / generate_ssl_nginx.sh
Created December 10, 2013 10:41
generate self-signed ssl certificates for nginx
sudo mkdir /etc/nginx/ssl && cd /etc/nginx/ssl
sudo openssl genrsa -des3 -out server.key 1024
sudo openssl req -new -key server.key -out server.csr
sudo cp server.key server.key.org
sudo openssl rsa -in server.key.org -out server.key
sudo openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
echo "add these lines into your nginx host config"
echo " ssl on;"
echo " ssl_certificate /etc/nginx/ssl/server.crt;"
echo " ssl_certificate_key /etc/nginx/ssl/server.key;"
Article:
manyToMany:
tags:
targetEntity: Tag
inversedBy: articles
joinTable:
name: tags_for_articles
joinColumns:
article_id:
referencedColumnName: id
alias l='ls -alF'
alias la='ls -A'
alias ll='ls -CF'
alias gittree='git log --pretty=format:"%h - %an, %ar : %s" --graph'