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: ...
@Congee
Congee / gets()
Created March 14, 2014 06:24
Dangerous function gets() in C89, c99's <stdio.h>
#include <stdio.h>
int main(void) {
char a[] = "ABCD";
char b[] = "BCDE";
char c[] = "CDEF";
puts(a);
puts(b);
puts(c);
hello world
@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 / 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 / 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);