Skip to content

Instantly share code, notes, and snippets.

@sohayb
sohayb / ArrayDeepCopy.swift
Last active October 13, 2023 07:58
Array deep copy in Swift
//Protocal that copyable class should conform
protocol Copying {
init(original: Self)
}
//Concrete class extension
extension Copying {
func copy() -> Self {
return Self.init(original: self)
}
@fliedonion
fliedonion / !GIST file list order - summary.md
Last active May 11, 2024 12:14
Understand GIST file list order.
Summary How to control (or Understand) your GIST page's files list order.
Notice not official documentation.
@mandiwise
mandiwise / Count lines in Git repo
Last active May 16, 2024 13:28
A command to calculate lines of code in all tracked files in a Git repo
// Reference: http://stackoverflow.com/questions/4822471/count-number-of-lines-in-a-git-repository
$ git ls-files | xargs wc -l
@ph3nx
ph3nx / timestamp.rb
Created January 16, 2014 08:36
Handy method to get the current unix time stamp in Ruby. Unix time, or POSIX time, is a system for describing instants in time, defined as the number of seconds that have elapsed since 00:00:00 Coordinated Universal Time (UTC), Thursday, 1 January 1970.
def timestamp
Time.now.to_i
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") {