Skip to content

Instantly share code, notes, and snippets.

View realeroberto's full-sized avatar
💭
Trust your journey.

Roberto Reale realeroberto

💭
Trust your journey.
View GitHub Profile
@realeroberto
realeroberto / self-evaluating.tcl
Created November 11, 2016 10:51
A self-evaluating Tcl proc.
proc x {} { set y "x" }
# let's try it...
#
# % x
# x
# % [x]
# x
# % [[x]]
# x
@realeroberto
realeroberto / up.sh
Last active November 16, 2016 10:43 — forked from ldante86/up.sh
Get uptime and second conversion
#!/bin/bash -
PROGRAM="${0##*/}"
IFS="."
for i in $(cat /proc/uptime)
do
UPTIME=$i
break
done
@realeroberto
realeroberto / github-backup.sh
Created April 20, 2017 15:38
Poor-man Bash hack to backup all of a user's GitHub repositories.
#!/bin/sh
username=
curl -s https://api.github.com/users/$username/repos | jq -r '.[].git_url' | while read git_url
do
repo_name=$(basename $git_url .git)
echo Backing up $repo_name
git clone -q $git_url 2> /dev/null || (
cd $repo_name
@realeroberto
realeroberto / perm2octal.sh
Created February 16, 2018 16:51
Convert a file mode string into the octal value
#!/bin/bash
# Convert a file mode string (e.g., -rw-rw-r--) into the octal value
function perm2octal()
{
local perm=${1:1} # remove first char (the file type)
res=$(echo "$perm" | sed 's/[^-]/1/g; s/-/0/g')
res=$(echo "ibase=2; obase=8; $res" | bc)
@realeroberto
realeroberto / make-tarball.sh
Created February 16, 2018 16:56
Create a tarball from inside a folder
#!/bin/sh
# create a tarball from inside a folder
dirname=$(cat PROJECT)-$(cat VERSION)
tarball=${dirname}.tar.gz
# avoid tar's error message ``file changed as we read it''
touch "$tarball"
tar cfz "$tarball" \
BEGIN
FOR cur_rec IN (SELECT object_name, object_type
FROM user_objects
WHERE object_type IN
('TABLE',
'VIEW',
'PACKAGE',
'PROCEDURE',
'FUNCTION',
'SEQUENCE',

Keybase proof

I hereby claim:

  • I am reale on github.
  • I am reale (https://keybase.io/reale) on keybase.
  • I have a public key ASC7prRw88qck0mao3uzp2TtsM1ZxhzzIMwGA62Z1s7llAo

To claim this, I am signing this object:

@realeroberto
realeroberto / e-power-series.tcl
Created September 15, 2018 22:26
Approximate the value of e using the power series expansion
#!/usr/bin/tclsh
#
# approximate e using the power series expansion
#
proc approx_e {{n 20}} {
set value 1
set factorial 1
set i 1
@realeroberto
realeroberto / chebyshev.tcl
Created September 15, 2018 22:27
Recursively calculate Chebyshev polynomials
#!/usr/bin/tclsh
# we need Tcl 8.5 for lrepeat to be defined
package require Tcl 8.5
#
# recursively calculate Chebyshev polynomials
#
# (see http://en.wikipedia.org/wiki/Chebyshev_polynomials)
#
@realeroberto
realeroberto / wallis.tcl
Created September 15, 2018 22:28
Approximate PI with the aid of Wallis' product
#!/usr/bin/tclsh
#
# approximate PI with the aid of Wallis' product
#
proc wallis {{n 1000000}} {
set value 1.0
set i 1