Skip to content

Instantly share code, notes, and snippets.

@tlikai
tlikai / attestation.txt
Created April 8, 2022 07:55
Attestation
I contributed to the Semaphore Trusted Setup Multi-Party Ceremony.
The following are my contribution signatures:
Circuit: semaphore16
Contributor # 239
Hash: ba38919e cd347495 caa47650 8bef4f56
6f479a56 48413429 cded54ba 96345e16
114aa434 741998d6 00fbae5c a70e5abd
1f5638ec 0de88ac0 e7fcf18f 9341e21c
@tlikai
tlikai / aes-128-cbc.php
Last active November 11, 2021 15:29 — forked from yuriy-yarvinen/encrypt_decrypt.php
php aes-128-cbc
<?php
define('ENCRYPTION_KEY', 'EncryptDecryptPHP201908Y');
// Encrypt
function encrypt($plaintext) {
$ivlen = openssl_cipher_iv_length($cipher = "AES-128-CBC");
$iv = openssl_random_pseudo_bytes($ivlen);
$ciphertext_raw = openssl_encrypt($plaintext, $cipher, ENCRYPTION_KEY, $options = OPENSSL_RAW_DATA, $iv);
$hmac = hash_hmac('sha256', $ciphertext_raw, ENCRYPTION_KEY, $as_binary = true);
@tlikai
tlikai / elasticsearch.rake
Created March 31, 2017 16:07
Rebuild elasticsearch index with zero downtime
require 'elasticsearch/rails/tasks/import'
namespace :elasticsearch do
desc 'Rebuild index with zerodown time'
task rebuild: :environment do
size = (ENV['size'].presence || 1000).to_i
model = ENV['model'].to_s.classify.constantize
delete_old_index = ENV['delete'].present?
es = model.__elasticsearch__
@tlikai
tlikai / .proxyrc
Last active December 26, 2016 09:51
Proxychain - automatically switch proxy between command
function proxy() {
proxy_on
$@
proxy_off
}
function proxy_on() {
export all_proxy="http://127.0.0.1:1087"
}
@tlikai
tlikai / faker.rb
Created September 30, 2016 02:17
Ruby Faker::PhoneNumber 生成国内手机号
module Faker
class PhoneNumber < Base
class << self
def cell_phone
operators = [
134, 135, 136, 137, 138, 139, 147, 150, 151, 152, 157, 158, 159, 182, 187, 188, # china mobile
130, 131, 132, 145, 155, 156, 185, 186, 145, # china unicom
133, 153, 180, 181, 189 # china telecom
]
suffix = Random.rand(10000000...99999999)
@tlikai
tlikai / export_mysql_table_schema_to_markdown_table.php
Last active October 1, 2020 01:07
export mysql table schema to markdown table
#!/usr/bin/env php
<?php
if (count($argv) == 1) {
throw new InvalidArgumentException('Missing tables');
}
$tables = array_slice($argv, 1);
$db = new PDO('mysql:dbname=uniqueway_development;host=127.0.0.1;charset=utf8mb4', 'root', '');
@tlikai
tlikai / delete_merged_branch.sh
Last active December 16, 2019 05:12
Delete merged branch
git branch --merged=develop | grep -v 'master' | grep -v 'develop' | tr -d '^ ' | xargs git branch -d
@tlikai
tlikai / regex
Created April 21, 2015 14:52
China cellphone number regex
/^(170[059]\d{7}|(14[57]|15[^4,\D]|17[678])\d{8}|1[38]\d{9})$/
@tlikai
tlikai / sources.list.trusty
Last active August 29, 2015 14:12
trusty sources list
deb http://ftp.sjtu.edu.cn/ubuntu/ trusty main restricted universe multiverse
deb http://ftp.sjtu.edu.cn/ubuntu/ trusty-updates main restricted universe multiverse
deb http://ftp.sjtu.edu.cn/ubuntu/ trusty-security main restricted universe multiverse
deb-src http://ftp.sjtu.edu.cn/ubuntu/ trusty main restricted universe multiverse
deb-src http://ftp.sjtu.edu.cn/ubuntu/ trusty-updates main restricted universe multiverse
deb-src http://ftp.sjtu.edu.cn/ubuntu/ trusty-security main restricted universe multiverse
@tlikai
tlikai / open-dl.php
Created October 9, 2013 08:23
网易公开课批量下载
#!/usr/bin/env php
<?php
require 'simple_html_dom.php'; // http://sourceforge.net/projects/simplehtmldom/
if (empty($argv[1])) {
echo 'Give me download url please.', PHP_EOL;
exit;
}