Skip to content

Instantly share code, notes, and snippets.

View lastday154's full-sized avatar

Steve Hoang lastday154

  • NIT Warangal, India
View GitHub Profile
@lastday154
lastday154 / compass.js
Created May 10, 2018 03:39
compass setup
sudo gem install compass -n /usr/local/bin
cd public
compass create styleSheets
ls
css styleSheets
cd styleSheets
/Applications/MAMP/htdocs/elasticsearch/public/styleSheets
@lastday154
lastday154 / csv.php
Created April 25, 2018 09:06
Export to csv
<?php
https://www.yiiframework.com/extension/csvexport
Yii::import('ext.ECSVExport');
// for use with array of arrays
$data = array(
array('key1'=>'value1', 'key2'=>'value2')
....
)
@lastday154
lastday154 / s3.xml
Created April 18, 2018 02:42
s3 configuration
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
<AllowedMethod>PUT</AllowedMethod>
<AllowedMethod>POST</AllowedMethod>
<AllowedMethod>DELETE</AllowedMethod>
<MaxAgeSeconds>3000</MaxAgeSeconds>
<AllowedHeader>*</AllowedHeader>
@lastday154
lastday154 / isset.php
Created March 29, 2018 03:33
isset vs in_array
<?php
$fields = ['id', 'availability', 'condition', 'description', 'image_link', 'link', 'title', 'price', 'currency'];
var_dump(isset($fields['id']));
var_dump(isset($fields[0]));
var_dump(in_array('id', $fields));
bool(false)
bool(true)
bool(true)
@lastday154
lastday154 / validate.php
Last active March 26, 2018 07:44
Yii Validation
class Validator extends CFormModel
{
public $id;
public function rules()
{
return [
[['id'], 'required'],
['id', 'length', 'max' => 50],
['price', 'validatePrice'],
@lastday154
lastday154 / error.php
Created March 21, 2018 08:35
Enable error
error_reporting(-1);
ini_set('display_errors', 'On');
@lastday154
lastday154 / stringtify.js
Created March 13, 2018 02:25
When sending data to a web server, the data has to be a string.
var mappingData = {};
mappingData[MASTER_PLATFORM_ID] = data;
formData.append('mapping_data', JSON.stringify(mappingData));
https://www.w3schools.com/js/js_json_stringify.asp
@lastday154
lastday154 / s3.php
Created March 9, 2018 02:37
Read from S3 aws
/**
* Get data from S3 as Stream Wrapper
* @param $catalogId
* @param $fileName
* @param bool $headerOnly
* @param int $numRow
* @return array
*/
public function getContentCsvS3($catalogId, $fileName, $headerOnly = false, $numRow = 0) {
$s3Client = S3Client::factory(array('key' => S3KEY_FEED, 'secret' => S3SECRET_FEED));
@lastday154
lastday154 / bigfile.php
Created March 2, 2018 04:50
Read big file csv
function file_get_contents_chunked($file,$chunk_size,$callback)
{
try
{
$handle = fopen($file, "r");
$i = 0;
while (!feof($handle))
{
call_user_func_array($callback,array(fread($handle,$chunk_size),&$handle,$i));
$i++;
@lastday154
lastday154 / onload.js
Created January 19, 2018 01:31
Execute after script loaded
function loadScript( url, callback ) {
var script = document.createElement( "script" )
script.type = "text/javascript";
if(script.readyState) { //IE
script.onreadystatechange = function() {
if ( script.readyState === "loaded" || script.readyState === "complete" ) {
script.onreadystatechange = null;
callback();
}
};