Skip to content

Instantly share code, notes, and snippets.

@genewoo
genewoo / decode_transaction.py
Created October 27, 2022 08:04 — forked from yifeihuang/decode_transaction.py
Decoding an Ethereum smart contract transaction
import traceback
import sys
from functools import lru_cache
from web3 import Web3
from web3.auto import w3
from web3.contract import Contract
from web3._utils.events import get_event_data
from web3._utils.abi import exclude_indexed_event_inputs, get_abi_input_names, get_indexed_event_inputs, normalize_event_input_types
from web3.exceptions import MismatchedABI, LogTopicError
from web3.types import ABIEvent
@genewoo
genewoo / dump_k8s.sh
Created April 26, 2021 15:11
Dump Kubernetes into Export Folder
#!/bin/bash -e
if [ -z "$NAMESPACES" ]; then
NAMESPACES=$(kubectl get ns -o jsonpath={.items[*].metadata.name})
fi
RESOURCETYPES="${RESOURCETYPES:-"ingress deployment configmap svc rc ds networkpolicy statefulset cronjob pvc"}"
GLOBALRESOURCES="${GLOBALRESOURCES:-"namespace storageclass clusterrole clusterrolebinding customresourcedefinition"}"
@genewoo
genewoo / accept_xcode_license.sh
Created September 16, 2016 18:27 — forked from ryanmaclean/accept_xcode_license.sh
Accept Xcode License on the Command Line
# Run using "sudo accept_xcode_license.sh"
#
# Solving the OSX Yosemite Xcode Command Line Tools Licensing problem
# for multiple updates in order to script post-install tasks.
# Typical error reads after running "xcode-select --install" when setting up
# Homebrew is: "Agreeing to the Xcode/iOS license requires admin priviledges,
# please re-run as root via sudo"
#
# CREDIT:
# Based on a tip found at http://krypted.com/mac-os-x/licensing-the-xcode-command-line-tools/
@genewoo
genewoo / BSTree.rb
Last active January 4, 2016 00:39
BST Implement in Ruby
class BSTree
attr_accessor :left, :right, :parent, :value
def initialize(value, parent = nil)
@value = value
@parent = parent
end
def self.build_by_array(array, parent = nil)
return nil unless array
@genewoo
genewoo / api_profiler.rb
Created September 10, 2013 05:21
A simple rack to log api performance.
class APIProfiler
def initialize(app, config = {})
@app = app
# default print out log to STDOUT, otherwise you can inject rails logger
@config = config
@config[:logger] = Logger.new(STDOUT) unless config[:logger]
@config[:log_level] = :info unless config[:logger_level]
@config[:filter] = lambda { false } unless config[:filter] #turn off by default
end
=begin
@genewoo
genewoo / watchdo.sh
Created August 23, 2013 16:27
Watch File or Files changed in a folder to run a command
#!/bin/bash
# watchdo "rake" .rb
command="$1"
shift
fileSpec="$@"
sentinel=/tmp/t.$$
touch -t197001010000 $sentinel
@genewoo
genewoo / Gitlab Public Access
Last active December 16, 2015 22:29
Enable user to access public project raw files and project without be a member of that project
commit 458580f297fbda26dc4b0f49cf18b231d1010597
Author: Gene Wu <genewoo_AT_gmail.com>
Date: Sun Apr 28 02:03:42 2013 -0700
Enable user to access public project
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 32b1246..89ab816 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@genewoo
genewoo / gitlab_ldap.sh
Created April 28, 2013 07:19
Login LDAP Authentication GitLab instance by CLI and Fetch RAW File by curl. Since LDAP authentication will create the account for you, so it's very useful to fetch file from GitLab.
#!/bin/sh
BASEURL=http://git
USERNAME=DOMAIN_USER
USERPASS=DOMAIN_PASSWORD
RAW_FILE=RAW_FILE_URI
# login
curl -s -c cookies.txt -d "username=$USERNAME&password=$USERPASS" $BASEURL/users/auth/ldap/callback -o /dev/null
curl -s -c cookies.txt -b cookies.txt $BASEURL$RAW_FILE
@genewoo
genewoo / export_user_email.rb
Created April 2, 2013 08:42
Send email to all GitLab User, output will be a list user email address. You can put in your mail client and sent to all of your gitlab users
require 'net/http'
require 'json'
YOUR_API_KEY="INPUT YOUR ADMIN PRIVATE_KEY HERE"
YOUR_SERVER_HOST="YOUR HOST"
response = Net::HTTP.get_response(YOUR_SERVER_HOST, "/api/v3/users?private_token=${YOUR_API_KEY}")
users = JSON.parse response.body
puts users.map{|user| user["email"] + ";"}
@genewoo
genewoo / irb_verbosity_toggle.rb
Last active December 13, 2015 16:59
enable disable irb echo
# via http://tagaholic.me/2009/05/29/exploring-how-to-configure-irb.html#echo
def irb_verbosity_toggle
irb_context.echo ? irb_context.echo = false : irb_context.echo = true
end