Skip to content

Instantly share code, notes, and snippets.

@Clarence-pan
Clarence-pan / go-routine-id.go
Last active September 13, 2017 06:26
获取go-routine的ID的方法
func getGoRoutineId() uint64 {
b := make([]byte, 32)
b = b[:runtime.Stack(b, false)]
b = bytes.TrimPrefix(b, []byte("goroutine "))
b = b[:bytes.IndexByte(b, ' ')]
id, err := strconv.ParseUint(string(b), 10, 64)
if err != nil {
log.Panicf("Cannot parse goroutine id from %v: %v", b, err)
}
@Clarence-pan
Clarence-pan / test.html
Last active August 31, 2017 03:13
HTML中嵌入svg图片的N种方式
<!doctype html>
<html>
<head><title>嵌入SVG图片的N种方式</title></head>
<body>
<h3>0. 使用`svg`标签</h3>
<svg version="1.1"
preserveAspectRatio="xMinYMin meet"
viewBox="0 0 660 342"
width="660" height="342"
xmlns="http://www.w3.org/2000/svg"
@Clarence-pan
Clarence-pan / zhihu-fix.css
Last active August 29, 2017 08:09
Fix the style of zhihu in my opinion
.AppHeader-inner,
.Footer,
.Card.AppBanner,
.Card[data-za-module=RelatedLives]{
display: none !important;
}
.Card{
position: relative;
z-index: 1;
}
@Clarence-pan
Clarence-pan / test-GetFullPathName.c
Created August 25, 2017 01:16
Test GetFullPathName
#include "windows.h"
#include <tchar.h>
#include <stdio.h>
#define BUFSIZE 4096
void _tmain(int argc, TCHAR *argv[])
{
DWORD retval=0;
BOOL success;
@Clarence-pan
Clarence-pan / html_entity_encode_unicode.php
Created August 14, 2017 05:25
将中文(unicode)编码成HTML实体编码,而保留ANSI字符
<?php
function html_entity_encode_unicode($str) {
$str = mb_convert_encoding($str , 'UTF-32', 'UTF-8');
$t = unpack("N*", $str);
$t = array_map(function($n) {
return $n < 128 ? chr($n) : "&#$n;";
}, $t);
@Clarence-pan
Clarence-pan / 0_product_discount_on_top_left_corner.html
Last active August 14, 2017 02:01
左上角的促销折扣信息
<!doctype html>
<html>
<head>
<title>Product Discount On Top Left Corner</title>
<style>
.product{
border: 1px solid black;
width: 400px;
height: 300px;
position: relative;
@Clarence-pan
Clarence-pan / validation.php
Created July 17, 2017 02:22
Laravel validation 中文翻译(更新至Laravel 5.4)
<?php
return [
/*
|--------------------------------------------------------------------------
| Validation Language Lines
|--------------------------------------------------------------------------
|
| The following language lines contain the default error messages used by
<?php
$testRounds = 100;
$testTimes = 1000000;
$times = [];
$data = 'abcdefgh';
for ($i = 0; $i < $testRounds; $i++){
$begin = microtime(true);
@Clarence-pan
Clarence-pan / most-brief-excel-xml-file.xml
Created June 1, 2017 10:24
最简洁的xml格式的表格文件。可以用excel2003以上版本打开。
<?xml version="1.0"?>
<?mso-application progid="Excel.Sheet"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet">
<Worksheet ss:Name="tt">
<Table>
<Row>
<Cell><Data ss:Type="String">Hello</Data></Cell>
</Row>
<Row>
@Clarence-pan
Clarence-pan / 0_test-bcrypt-speed.php
Created May 31, 2017 09:13
测试bcrypt的速度
<?php
echo sprintf("%10s %10s\n", 'cost', 'time');
for ($cost = 8; $cost < 20; $cost++) {
$begin = microtime(true);
password_hash('test1234', PASSWORD_BCRYPT, ['cost' => $cost]);
$delta = microtime(true) - $begin;