Skip to content

Instantly share code, notes, and snippets.

View lvguowei's full-sized avatar

Guowei Lv lvguowei

View GitHub Profile
@lvguowei
lvguowei / gist:c44effdb034abd99094e30d60d695289
Last active September 6, 2021 18:40
A little java, a few patterns
import java.util.*
import kotlin.math.sqrt
abstract class Point(val x: Int, val y: Int) {
abstract fun distanceToO(): Double
fun closerToO(p: Point) = distanceToO() < p.distanceToO()
fun minus(p: Point) = CartesianPt(x - p.x, y - p.y)
}
open class CartesianPt(x: Int, y: Int) : Point(x, y) {
@lvguowei
lvguowei / breakout-8.lua
Last active June 2, 2021 10:32
Breakout Pico-8
function _init()
cls()
ball_x = 10
ball_dx = 2
ball_y = 20
ball_dy = 2
ball_r = 2
pad_x = 52
pad_y = 120
@lvguowei
lvguowei / unix
Last active August 2, 2018 18:56
,_ ,_==▄▂
, ▂▃▄▄▅▅▅▂▅¾. / /
▄▆<´ "»▓▓▓%\ / / / /
,▅7" ´>▓▓▓% / / > / >/%
▐¶▓ ,»▓▓¾´ /> %/%// / /
▓▃▅▅
@lvguowei
lvguowei / circuitous.py
Last active June 26, 2019 22:01
Code of Raymond Hettinger's talk Python's Class Development Toolkit
'''
Circuitous, LLC -
An Advanced Circle Analytics Company
Summary: Toolset for New-Style Classes
1. Inherit from object.
2. Instance variables for information unique to an instance.
3. Class variables for data shared among all instances.
4. Regular methods need "self" to operate on instance data.
@lvguowei
lvguowei / Greeter.js
Created May 3, 2018 13:18
Javascript the Weird Part
(function (global, $) {
// Saves the user from typing the new keyword
var Greeter = function (firstname, lastname, language) {
return new Greeter.init(firstname, lastname, language);
};
var supportedLangs = ['en', 'es'];
var greetings = {
en: 'Hello',
@lvguowei
lvguowei / pre-commit
Created February 17, 2016 07:48 — forked from kaushikgopal/pre-commit
pre-commit git hook - no "hacking"
#!/usr/bin/env ruby
# This pre-commit hook will prevent any commit with the work "hacking"
# Put this file in your local repo, in the .git/hooks folder
# and make sure it is executable.
# The name of the file *must* be "pre-commit" for Git to pick it up.
def current_branch()
branches = `git branch --no-color`.split(/\n/)
current = branches.select{ |b| b =~ /\s*\*/ }.first
@lvguowei
lvguowei / gist:6752849
Created September 29, 2013 14:09
zshrc
fpath=(~/config/zsh/functions $fpath)
autoload -U compinit && compinit
## Command history configuration
HISTFILE=$HOME/.zsh_history
HISTSIZE=10000
SAVEHIST=10000
setopt append_history
setopt extended_history