Skip to content

Instantly share code, notes, and snippets.

View Mark24Code's full-sized avatar
💻
Exploring

Mark24 Mark24Code

💻
Exploring
View GitHub Profile
@Mark24Code
Mark24Code / middleware.rb
Created September 27, 2023 02:36 — forked from marcelobbfonseca/middleware.rb
Sinatra ruby JWT authentication middleware
# To connect this middleware.rb file to your sinatra app
# add 'use JWTAuthorization' as one of your first lines in
# your Application class.
# e.g.
# require 'middlewares.rb'
# class Application < Sinatra::Base
# use JWTAuthorization
# ...
# end
@Mark24Code
Mark24Code / process_rss.rb
Created January 21, 2022 07:22 — forked from pvdb/process_rss.rb
Get real memory (resident set) used by current Ruby process
#
# This first version should work on Mac OS X and Linux, but it spawns a process
#
# http://stackoverflow.com/questions/7220896/
# https://github.com/rdp/os/blob/master/lib/os.rb#L127
# http://www.ruby-doc.org/core-2.0/Process.html
#
# the real memory (resident set) size of the process (in 1_024 byte units).
def Process.rss() `ps -o rss= -p #{Process.pid}`.chomp.to_i ; end
@Mark24Code
Mark24Code / debug_httparty_request.rb
Created January 12, 2022 04:47 — forked from natritmeyer/debug_httparty_request.rb
How to debug HTTParty requests
class MyResource
include HTTParty
debug_output $stdout # <= will spit out all request details to the console
#...
end
@Mark24Code
Mark24Code / nginx.conf
Last active June 13, 2020 16:06
Nginx.conf注释版本
#总体上分成三个部分构成:基本配置、events配置、HTTP配置,以下为配置详情
#------------------------基本配置-------------------------
#user nobody; #配置worker进程运行用户
worker_processes 4; #配置工作进程数目,根据硬件调整,通常等于CPU数量或者2倍于CPU数量
#error_log logs/error.log; #配置全局错误日志及类型,[debug | info | notice | warn | error | crit],默认是error
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid; #配置进程pid文件
@Mark24Code
Mark24Code / .irbrc
Created June 5, 2020 09:58
ruby irb自动补全配置
require 'bond'
Bond.start
# For users using a pure ruby readline
Bond.start :readline => :ruby
git log --numstat --pretty="%H" <HashStart>..<HashEnd> | awk 'NF==3 {plus+=$1; minus+=$2} END {printf("+%d,-%d\n",plus,minus)}'\n
@Mark24Code
Mark24Code / README.md
Created April 8, 2018 02:07 — forked from datagrok/README.md
Circular imports in Python 2 and Python 3: when are they fatal? When do they work?

When are Python circular imports fatal?

In your Python package, you have:

  • an __init__.py that designates this as a Python package
  • a module_a.py, containing a function action_a() that references an attribute (like a function or variable) in module_b.py, and
  • a module_b.py, containing a function action_b() that references an attribute (like a function or variable) in module_a.py.

This situation can introduce a circular import error: module_a attempts to import module_b, but can't, because module_b needs to import module_a, which is in the process of being interpreted.

But, sometimes Python is magic, and code that looks like it should cause this circular import error works just fine!

@Mark24Code
Mark24Code / unorderArr.js
Created January 10, 2018 09:11
乱序数组算法
function unorderArr(arr){
let carr = arr.concat();
carr.sort(function(x,y){
return 0.5-Math.random()
})
return carr
}
@Mark24Code
Mark24Code / base64toBob&AxiosUploadFile.js
Last active January 10, 2018 09:11
base64转文件,axios上传文件(适用于裁剪头像上传)
//base64转 bob文件
function dataURItoBlob(dataURI) {
// convert base64/URLEncoded data component to raw binary data held in a string
var byteString;
if (dataURI.split(',')[0].indexOf('base64') >= 0)
byteString = atob(dataURI.split(',')[1]);
else
byteString = unescape(dataURI.split(',')[1]);
// separate out the mime component
@Mark24Code
Mark24Code / mover.py
Created August 9, 2017 08:46
mover搬运工
# encoding: utf-8
"""
搬运工Mover
列表一一对应,搬运文件
Windows下要注意,硬盘符号要写成C:\\,Win下Unicode的问题
author: mark24
email: mark.zhangyoung@qq.com
date: 2017.08.09