Skip to content

Instantly share code, notes, and snippets.

View digitalextremist's full-sized avatar
🏴

//de digitalextremist

🏴
View GitHub Profile
module System
extend self
def cpu_count
return Java::Java.lang.Runtime.getRuntime.availableProcessors if defined? Java::Java
return File.read('/proc/cpuinfo').scan(/^processor\s*:/).size if File.exist? '/proc/cpuinfo'
require 'win32ole'
WIN32OLE.connect("winmgmts://").ExecQuery("select * from Win32_ComputerSystem").NumberOfProcessors
rescue LoadError
Integer `sysctl -n hw.ncpu 2>/dev/null` rescue 1
end
@sauloperez
sauloperez / signal_catching.rb
Last active November 11, 2020 11:25
How to catch SIGINT and SIGTERM signals in Ruby
# Signal catching
def shut_down
puts "\nShutting down gracefully..."
sleep 1
end
puts "I have PID #{Process.pid}"
# Trap ^C
Signal.trap("INT") {
@teocci
teocci / php-nginx-install.md
Last active January 24, 2022 09:49
Install PHP7.2 NGINX and PHP7.2-FPM on Ubuntu 18.04

Install NGINX

# Install software-properties-common package to give us add-apt-repository package
sudo apt-get install -y software-properties-common

# Install latest nginx version from community maintained ppa
sudo add-apt-repository ppa:nginx/stable

# Update packages after adding ppa
sudo apt-get update
@hellerbarde
hellerbarde / latency.markdown
Created May 31, 2012 13:16 — forked from jboner/latency.txt
Latency numbers every programmer should know

Latency numbers every programmer should know

L1 cache reference ......................... 0.5 ns
Branch mispredict ............................ 5 ns
L2 cache reference ........................... 7 ns
Mutex lock/unlock ........................... 25 ns
Main memory reference ...................... 100 ns             
Compress 1K bytes with Zippy ............. 3,000 ns  =   3 µs
Send 2K bytes over 1 Gbps network ....... 20,000 ns  =  20 µs
SSD random read ........................ 150,000 ns  = 150 µs

Read 1 MB sequentially from memory ..... 250,000 ns = 250 µs