Skip to content

Instantly share code, notes, and snippets.

View ericstone57's full-sized avatar

ericstone57 ericstone57

  • Kantar
  • Shanghai
View GitHub Profile
@ericstone57
ericstone57 / gist:4b4f473a0fb0d703dd30
Created May 27, 2014 15:17
PHP Curl POST and GET
/**
* Send a POST requst using cURL
* @param string $url to request
* @param array $post values to send
* @param array $options for cURL
* @return string
*/
function curl_post($url, array $post = NULL, array $options = array())
{
$defaults = array(
@ericstone57
ericstone57 / gist:25ec83de97d5468810a5
Created December 4, 2014 03:30
sanitize utf8mb4 characters
/**
* sanitize utf8mb4 characters
*/
function _utf8_4byte_to_3byte($input) {
if (!empty($input)) {
$utf8_2byte = 0xC0 /*1100 0000*/; $utf8_2byte_bmask = 0xE0 /*1110 0000*/;
$utf8_3byte = 0xE0 /*1110 0000*/; $utf8_3byte_bmask = 0XF0 /*1111 0000*/;
$utf8_4byte = 0xF0 /*1111 0000*/; $utf8_4byte_bmask = 0xF8 /*1111 1000*/;
$sanitized = "";
@ericstone57
ericstone57 / sequence_img_combine.php
Created July 23, 2016 18:00
Combine image sequences as numbers of pics in a row which with multiple files. Depend on ImageMagic.
<?php
$from = 1;
$to = 360;
$figure_lenght = 4;
$pic_one_row = 3;
$file_prefix = "output_";
$file_extension = ".jpg";
$output_folder = "./result/";
$output_index = 1;
@ericstone57
ericstone57 / http_proxy_setting.sh
Created April 25, 2020 07:28
http_proxy_setting.sh
# where proxy
proxy () {
export http_proxy="http://127.0.0.1:8087"
export https_proxy="http://127.0.0.1:8087"
echo "HTTP Proxy on"
}
# where noproxy
noproxy () {
unset http_proxy
@ericstone57
ericstone57 / dict_flatten.py
Last active October 26, 2020 18:52
to flatten dict strcuture
def dict_flatten(d, parent_key='', sep=''):
items = []
for k, v in d.items():
new_key = parent_key + sep + str(k) if parent_key else str(k)
if v and isinstance(v, collections.MutableMapping):
items.extend(dict_flatten(v, new_key, sep=sep).items())
else:
items.append((new_key, v))
return dict(items)
@ericstone57
ericstone57 / code_generate.php
Last active October 26, 2020 18:51
PHP simple random code generator
<?php
// code length 5 characters
$code = substr(str_shuffle('0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'), 1, 5);
@ericstone57
ericstone57 / install-docker.sh
Last active January 3, 2021 16:35 — forked from EvgenyOrekhov/A simple Docker and Docker Compose install script for Ubuntu.md
A simple Docker and Docker Compose install script for Ubuntu
#!/bin/sh
set -o errexit
set -o nounset
# Docker
sudo apt update
sudo apt --yes --no-install-recommends install software-properties-common apt-transport-https ca-certificates
wget --quiet --output-document=- https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=$(dpkg --print-architecture)] https://download.docker.com/linux/ubuntu $(lsb_release --codename --short) stable"
@ericstone57
ericstone57 / ip.php
Created November 24, 2020 08:05
Get IP Address
// uses isset to remove notices
$ip = isset($_SERVER['HTTP_CLIENT_IP']) ? $_SERVER['HTTP_CLIENT_IP'] : isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];