Skip to content

Instantly share code, notes, and snippets.

View apbarrero's full-sized avatar

Antonio Pérez Barrero apbarrero

View GitHub Profile
@apbarrero
apbarrero / process_state_codes.md
Created August 26, 2013 07:06
Meaning of process state codes (C column) on `ps` output

PROCESS STATE CODES

Here are the different values that the s, stat and state output specifiers (header "STAT" or "S") will display to describe the state of a process.

CODE Meaning
D Uninterruptible sleep (usually IO)
R Running or runnable (on run queue)
S Interruptible sleep (waiting for an event to complete)
T Stopped, either by a job control signal or because it is being traced.
W paging (not valid since the 2.6.xx kernel)
@apbarrero
apbarrero / ps_headers.md
Last active May 30, 2022 02:42
Legend for headers dumped by `ps -f` command
HEADER Meaning
UID effective user ID. (alias uid).
PID process ID number of the process.
PPID parent process ID.
C processor utilization. Currently, this is the integer value of the percent usage over the lifetime of the process. (see %cpu).
START/STIME starting time or date of the process. Only the year will be displayed if the process was not started the same year ps was invoked, or "mmmdd" if it was not started the same day, or "HH:MM" otherwise.
TTY controlling tty (terminal). (alias tt, tty).
STAT multi-character process state. See section PROCESS STATE CODES for the different values meaning. See also s and state if you just want the first character displayed.
TIME cumulative CPU time, "[dd-]hh:mm:ss" format. (alias cputime).
@apbarrero
apbarrero / git-completion.tcsh
Created December 5, 2012 08:59 — forked from kohenkatz/git-completion.tcsh
Source this file in your .tcshrc to get git command completion. Original source is http://gtirtha.wordpress.com/2010/05/14/git-autocomplete/ but WordPress's WSYIWYG editor messed it up and I cleaned it up.
# Source this script in tcsh to setup shell completions
# for git. Completions are activated by typing or Control-D
# in the shell after entering a partial command.
#
# Usage:
# source git-completion.tcsh (e.g. in ~/.cshrc)
#
# Supported completions:
# git (lists git commands)
# git help (lists git commands)
@apbarrero
apbarrero / lists1.erl
Created June 27, 2017 20:53
Defining functions over lists in practice
-module(lists1).
-export([product/1, maximum/1]).
product(Xs) -> product(Xs, 1).
product([], P) -> P;
product([X|Xs], P) -> product(Xs, X*P).
maximum([X|Xs]) -> maximum(Xs, X).
maximum([X|[]], M) -> max(X, M);
maximum([X|Xs], M) -> maximum(Xs, max(X, M)).
@apbarrero
apbarrero / tailrecurs.erl
Last active June 24, 2017 13:52
Tail recursion exercise
-module(tailrecurs).
-export([fib/1, perfect/1, testPerfect/0]).
fib(0) -> 0;
fib(1) -> 1;
fib(N) when N>1 ->
fib(N, 1, 0).
fib(2, Acc1, Acc2) -> Acc1 + Acc2;
fib(N, Acc1, Acc2) when N>2 -> fib(N-1, Acc1 + Acc2, Acc1).
-module(recurs).
-export([fib/1, pieces/1]).
fib(1) ->
[0];
fib(2) ->
[1,0];
fib(N) when N>2 ->
L = fib(N-1),
[X|Xs] = L,
@apbarrero
apbarrero / first.erl
Created June 21, 2017 20:17
First erlang program
-module(first).
-export([double/1,mult/2,area/3,sq/1,treble/1]).
mult(X,Y) ->
X*Y.
double(X) ->
mult(2,X).
area(A,B,C) ->
@apbarrero
apbarrero / flatten.rb
Created March 13, 2016 21:45
Array flatten
#!/usr/bin/env ruby
require 'test/unit'
def flatten(array)
f = []
if array.kind_of?(Array)
array.each{ |e| f.concat(e.kind_of?(Array) ? flatten(e) : [e]) }
else
f = [array]
NORMAL=$(tput sgr0)
GREEN=$(tput setaf 2; tput bold)
YELLOW=$(tput setaf 3)
RED=$(tput setaf 1)
function red() {
echo -e "$RED$*$NORMAL"
}
function green() {
[antonio@localhost] rsync_project: rsync -pthrvz --rsh='ssh -p 22 ' /var/folders/pq/xk94_z4910s0m0xyh5hyth_h0000gn/T/tmpJ0XIrt antonio@localhost:/var/folders/pq/xk94_z4910s0m0xyh5hyth_h0000gn/T/tmpLUX7m_
[localhost] local: rsync -pthrvz --rsh='ssh -p 22 ' /var/folders/pq/xk94_z4910s0m0xyh5hyth_h0000gn/T/tmpJ0XIrt antonio@localhost:/var/folders/pq/xk94_z4910s0m0xyh5hyth_h0000gn/T/tmpLUX7m_
Password:
building file list ... done
tmpJ0XIrt/
tmpJ0XIrt/tmp7BuTNr
sent 110 bytes received 48 bytes 45.14 bytes/sec
total size is 0 speedup is 0.00
.[antonio@localhost] rsync_project: rsync -pthrvz --rsh='ssh -p 22 ' antonio@localhost:/var/folders/pq/xk94_z4910s0m0xyh5hyth_h0000gn/T/tmp4KS64r /var/folders/pq/xk94_z4910s0m0xyh5hyth_h0000gn/T/tmpnYN8AK