Skip to content

Instantly share code, notes, and snippets.

View codcodog's full-sized avatar
🤷‍♂️
how to exit vim

h2O codcodog

🤷‍♂️
how to exit vim
  • ShenZhen, China
View GitHub Profile
@codcodog
codcodog / Makefile
Created January 29, 2019 03:07 — forked from isaacs/Makefile
# Hello, and welcome to makefile basics.
#
# You will learn why `make` is so great, and why, despite its "weird" syntax,
# it is actually a highly expressive, efficient, and powerful way to build
# programs.
#
# Once you're done here, go to
# http://www.gnu.org/software/make/manual/make.html
# to learn SOOOO much more.
@codcodog
codcodog / copyToClipboard.html
Last active March 20, 2019 07:16
浏览器复制文本
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<input id="el" type="text" value="Hello World." />
<button id="copy">复制</button>
</body>
@codcodog
codcodog / getParam.js
Last active March 20, 2019 08:57
获取 URL GET 参数
function getParam(paramName, defaultValue = '')
{
let url = location.search;
let params = new Object();
if (url.indexOf('?') != -1) {
url = url.slice(1);
strs = url.split('&');
strs.forEach(function (str) {
@codcodog
codcodog / ctags-for-php-include-trait.sh
Created April 19, 2019 01:48
PHP tags 包括 traits
ctags --languages=php --regex-php='/^[ \t]*trait[ \t]+([a-z0_9_]+)/\1/t,traits/i' -R .
@codcodog
codcodog / cli.go
Last active April 28, 2019 01:45
golang 命令行
package main
import (
"flag"
"fmt"
"os"
)
func main() {
var (
@codcodog
codcodog / lines.go
Created April 30, 2019 03:45
读取行
package main
import (
"bufio"
"fmt"
"os"
)
func main() {
scanner := bufio.NewScanner(os.Stdin)
@codcodog
codcodog / request.go
Created May 7, 2019 03:23
HTTP 请求示例
package main
import (
"fmt"
"io/ioutil"
"net/http"
)
func main() {
req, err := http.NewRequest("GET", "https://cn.bing.com", nil)
@codcodog
codcodog / distributed-lock.php
Last active August 7, 2019 03:26
Redis setnx 实现分布式锁
/**
* 当前 cron 触发的进程获取 redis 锁
*
* 主要是防止在跑 cron 时,上一个 cron 计算尚没完成,
* 从而导致,重复执行计算的情况.
*
* 例如:1 * * * * 的定时任务,一分钟内计算未完成,
* 又再次触发,则会出现重复计算的混乱情况.
*
@codcodog
codcodog / touchpad.sh
Last active November 8, 2019 07:17
Dell 13 touchpad enable & disable.
#!/bin/bash
#
# XPS13 touchpad enable/disable.
ID=$(xinput list | grep DLL.*Touchpad | awk '{print $6}' | awk -F'=' '{print $2}')
STATE=$(xinput list-props $ID | grep 'Device Enabled' | awk '{print $4}')
if [ $STATE -eq 1 ]; then
xinput disable $ID
else
@codcodog
codcodog / url_get_post.php
Created November 12, 2019 06:18
curl 实现的 get/post 请求样例
<?php
/**
* @Author Cryven
* @Date 2019-11-12 13:40:42
*/
function get($url, $params, $timeout = 3)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);