Skip to content

Instantly share code, notes, and snippets.

View rtacconi's full-sized avatar

Riccardo Tacconi rtacconi

View GitHub Profile
@rtacconi
rtacconi / rust_fibonacci.rs
Last active July 14, 2017 17:48
Calculation of fibonacci number with Rust
fn fib(x: u64) -> u64 {
if x > 1 { fib(x - 1) + fib(x - 2) } else { x }
}
fn main() {
println!("Result {}", fib(10)); // -> 55
}
{
// Configure the daemon below:
"options": {
"host_identifier": "scw-xxxxxxx",
"config_plugin": "filesystem",
// Select the osquery logging plugin.
"logger_plugin": "aws_kinesis",
"enable_monitor": "true",
// Splay the scheduled interval for queries.
require "openssl"
class Chef
class Recipe
def self.certificate_expired?(path)
OpenSSL::X509::Certificate.new(File.open(path, "rb").read).not_after <= Time.now
end
end
end
REPORT=/tmp/ssh_acl.txt
for user in $(knife data bag show users)
do
knife data bag show users $user | grep -v ssh_keys | grep -v ssh-rsa | grep -v htpasswd | grep -v shell >> $REPORT
echo "---------------------" >> $REPORT
done
@rtacconi
rtacconi / gist:2d90655ad55324d697ab9f1907b70c5b
Last active February 7, 2017 17:14
AWS CLI list instances name with public IP
aws ec2 describe-instances \
--query 'Reservations[*].Instances[*].[Tags[?Key==`Name`].Value|[0],PublicIpAddress]' \
--output table --region us-east-1
@rtacconi
rtacconi / run_chef_client_kitchen.sh
Last active February 6, 2017 19:20
Run chef-client in Test Kitchen. It installs Chef Zero and it uploads everything to it.
#!/bin/bash
cd /tmp/kitchen
/opt/chef/embedded/bin/gem install chef-zero
/opt/chef/embedded/bin/chef-zero -d
knife upload / -c client.rb
chef-client -j dna.json -c client.rb
@rtacconi
rtacconi / rsyslog.conf
Created January 31, 2017 22:48
rsyslog.conf configured to send logs to a local ping, change the IP with the IP of your machine
# rsyslog configuration file
# For more information see /usr/share/doc/rsyslog-*/rsyslog_conf.html
# If you experience problems, see http://www.rsyslog.com/doc/troubleshoot.html
#### MODULES ####
# The imjournal module bellow is now used as a message source instead of imuxsock.
$ModLoad imuxsock # provides support for local system logging (e.g. via logger command)
$ModLoad imjournal # provides access to the systemd journal
@rtacconi
rtacconi / Ruby 2.0 on CentOS 6
Created September 16, 2015 11:17
Compile Ruby 2.0 p647 on CentOS 6
#!/usr/bin/env bash
# repository
cd /tmp
wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
rpm -Uvh epel-release-6-8.noarch.rpm
# system update
yum -y update
yum -y groupinstall "Development Tools"
yum -y install libxslt-devel libyaml-devel libxml2-devel gdbm-devel libffi-devel zlib-devel openssl-devel libyaml-devel readline-devel curl-devel openssl-devel pcre-devel git memcached-devel valgrind-devel mysql-devel ImageMagick-devel ImageMagick
@rtacconi
rtacconi / binary_search.rb
Last active August 7, 2016 19:57
Binary search
def binary_search(list, item)
low = 0
high = list.size - 1
return nil if list.last < item # item not in array
while low < high do
mid = (low + high) / 2
guess = list[mid]
@rtacconi
rtacconi / flatten.rb
Created August 7, 2016 18:36
Flatten an array without using the Ruby library
def flatten(in_array, out_array = [])
in_array.each do |a|
if a.class == Array
flatten(a, out_array)
else
out_array << a
end
end
out_array