Skip to content

Instantly share code, notes, and snippets.

View Congee's full-sized avatar
🤔
Focus

Changsheng Wu Congee

🤔
Focus
View GitHub Profile
@Congee
Congee / singleton.py
Created September 22, 2022 19:46
Python Singleton
from typing import Any, Callable, ParamSpec, Type, TypeVar
T = TypeVar('T')
P = ParamSpec('P')
def singleton(cls: Type[T]) -> Callable[P, T]:
"""
Example:
>>> @singleton
... class C: ...
hello world
@Congee
Congee / libcpuid.rb
Created May 28, 2016 11:42
Homebrew formula for libcpuid
class Libcpuid < Formula
desc "A small C library for x86 CPU detection and feature extraction "
homepage "https://github.com/anrieff/libcpuid"
head "https://github.com/anrieff/libcpuid.git"
depends_on "automake" => :build
depends_on "libtool" => :build
depends_on "autoconf" => :build
def install
@Congee
Congee / precmd.zsh
Created May 26, 2016 15:10
shortening pwd
autoload -U colors && colors
precmd() {
red_at="%{$fg[red]}@%{$reset_color%}"
red_dollar="%{$fg[red]%}$%{$reset_color%}"
typeset host_info
[[ -n $SSH_CONNECTION ]] && host_info="$USER${red_at}$HOST "
if [[ $USER == "CC" ]]; then
# number of chracters of the path of the prompt is less 30
# use '~' to represent $HOME as long as possible
@Congee
Congee / gdb.rb
Created January 13, 2016 01:29
For gdb to execute python3 script on OSX 10.10 or later
class UniversalBrewedPython < Requirement
satisfy { archs_for_command("python").universal? }
def message; <<-EOS.undent
A build of GDB using a brewed Python was requested, but Python is not
a universal build.
GDB requires Python to be built as a universal binary or it will fail
if attempting to debug a 32-bit binary on a 64-bit host.
EOS
@Congee
Congee / latexmk.rb
Last active August 29, 2015 14:23
latexmk on Mac OS X
class Latexmk < Formula
desc "La­texmk com­pletely au­to­mates the pro­cess of gen­er­at­ing a LaTeX doc­u­ment."
homepage "http://users.phys.psu.edu/~collins/software/latexmk-jcc/"
url "http://users.phys.psu.edu/%7Ecollins/software/latexmk-jcc/latexmk-443a.zip"
sha256 "e410d295c0a47327b953ece5b582c294359bdf89138ef990d5621b020ff2bbe5"
depends_on :tex
depends_on "ghostscript" => :optional
def install
@Congee
Congee / zlog.rb
Created March 31, 2015 03:44
zlog in Homebrew
class Zlog < Formula
homepage "https://hardysimpson.github.io/zlog/"
stable do
url "https://github.com/HardySimpson/zlog/archive/1.2.12.tar.gz"
sha1 "592be9688df1a713e190e2a9664157516cc6724f"
end
head do
url "https://github.com/HardySimpson/zlog.git"
@Congee
Congee / r2.rb
Created March 30, 2015 08:24
radare2 homebrew
require "formula"
class R2 < Formula
homepage "http://radare.org"
revision 2
head do
url "https://github.com/radare/radare2.git"
resource "bindings" do
diff -urNad nbtscan-1.5.1~/nbtscan.c nbtscan-1.5.1/nbtscan.c
--- nbtscan-1.5.1~/nbtscan.c 2003-06-06 14:14:00.000000000 +0200
+++ nbtscan-1.5.1/nbtscan.c 2008-05-09 14:38:59.000000000 +0200
@@ -111,7 +111,7 @@
for(i=0; i< hostinfo->header->number_of_names; i++) {
service = hostinfo->names[i].ascii_name[15];
strncpy(name, hostinfo->names[i].ascii_name, 15);
- name[16]=0;
+ name[15]=0;
printf("%-17s Service: 0x%02x Flags: 0x%04x\n", name, service, hostinfo->names[i].rr_flags);
diff -urNad nbtscan-1.5.1~/list.c nbtscan-1.5.1/list.c
--- nbtscan-1.5.1~/list.c 2008-05-08 14:10:54.000000000 +0200
+++ nbtscan-1.5.1/list.c 2008-05-08 14:12:29.000000000 +0200
@@ -49,7 +49,7 @@
if(item1==NULL) return 1;
if(item1->content == item2->content) return 0;
if(item1->content > item2->content) return 1;
- if(item1->content < item2->content) return -1;
+ return -1;
};