Skip to content

Instantly share code, notes, and snippets.

View yinian1992's full-sized avatar
🌌
Building dyson sphere

亦念 yinian1992

🌌
Building dyson sphere
View GitHub Profile
@yinian1992
yinian1992 / wx.py
Created May 4, 2020 06:46
Weixin Bot Test
import werobot
import random
robot = werobot.WeRoBot(token='zzz',
enable_session=True)
@robot.handler
def echo(message, session):
if message.content == '猜数字':
digits = [str(i) for i in range(10)]
@yinian1992
yinian1992 / csharp-offline.py
Created March 6, 2020 07:51
VSCode C# extension offline helper
#!/usr/bin/env python3
#
# VSCode C# extension offline helper
# Version 202003061443
#
# The MIT License (MIT)
#
# Copyright © 2020 yinian@jinkan.org
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
@yinian1992
yinian1992 / wtf.py
Last active November 19, 2015 14:25
The most god-stick-like code written in Python this year.
# God-stick-like
from itertools import chain, repeat
from functools import partial, reduce
this_is_a_list = [1, 2, 3, 4, 5]
what_you_want = reduce(chain, map(partial(repeat, times=2), this_is_a_list))
# Normal
this_is_a_list = [1, 2, 3, 4, 5]
what_you_want = [val for val in this_is_a_list for i in range(2)]
@yinian1992
yinian1992 / game.py
Created June 7, 2015 07:51
Huawei Texas Hold'em Poker Player
#!/usr/bin/python
import errno
import socket
import sys
import time
PLAYER_NAMES = (
'Alice',
'Bob',
@yinian1992
yinian1992 / epoll_tcprp.py
Last active August 29, 2015 14:03
tentative tcp reserve proxy
import socket
import select
BACKEND_HOST = 'example'
BACKEND_PORT = 1234
BUF_SIZE = 1024
LISTEN_PORT = 1234
proxy_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
proxy_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
@yinian1992
yinian1992 / darth.vbs
Last active August 29, 2015 13:57
Something Luke Filewalker can save.
'Darth virus is licensed under GPL3.
'https://www.gnu.org/copyleft/gpl.html
'
'Copyright (c) 2014 yinian1992.
Dim myVirus
myVirus = MsgBox ("No, I am your father.", 16, "Darth Virus")
@yinian1992
yinian1992 / truncate.py
Last active December 25, 2015 13:59
Proper truncate template filter considering char width
import unicodedata
from django import template
register = template.Library()
@register.filter
def truncate(text, max_length):
max_length = int(max_length) - 3
@yinian1992
yinian1992 / base56.py
Last active December 21, 2015 16:28
Base56 Unique ID Generator
# Porting from http://blog.kevburnsjr.com/php-unique-hash
# and modified some codes to support variable length
# Min length of unique id
MIN_LENGTH = 2
# Unique ID contains some of these 56 chars
CHARSET = 'ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnpqrstuvwxyz23456789'
# Some primes greater than 56 ^ n / 1.61803398874989484
@yinian1992
yinian1992 / count_last_24.py
Last active January 20, 2021 13:22
SqlAlchemy Example / Count submits in each of the last 24 hours.
from datetime import datetime, timedelta
import sqlalchemy as sa
import sqlalchemy.orm as orm
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import scoped_session, sessionmaker
NOW = datetime.utcnow()
DBSession = scoped_session(sessionmaker())
Base = declarative_base()
@yinian1992
yinian1992 / count.php
Created October 2, 2012 16:05
A php line number counter just for pratice.
<?php
/**
* Code Calculator
*
* count line number of php project
* @author yinian1992
*
*/
// define('BASEPATH', 'absolute path of your php project');