Skip to content

Instantly share code, notes, and snippets.

View quwubin's full-sized avatar

Wubin Qu quwubin

View GitHub Profile
@JosephPecoraro
JosephPecoraro / shell-execution.rb
Last active March 19, 2025 06:46
Shell Execution in Ruby
# Ways to execute a shell script in Ruby
# Example Script - Joseph Pecoraro
cmd = "echo 'hi'" # Sample string that can be used
# 1. Kernel#` - commonly called backticks - `cmd`
# This is like many other languages, including bash, PHP, and Perl
# Synchronous (blocking)
# Returns the output of the shell command
# Docs: http://ruby-doc.org/core/classes/Kernel.html#M001111
@quwubin
quwubin / remove_blank_line.rb
Created June 8, 2012 01:31
Ruby: Remove blank lines and leading ^M characters
#!/usr/bin/env ruby
#
# Wubin Qu <[email protected]>
#
if ARGV.size != 1
$stderr.puts "
Remove blank lines and leading ^M characters
Usage:
@quwubin
quwubin / get_cpu_usage
Created March 25, 2014 08:17
Get CPU usage
#!/usr/bin/bash
# Give all CPUs usage percent
ps fuxw | awk '{ if ($3 ~ /^[0-9]/) {SUM +=$3}} END {print SUM"%"}'
@mattes
mattes / check.go
Last active April 22, 2025 19:16
Check if file or directory exists in Golang
if _, err := os.Stat("/path/to/whatever"); os.IsNotExist(err) {
// path/to/whatever does not exist
}
if _, err := os.Stat("/path/to/whatever"); !os.IsNotExist(err) {
// path/to/whatever exists
}