Skip to content

Instantly share code, notes, and snippets.

@rettal
rettal / isemptyobject.js
Created January 25, 2016 09:26 — forked from gruppjo/isemptyobject.js
angularjs - empty object filter
'use strict';
angular.module('crmApp')
.filter('isEmptyObject', function () {
return function (obj) {
return angular.equals({}, obj);
};
});
function convert_to_csv($input_array, $output_file_name, $delimiter)
{
/** open raw memory as file, no need for temp files, be careful not to run out of memory thought */
$f = fopen('php://memory', 'w');
/** loop through array */
foreach ($input_array as $line) {
/** default php csv handler **/
fputcsv($f, $line, $delimiter);
}
/** rewrind the "file" with the csv lines **/
function getList(item, $list) {
if($.isArray(item)) {
$.each(item, function (key, value) {
getList(value, $list);
});
return;
}
if (item) {
var $li = $('<li />');
if (item.name) {
# http://php.net/manual/en/function.checkdate.php
function validateDate($date, $format = 'Y-m-d H:i:s')
{
$d = DateTime::createFromFormat($format, $date);
return $d && $d->format($format) == $date;
}
var_dump(validateDate('2012-02-28 12:12:12')); # true
var_dump(validateDate('2012-02-30 12:12:12')); # false
var_dump(validateDate('2012-02-28', 'Y-m-d')); # true
<?php
use Zend\Mvc\ModuleRouteListener;
use Zend\Mvc\MvcEvent;
class Module
{
public function onBootstrap(MvcEvent $e)
{
@rettal
rettal / composer_git_create_project
Created April 23, 2015 19:15
Composer/Git Checkout and Create Project
php composer.phar create-project -sdev --repository-url="https://packages.zendframework.com" zendframework/skeleton-application c:\xampp\htdocs\zf2
update log_data SET `timestamp` = `timestamp` + INTERVAL 1 DAY WHERE id >= 1000 LIMIT 1000;
SELECT datetime + INTERVAL 10 YEAR + INTERVAL 3 MONTH + INTERVAL 22 DAY
+ INTERVAL 10 HOUR + INTERVAL 30 MINUTE AS new_date_time FROM table;
@rettal
rettal / chart.html
Last active August 29, 2015 14:16 — forked from eyeseast/chart.html
<div id="chart">
<h4>Percent of adults over 25 with at least a bachelor's degree:</h4>
<p><strong>Median:</strong> <span class="median"></span></p>
<small>Source: <cite><a href="http://census.gov">U.S. Census Bureau</a></cite>, via <cite><a href="http://beta.censusreporter.org/compare/01000US/040/table/?release=acs2011_1yr&table=B15003">Census Reporter</a></cite></small>
</div>
@rettal
rettal / Download CSV
Created February 20, 2015 13:55
Download CSV
public function downloadCsvAction()
{
$oldTimeLimit = ini_get('max_execution_time');
ini_set('max_execution_time', 60);
$lang = $this->params('lang', "en");
$this->setRatingsViewData($this->viewData, $lang);
$headers = array(
'location_name',
'breakdown_period',
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min)) + min;
}
/*
Code example explaining the enter, update and exit states in D3.
The 3 states basically define the actions that occur when data is added to a selection of elements.
Say if we were selecting data from a database where we had to perform a search with a query string,
each time we ran query the number of rows returned could be more, less, or could be the same but
contain different data, these in essence are the 3 states. more = enter, less = exit, same = update.