Skip to content

Instantly share code, notes, and snippets.

View ladyrick's full-sized avatar
🎯
Focusing

LadyRick ladyrick

🎯
Focusing
View GitHub Profile
@ladyrick
ladyrick / patch-django-shell.py
Last active November 29, 2022 04:15
enable `django manage.py shell` run a script
def patch_django_shell():
import os
import runpy
import sys
from functools import wraps
from unittest.mock import patch
from django.core.management.commands.shell import Command
original_handle = Command.handle
@ladyrick
ladyrick / iterm2_profiles.json
Created April 24, 2020 11:27
iterm2 profiles
{
"Profiles": [
{
"Thin Strokes": 0,
"Working Directory": "\/",
"Prompt Before Closing 2": false,
"Selected Text Color": {
"Green Component": 0,
"Blue Component": 0,
"Red Component": 0
from google.protobuf import text_format
def ParseFromBinary(bytestr, message):
message.ParseFromString(bytestr)
def ParseFromText(string, message):
text_format.Merge(string, message)
def SerializeToBinary(message):
return message.SerializeToString()
[user]
name = ladyrick
email = ladyrick@qq.com
[alias]
lg = log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
[gui]
encoding = utf-8
[i18n]
commitencoding = utf-8
logoutputencoding = utf-8
@ladyrick
ladyrick / pymsgbox
Last active November 22, 2018 02:40
python的message box
class PyMsgBox():
def __init__(self):
from tkinter import Tk, messagebox
self.msgbox = messagebox
self.root = Tk()
self.root.wm_attributes('-topmost', 1)
self.root.withdraw()
def info(self, msg):
self.msgbox.showinfo("来自ladyrick的提示", msg)
@ladyrick
ladyrick / print_vtable.cpp
Created August 28, 2018 03:35
print the virtual function table of an object.
#include <cstring>
#include <iomanip>
#include <iostream>
using namespace std;
class Base1 {
public:
virtual void f() { cout << "Base1::f" << endl; }
virtual void g() { cout << "Base1::g" << endl; }
virtual void h() { cout << "Base1::h" << endl; }
@ladyrick
ladyrick / str_split.cpp
Created August 12, 2018 08:11
c++ string split()
vector<string> split(const string &str, const string &c) {
int start = 0;
int npos = str.find(c, start);
vector<string> result;
while (start < str.length() && npos != str.npos) {
result.push_back(str.substr(start, npos - start));
start = npos + c.length();
npos = str.find(c, start);
}
result.push_back(str.substr(start, str.length() - start));
@ladyrick
ladyrick / NumberOf1Between1andN
Last active August 11, 2018 07:54
求1到n的数字中,1的个数
int NumberOf1Between1AndN_Solution(int n)
{
int ones = 0;
for (long long m = 1; m <= n; m *= 10)
ones += (n / m + 8) / 10 * m + (n / m % 10 == 1) * (n % m + 1);
return ones;
}
@ladyrick
ladyrick / .bashrc
Last active August 4, 2018 16:37
my .bashrc
export PS1='\[\033[35;1m\]\w\[\033[36;1m\] > \[\033[00m\]'
alias ls="ls --color=auto"
alias ll="ls -alhF"
alias la="ls -a"
alias l="ll"
alias ..="cd .."
@ladyrick
ladyrick / cast2bits.cpp
Last active July 28, 2019 08:18
Given a variable or an object, then print the memory state. The MSB is on the left and the LSB is on the right.
#include <iostream>
#include <string>
#include <sstream>
#include <bitset>
#include <typeinfo>
using namespace std;
class cast2bits {
private: