Skip to content

Instantly share code, notes, and snippets.

View slow-is-fast's full-sized avatar

slow-is-fast slow-is-fast

View GitHub Profile
function removeEmoji($text)
{
$cleanText = "";
// Match Emoticons
$regexEmoticons = '/[\x{1F600}-\x{1F64F}]/u';
$cleanText = preg_replace($regexEmoticons, '', $text);
// Match Miscellaneous Symbols and Pictographs
$regexSymbols = '/[\x{1F300}-\x{1F5FF}]/u';
@slow-is-fast
slow-is-fast / __upload_file.md
Created August 16, 2018 09:58 — forked from maxivak/__upload_file.md
PHP upload file with curl (multipart/form-data)

We want to upload file to a server with POST HTTP request. We will use curl functions.


// data fields for POST request
$fields = array("f1"=>"value1", "another_field2"=>"anothervalue");

// files to upload
$filenames = array("/tmp/1.jpg", "/tmp/2.png");;
@slow-is-fast
slow-is-fast / MultiPartFromStrings.php
Created August 16, 2018 09:58 — forked from iansltx/MultiPartFromStrings.php
Multipart file uploads in PHP from strings
<?php
/**
* PHP's curl extension won't let you pass in strings as multipart file upload bodies; you
* have to direct it at an existing file (either with deprecated @ syntax or the CURLFile
* type). You can use php://temp to get around this for one file, but if you want to upload
* multiple files then you've got a bit more work.
*
* This function manually constructs the multipart request body from strings and injects it
* into the supplied curl handle, with no need to touch the file system.
```AppleScript
(*
◸ Veritrope.com
Export All Safari Tabs to a Text File
VERSION 1.1
March 5, 2013
// UPDATE NOTICES
** Follow @Veritrope on Twitter, Facebook, Google Plus, and ADN for Update Notices! **
@slow-is-fast
slow-is-fast / pad.js.md
Last active March 20, 2018 11:33
format js format
function pad(num, size) {
    var s = num+"";
    while (s.length < size) s = "0" + s;
    return s;
}
@slow-is-fast
slow-is-fast / rename_sequence_file.md
Created March 20, 2018 09:27
rename sequence file
a=1
for i in *.jpg; do
  new=$(printf "%04d.jpg" "$a") #04 pad to length of 4
  mv -i -- "$i" "$new"
  let a=a+1
done
@slow-is-fast
slow-is-fast / file_md5.md
Created March 10, 2018 06:12
python get file md5
#!/usr/bin/env python

import hashlib


def md5(fname):
    hash_md5 = hashlib.md5()
    with open(fname, "rb") as f:
 for chunk in iter(lambda: f.read(4096), b""):
@slow-is-fast
slow-is-fast / openssl incompatiblity.md
Created March 9, 2018 16:37
Incompatibility between OpenSSL 1.1.0 and 1.0.2

AttributeError: /usr/lib/x86_64-linux-gnu/libcrypto.so.1.1: undefined symbol: EVP_CIPHER_CTX_cleanup

vim /usr/local/lib/python2.7/dist-packages/shadowsocks/crypto/openssl.py

将第52行libcrypto.EVP_CIPHER_CTX_cleanup.argtypes = (c_void_p,) 改为libcrypto.EVP_CIPHER_CTX_reset.argtypes = (c_void_p,)

再次搜索cleanup(全文件共2处,此处位于111行),将libcrypto.EVP_CIPHER_CTX_cleanup(self._ctx) 改为libcrypto.EVP_CIPHER_CTX_reset(self._ctx)

@slow-is-fast
slow-is-fast / gist:736b14ba020f6600a8ecbca52d893e78
Created March 2, 2018 01:23
Mounty 导致NTFS盘 无法读取内容的处理方法
首先将硬盘从热插拔后不能被OS X读取的状态中拯救出来。将移动硬盘插到Windows系统的电脑上,然后 以管理员权限 运行命令行cmd。在弹出的小黑窗中输入
# 这里的D:需要按你移动硬盘的盘符号设置。然后,等命令运行完毕,硬盘就拯救回来了
chkdsk /f D:
# 这里的D:需要按你移动硬盘的盘符号设置。然后,等命令运行完毕,硬盘就拯救回来了
chkdsk/fD:
然后要做的是拯救那些被Mounty搞坏的文件们。将移动硬盘插入MacBook,暂时咱还是用Mounty将移动硬盘mount上,找到移动硬盘中那些文件的路径。这里提供一个小命令,OS X默认是不会在Finder窗口上沿跟Windows一样显示文件夹的完整路径的,将这个路径调出来的命令是,在OS X的“终端”中输入
@slow-is-fast
slow-is-fast / jsonMultiParse.md
Last active February 3, 2018 03:01
python parse multi json in one string
#-*- coding:utf-8 -*-

import json
import re


def jsonMultiParse(s):
    try:
 return json.loads(s)