Skip to content

Instantly share code, notes, and snippets.

Avatar

ericstone57 ericstone57

  • Kantar
  • Shanghai
View GitHub Profile
@ericstone57
ericstone57 / ip.php
Created Nov 24, 2020
Get IP Address
View ip.php
// 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'];
@ericstone57
ericstone57 / install-docker.sh A simple Docker and Docker Compose install script for Ubuntu
View install-docker.sh
#!/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 / code_generate.php
Last active Oct 26, 2020
PHP simple random code generator
View code_generate.php
<?php
// code length 5 characters
$code = substr(str_shuffle('0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'), 1, 5);
@ericstone57
ericstone57 / dict_flatten.py
Last active Oct 26, 2020
to flatten dict strcuture
View dict_flatten.py
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)
View 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 / sequence_img_combine.php
Created Jul 23, 2016
Combine image sequences as numbers of pics in a row which with multiple files. Depend on ImageMagic.
View sequence_img_combine.php
<?php
$from = 1;
$to = 360;
$figure_lenght = 4;
$pic_one_row = 3;
$file_prefix = "output_";
$file_extension = ".jpg";
$output_folder = "./result/";
$output_index = 1;
View gist:25ec83de97d5468810a5
/**
* 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 = "";
View gist:4b4f473a0fb0d703dd30
/**
* 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(