Skip to content

Instantly share code, notes, and snippets.

@pebriana
pebriana / Yii Examples of Using CDbCriteria
Last active April 28, 2022 12:34
Yii Examples of Using CDbCriteria
<?php
//Examples of Using CDbCriteria
//Basic Usage
$Criteria = new CDbCriteria();
$Criteria->condition = "price > 30";
$Products = Product::model()->findAll($Criteria);
//OR
-- Grant For Schema
GRANT ALL PRIVILEGES ON SCHEMA pdg TO project1;
-- Grant For Table
GRANT ALL PRIVILEGES ON TABLE pdg.proposal TO project1;
-- Grant For Sequence
GRANT USAGE, SELECT ON SEQUENCE pdg.proposal_id_seq TO project1;
-- Grant For View
GRANT SELECT ON pdg.vw_program_hierarchy TO project1;
-- //-- Source: http://www.postgresql.org/docs/8.3/static/sql-grant.html --//
<?php
/**
* Calculate a precise time difference.
* @param string $start result of microtime()
* @param string $end result of microtime(); if NULL/FALSE/0/'' then it's now
* @return flat difference in seconds, calculated with minimum precision loss
*/
function microtime_diff($start, $end = null) {
if (!$end) $end = microtime();
-- Enable tablefunc
CREATE EXTENSION tablefunc;
-- Original Query Data
SELECT generate_series AS date,
b.desc AS TYPE,
(random() * 10000 + 1)::int AS val
FROM generate_series((now() - '100 days'::interval)::date, now()::date, '1 day'::interval),
(SELECT unnest(ARRAY['OSX', 'Windows', 'Linux']) AS DESC) b;
// add this to your API controller in Yii
public function actionPreflight() {
$content_type = 'application/json';
$status = 200;
// set the status
$status_header = 'HTTP/1.1 ' . $status . ' ' . $this->_getStatusCodeMessage($status);
header($status_header);
@pebriana
pebriana / wp-json-last-5-post
Created June 24, 2015 02:18
mengambil 5 post terakir. dalam format json
<?php header('Access-Control-Allow-Origin: *'); ?>
{"berita":[
<?php
$args = array( 'posts_per_page' => 5, 'offset'=> 0 );
$myposts = get_posts( $args );
$no=1;
foreach ( $myposts as $post ) : setup_postdata( $post ); ?>
{
"judul": "<?php the_title(); ?>",
"gambar": "<?php if ( has_post_thumbnail() ) {
@pebriana
pebriana / gist:c3615aefe4f483f287ff
Created July 1, 2015 06:50
Google Advanced search
https://support.google.com/mail/answer/7190?hl=en
@pebriana
pebriana / gist:b716c3a95baacdc9e935
Last active February 21, 2016 00:39
Material Design
http://material-ui.com/
https://www.muicss.com/
http://materializecss.com/
https://material.angularjs.org/
http://googel.com/design/
http://materialup.com/
https://fezvrasta.github.io/bootstrap-material-design/
http://www.getmdl.io/
@pebriana
pebriana / PHP CODE SNIPPETS
Created July 9, 2015 01:54
46 USEFUL PHP CODE SNIPPETS THAT CAN HELP YOU WITH YOUR PHP PROJECTS
http://blog.koonk.com/2015/07/46-useful-php-code-snippets-that-can-help-you-with-your-php-projects/
@pebriana
pebriana / link
Created July 15, 2015 09:16
link