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 / 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 / eleme.py
Created May 8, 2017 00:42 — forked from SaulLawliet/eleme.py
查询饿了么品牌馆中有哪些是 <真·五折>
# coding: utf-8
import json
import re
import requests
# 替换成你自己的经纬度数据
# 查询方式 打开饿了么官网 -> 开发者模式 -> 输入送餐地址 -> 观察请求 -> 找到经纬度数据
latitude = 31.23978
longitude = 121.49968
@Mark24Code
Mark24Code / app.py
Created February 16, 2017 12:16 — forked from zaccrites/app.py
Flask Application Factory
import jinja2
from flask import Flask, render_template, request, redirect, url_for
from flask.ext.sqlalchemy import SQLAlchemy
from . import formatting
from .config import get_config
db = SQLAlchemy()
@Mark24Code
Mark24Code / cheatsheet.py
Created August 27, 2016 04:27 — forked from fuyufjh/cheatsheet.py
My Python Cheatsheet
Python Cheatsheet
=================
################################ Input & Output ###############################
name = input('please enter your name: ')
print('hello,', name)
ageStr = input('please enter your age: ')
age = int(ageStr)
@Mark24Code
Mark24Code / zepto.smoothScroll.js
Created August 18, 2016 03:14 — forked from benjamincharity/zepto.smoothScroll.js
Smooth scrolling with Zepto.js
function smoothScroll(el, to, duration) {
if (duration < 0) {
return;
}
var difference = to - $(window).scrollTop();
var perTick = difference / duration * 10;
this.scrollToTimerCache = setTimeout(function() {
if (!isNaN(parseInt(perTick, 10))) {
window.scrollTo(0, $(window).scrollTop() + perTick);
smoothScroll(el, to, duration - 10);

Specs

  • Mini PC + Arduino = pcDuino
  • OS: Lubuntu 和 Android 4.0 ICS
  • 本地输出: HDMI
  • 硬件接口与Arduino兼容

Details

  • 支持通过任何I/O接口来连接Arduino的盾板(shield), 允许使用在Arduino中一样的代码.
  • 出厂默认系统安装Ubuntu在NAND flash上. Ubuntu可以从NAND flash或者一个可以启动的microSD卡上启动.
@Mark24Code
Mark24Code / tree.md
Created May 11, 2016 08:37 — forked from upsuper/tree.md
一行 Python 实现树

一行 Python 实现树

使用 Python 内置的 defaultdict,我们可以很容易的定义一个树形数据结构:

def tree(): return defaultdict(tree)

就是这样!