Skip to content

Instantly share code, notes, and snippets.

View arth2o's full-sized avatar

ArtH2O arth2o

View GitHub Profile
@arth2o
arth2o / Faker user csv generator
Created December 10, 2013 10:57
Generate Faker User Data and save CSV format. Used external class: https://github.com/fzaninotto/Faker Class Use in Command line: php faker_csv.php -- 'count=10000' > lorem-10000.csv
#!/usr/bin/php
<?php
error_reporting(0);
//https://github.com/fzaninotto/Faker
require_once 'faker/autoload.php';
$faker = Faker\Factory::create('it_IT'); // create a Italy
//CSV TITLE LINE
$headers = array('unique_client_pk', 'sesso', 'nome', 'cognome', 'email', 'citta', 'cap', 'provincia', 'anno di nascita', 'registrazione', 'partner_pk', );
@arth2o
arth2o / Yandex Translate static class
Created January 1, 2014 19:53
Yandex Translate static class
<?php
/*
* Translate URL: translate.yandex.com
* YANDEX translate documentation: http://api.yandex.com/translate/doc/dg/concepts/About.xml
*/
interface ITranslate {
public static function getMsg($return_status_code = FALSE);
@arth2o
arth2o / isValidDate - javascript
Last active September 30, 2020 11:27
Javascript function: validate date (yyyy-mm-dd) format via JavaScript.
/**
* isValidDate(str)
* @param string str value yyyy-mm-dd
* @return boolean true or false
* IF date is valid return true
*/
function isValidDate(str){
// STRING FORMAT yyyy-mm-dd
if(str=="" || str==null){return false;}
@arth2o
arth2o / Doctrine Cheatsheet
Last active July 23, 2016 17:22
Doctrine Cheatsheet
Doctrine generate entity/entities from database:table
php app/console doctrine:mapping:import --force GleamPageBundle xml
php app/console doctrine:mapping:convert annotation ./src
php app/console doctrine:generate:entities GleamPageBundle
Creating the Database Tables/Schema
php app/console doctrine:schema:update --force
------------------------
@arth2o
arth2o / Twig cheatsheet
Created May 5, 2014 09:06
Twig cheatsheet
Twig list and dinamic url
{% extends 'GleamPageBundle::base.html.twig' %}
{% block body %}
{% if pages %}
<ul>
{% for page in pages %}
<li><a href="{{ path('gleam_page_showcontent', {'id': page.id}) }}" target="_blank" title="{{ page.title }}">{{ page.title }}</a></li>
{% endfor %}
</ul>
@arth2o
arth2o / gist:ced65bce081c163e3fb2
Created June 22, 2015 06:35
Batch video convert from flv to mp4 via Linux CMD use avconv binary
#!/usr/bin/php
<?php
$folder = dirname(__FILE__)."/";
//or you can set this by manual
//$folder = "/var/www/lorem/ipsum/"
$outputFolder = "mp4/";
$from = ".flv";
$to = ".mp4";
@arth2o
arth2o / Flat array
Created November 18, 2015 10:47
Flatten an array of arbitrarily nested arrays
$arr = [[1,2,[3]],4];
$newArr = array();
foreach( (new RecursiveIteratorIterator(new RecursiveArrayIterator($arr))) as $val) {
$newArr[] = $val;
}
var_dump($newArr);
@arth2o
arth2o / PHP yield to stream big file
Last active November 20, 2015 14:54
PHP yield example to open big file and stream line by line
<?php
/**
* Class File
*/
class File
{
private $fileName;
private $file;
@arth2o
arth2o / JavaScript IpToLong and IpFromLong
Created November 19, 2015 10:58
JavaScript IpToLong and IpFromLong
ipToLong = function toInt(ip){
var ipl=0;
ip.split('.').forEach(function( octet ) {
ipl<<=8;
ipl+=parseInt(octet);
});
return(ipl >>>0);
};
ipFromLong = function fromInt(ipl){
@arth2o
arth2o / JavaScript IP validation
Created November 19, 2015 11:32
JavaScript regexp ip validation
function validateIp(ipaddress)
{
if (/^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/.test(ipaddress))
{
return (true)
}
return (false)
}