Skip to content

Instantly share code, notes, and snippets.

View rtacconi's full-sized avatar

Riccardo Tacconi rtacconi

View GitHub Profile
@rtacconi
rtacconi / build.gradle
Created April 5, 2016 10:48
gradle aws lambda jruby build
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
buildscript {
repositories { jcenter() }
dependencies {
/* check jruby-gradle.org for the latest release */
classpath "com.github.jruby-gradle:jruby-gradle-jar-plugin:1.0.1"
apt-get -y update
apt-get -y install build-essential zlib1g-dev libssl-dev libreadline6-dev libyaml-dev
cd /tmp
wget http://ftp.ruby-lang.org/pub/ruby/2.3/ruby-2.3.0.tar.gz
tar -xvzf ruby-2.3.0.tar.gz
cd ruby-2.3.0/
./configure --prefix=/usr/local
make
make install
wget https://opscode-omnibus-packages.s3.amazonaws.com/el/7/x86_64/chefdk-0.10.0-1.el7.x86_64.rpm
rpm -i chefdk-0.10.0-1.el7.x86_64.rpm
if [ ! -d /var/chef/cache/ ]; then mkdir -p /var/chef/cache/; fi
if [ ! -d /var/chef/cookbooks/ ]; then mkdir -p /var/chef/cookbooks/; fi
if [ ! -d /var/chef/checksums/ ]; then mkdir -p /var/chef/checksums/; fi
if [ ! -d /etc/chef ]; then mkdir -p /etc/chef; fi
if [ ! -d /var/chef/backup ]; then mkdir -p /var/chef/backup; fi
if [ ! -d /var/chef/environments ]; then mkdir -p /var/chef/environments; fi
if [ ! -f /var/chef/environments/production.rb ]; then mkdir -p /var/chef/environments/production.rb; fi
cat << EOF > /etc/chef/solo.rb
@rtacconi
rtacconi / install_jenkins.sh
Last active April 5, 2019 11:52
Install Jenkins Centos 7
#!/bin/sh
yum install -y java
wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat/jenkins.repo
rpm --import https://jenkins-ci.org/redhat/jenkins-ci.org.key
yum install -y jenkins
yum install -y git
service jenkins start/stop/restart
chkconfig jenkins on
def next_id(arr)
return 0 if arr && arr.size == 0
return 1 if arr.inject(&:+) == 0
arr = arr.uniq.sort
arr.each_with_index do |n, i|
return i unless n == i
end
arr.last + 1
@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
# https://codility.com/demo/results/demoJ2Q7MX-R8M/
# 100% performance and correctness
def solution(a)
return 1 unless a && a.size > 0
length = a.length + 1
sum1 = 0
sum2 = 0
sum1 = a.inject(&:+)
Prelude> let factorial n = product [1..n]
Prelude> factorial 2
2
Prelude> factorial 3
6
Prelude> factorial 4
24
# using first order functions
def factorial(n)
(1..n).inject(:*) || 1
end
factorial(4)
=> 24
@rtacconi
rtacconi / gist:e463fbc9afa7f0665cf9
Last active August 29, 2015 14:24
TapeEquilibrium
Initial solution, test passing, 0% scores:
(1..a.size-2).each {|i| p (a.slice(i,a.size).inject(:+) - a.slice(0, i).inject(:+)) }.min
I found this on internet, 100% scores, very long:
puts "tape_equilibrium: "
return 0 if a.empty?
# Example data: N=5, P(1-4), A[3,1,2,4,3]
# P1: