Skip to content

Instantly share code, notes, and snippets.

@real34
real34 / memory_usage.php
Created November 1, 2011 06:59
PHP : A simple function to display the current memory usage
<?php
// @see http://fr2.php.net/manual/en/function.mb-convert-encoding.php#103300
function memory_usage() {
$mem_usage = memory_get_usage(true);
if ($mem_usage < 1024) {
$mem_usage .= ' bytes';
} elseif ($mem_usage < 1048576) {
$mem_usage = round($mem_usage/1024,2) . ' kilobytes';
} else {
$mem_usage = round($mem_usage/1048576,2) . ' megabytes';
@real34
real34 / load-test.sh
Last active November 30, 2020 09:57 — forked from bigomega/load-test.sh
A simple bash script to do load (performance) testing of a web service
max="$1"
date
echo "url: $2
rate: $max calls / second"
START=$(date +%s);
get () {
curl -s -o /dev/null -w %{http_code} --max-time 3 "$1" 2>&1 | tr '\r\n' '\\n' | awk -v date="$(date +'%r')" '{print $0"\n-----", date}' >> /tmp/perf-test.log
}
@real34
real34 / monitor_slave.js
Created June 6, 2013 10:05
CasperJs script to monitor MySQL replication slave status through PhpMyAdmin. Tested with PhpMyAdmin v3.3.9
var casper = require('casper').create();
var utils = require('utils');
var phpMyAdminUrl = casper.cli.args[0];
var phpMyAdminCredentials = {
pma_username: casper.cli.options.user,
pma_password: casper.cli.options.password
};
if (!phpMyAdminUrl || !phpMyAdminCredentials.pma_username || !phpMyAdminCredentials.pma_password) {
casper.echo('Invalid parameters. Usage: casperjs monitor_slave.js http://example.com/phpMyAdmin --user=foo --password=bar');
// Created with https://checklyhq.com/docs/puppeteer-recorder/
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch()
const page = await browser.newPage()
const navigationPromise = page.waitForNavigation()
await page.goto('https://demo.front-commerce.com/')
import React, { useState } from "react";
import logo from "./logo.svg";
import "./App.css";
function App() {
const [counter, setCounter] = useState(0);
const increment = () => setCounter(counter + 1);
const decrement = () => setCounter(counter - 1);
{
product(sku:"LOW-310589") {
name
imageUrl
giftMessageAvailable
sku
brand
terrangAdvice
isBuyableOnline
additionalInformation {
@real34
real34 / APC-Recipe.rb
Created June 22, 2012 13:26
Capistrano : APC recipe to deal with Apache APC cache
##
# APC recipe
# => convenience rules for dealing with APC in applications
##
_cset(:apc_webroot) { "" }
namespace :apc do
desc <<-DESC
Create a temporary PHP file to clear APC cache, call it (using curl) and removes it
@real34
real34 / front_commerce-magento_2_url.json
Created May 23, 2017 06:37
Pact specification for retrieving urls from a headless Magento2 (custom module)
{
"consumer": {
"name": "Front Commerce"
},
"provider": {
"name": "Magento 2 Url"
},
"interactions": [
{
"description": "A find request for entity with type category and id 6",
@real34
real34 / FakeAddressRepository.php
Last active May 2, 2017 19:44
Magento2 Fakes implementation built step by step to support our tests. (Context: https://mobile.twitter.com/fschmengler/status/859473111984590848)
<?php
namespace Terrang\Fluxs\Test\Fake\Repository;
use Magento\Framework\Exception\NoSuchEntityException;
class FakeAddressRepository implements \Magento\Customer\Api\AddressRepositoryInterface
{
private $db = [];