View isemptyobject.js
'use strict'; | |
angular.module('crmApp') | |
.filter('isEmptyObject', function () { | |
return function (obj) { | |
return angular.equals({}, obj); | |
}; | |
}); |
View AngulaJS Filter Example
<!DOCTYPE html> | |
<html data-ng-app="DemoApp"> | |
<head> | |
<meta charset="utf-8"> | |
<body> | |
<div class="container" data-ng-controller="SimpleController"> | |
Name: | |
<br /> | |
<input type="text" data-ng-model="name" /> {{name}} |
View Strip Spaces & Tabs in Javascrip
var str = '\n\n\n Multiline text\n with indentation\n damn.\n\n\n'; | |
// remove first and last empty lines | |
str = str.replace(/^[\r\n]+|[\n\r]+$/gi, ''); | |
var indentTab = str.match(/\t*/) != '', | |
indentSize = indentTab ? 1 : str.match(/\s*/)[0].length, | |
regex = new RegExp('^(?:' + (indentTab ? '\\t' : ' {' + indentSize + '}') + ')', 'mg'); | |
// Remove indent |
View array_to_csv.php
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 **/ |
View nested list.js
function getList(item, $list) { | |
if($.isArray(item)) { | |
$.each(item, function (key, value) { | |
getList(value, $list); | |
}); | |
return; | |
} | |
if (item) { | |
var $li = $('<li />'); | |
if (item.name) { |
View validate_date.php
# 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 |
View gist:4a6e9ae973ed09fae382
<?php | |
use Zend\Mvc\ModuleRouteListener; | |
use Zend\Mvc\MvcEvent; | |
class Module | |
{ | |
public function onBootstrap(MvcEvent $e) | |
{ |
View composer_git_create_project
php composer.phar create-project -sdev --repository-url="https://packages.zendframework.com" zendframework/skeleton-application c:\xampp\htdocs\zf2 |
View MySQL Datetime Manipulation
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; |
View 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> |
NewerOlder