Skip to content

Instantly share code, notes, and snippets.

View mihai-vlc's full-sized avatar

Mihai Ionut Vilcu mihai-vlc

View GitHub Profile
@mihai-vlc
mihai-vlc / vaild_email.php
Last active December 17, 2015 17:59
PHP: isValidMail
<?php
function isValidMail($mail) {
if(!filter_var($mail, FILTER_VALIDATE_EMAIL))
return FALSE;
if(!checkdnsrr("gmail.com", "MX")) // if we have no internet access on the server
return TRUE;
@mihai-vlc
mihai-vlc / conio.h
Last active December 18, 2015 02:09
CPP: getch() on linux
// found on http://stackoverflow.com/a/7469410/1579481
#include <termios.h>
#include <stdio.h>
static struct termios old, newp;
/* Initialize new terminal i/o settings */
void initTermios(int echo)
{
tcgetattr(0, &old); /* grab old terminal i/o settings */
@mihai-vlc
mihai-vlc / sendMail.php
Last active December 18, 2015 10:59
PHP: sendMail
<?php
function sendMail($to, $subject, $message, $from = 'From: [email protected]', $isHtml = true) {
$from .= "\r\n"; // we make sure we have an endline
if($isHtml) {
$from .= "MIME-Version: 1.0 \r\n";
$from .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
}
$from .= 'X-Mailer: PHP/'.phpversion()."\r\n";
@mihai-vlc
mihai-vlc / getos.php
Created June 23, 2013 20:34
PHP: get os
<?php
function get_os() {
$browser = $_SERVER['HTTP_USER_AGENT'];
if (strpos($browser,"Windows") !== FALSE) {
return "Windows";
}else if (strpos($browser,"Linux") !== FALSE) {
return "Linux";
}else if (strpos($browser,"FreeBSD") !== FALSE) {
return "FreeBSD";
@mihai-vlc
mihai-vlc / maxupl.php
Last active December 19, 2015 04:49
PHP: get max upload
<?php
function get_max_upl() {
$max_upload = (int)(ini_get('upload_max_filesize'));
$max_post = (int)(ini_get('post_max_size'));
$memory_limit = (int)(ini_get('memory_limit'));
return min($max_upload, $max_post, $memory_limit);
}
@mihai-vlc
mihai-vlc / deleteAll.php
Created July 6, 2013 08:31
PHP: delete all files/folders
<?php
function deleteAll($directory, $empty = false) {
$t= time() - 60*60*24*4;
if(substr($directory,-1) == "/") {
$directory = substr($directory,0,-1);
}
if(!file_exists($directory) || !is_dir($directory)) {
return false;
@mihai-vlc
mihai-vlc / tsince.php
Last active December 19, 2015 11:08
PHP: time since
<?php
/**
* Time elapes since a times
* @param int $time The past time
* @return string time elapssed
* credits: http://stackoverflow.com/a/2916189/1579481
*/
function tsince($time, $end_msg = 'ago') {
$time = abs(time() - $time); // to get the time since that moment
@mihai-vlc
mihai-vlc / realip.php
Last active December 19, 2015 11:08
PHP: real ip
<?php
// Returns the real IP address of the user
function i2c_realip()
{
// No IP found (will be overwritten by for
// if any IP is found behind a firewall)
$ip = FALSE;
// If HTTP_CLIENT_IP is set, then give it priority
@mihai-vlc
mihai-vlc / cssreset.css
Created July 9, 2013 08:26
CSS: css reset
/******************************/
/* 1. CSS Reset
/******************************/
body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,form,fieldset,input,textarea,p,blockquote,th,td {
margin:0;
padding:0;
}
table {
border-collapse:collapse;
border-spacing:0;
@mihai-vlc
mihai-vlc / bootstrap.html
Created July 13, 2013 17:51
HTML: bootstrap css/js cdn
<!DOCTYPE html>
<html>
<head>
<link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css" rel="stylesheet">
<script src="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/js/bootstrap.min.js">
</script>
<title></title>
</head>
<body>