Skip to content

Instantly share code, notes, and snippets.

View vimfun's full-sized avatar
🧘

⸮o-o ? 林 vimfun

🧘
  • Beijing, China
View GitHub Profile
@vimfun
vimfun / generate-rand-str.clj
Last active October 24, 2021 09:53
generate random string for vcode (digits)
(defn generate-rand-str
([] (generate-rand-str 4))
([n]
(apply str
(map
(fn [_] (rand-int 10))
(range n)))))
@vimfun
vimfun / retry.py
Last active February 28, 2019 09:47
Python `retry` function (recursion version)
# Version 1.0.1
def retry(times=5, interval=15, max_interval=600):
def _iter(n, fn, *args, **kwargs):
try:
res = fn(*args, **kwargs)
return res
@vimfun
vimfun / range_of_datetime.md
Last active July 13, 2017 09:27
range of datetime (python)
from datetime import datetime, timedelta


def range_of_datetime(interval: timedelta, size:(int, None)=None, start:(datetime, None)=None, end:(datetime, None)=None):
    if start is None and end is None and size is None:
        raise Exception('Supply 3 arguments at least')
    zero_timedelta = timedelta()
    if start is not None and end is not None:
 if (start < end and interval > zero_timedelta) or (start > end and interval < zero_timedelta):
@vimfun
vimfun / install_ag_on_centos.md
Last active July 12, 2017 02:53 — forked from jsivakumaran/installSilverSearcherOnCentoOS
Installing ag on CentOS.md
# 0. Prerequistes
sudo yum install pcre-devel xz-devel zlib-devel -y

# 1. Get the code
cd /usr/local/src
sudo git clone https://github.com/ggreer/the_silver_searcher.git

# 2. Build and install it
cd the_silver_searcher && sudo ./build.sh && sudo make install
import sys

if sys.version_info[0] == 3:

    is_prime = lambda n: not any(filter(lambda x: n % x == 0, range(2, n)))
elif sys.version_info[0] == 2:
    import itertools

 is_prime = lambda n: not any(itertools.ifilter(lambda x: n % x == 0, range(2, n))
@vimfun
vimfun / our mysql is hacked.md
Last active July 12, 2017 02:54
iptables for mysql 'max_allowed_packet' 1024 ------ (2006, 'MySQL server has gone away')
> mysql> show global variables like 'max_allowed_packet';
>
> +--------------------+----------+
> 
| Variable_name      | Value    |
>
+--------------------+----------+
>
| max_allowed_packet | 16777216 |