Skip to content

Instantly share code, notes, and snippets.

@scudelletti
scudelletti / attr_accessor_for_class_variables.rb
Last active December 16, 2015 13:59
attr_accessor for Class Variables
module XptoModule
class << self
attr_accessor :classes_with_xpto_module
end
self.classes_with_xpto_module = []
def self.included(base)
self.classes_with_xpto_module << base
end
@scudelletti
scudelletti / function.sh
Created April 30, 2013 14:06
Simple Function with Condition(IF) in Shell Script
$VAR1=BlaBlaBla
$VAR1=PqPqPqPq
function export_ambient_variable_for() {
if [[ $1 = 'prod' ]]; then
echo 'Exporting ambient variables for Prod environment'
export ZZZZ=$VAR1
else
echo 'Exporting ambient variables for Dev environment'
export ZZZZ=$VAR2
class Model
def method(&block)
puts "START"
block.call
puts "END"
end
def second(&block)
puts "SECOND - START"
method(&block)
@scudelletti
scudelletti / exception.rb
Created August 22, 2013 19:29
Handling Exceptions
puts "Getting the Exception 1"
begin
eval("1+")
rescue Exception => e
puts "Exception Class => #{e.class} - Message: #{e}"
end
puts "Getting the Exception 2"
begin
eval("1+")
@scudelletti
scudelletti / gist:6708031
Last active December 23, 2015 23:09
Imperial March
// Source => http://www.adafruit.com/forums/viewtopic.php?f=25&t=34567
//code https://gist.github.com/1804108 20121125 @ 1339
//led for visualization (use 13 for built-in led)
int ledPin = 13;
//speaker connected to one of the pwm ports
int speakerPin = 9;
//tone frequencies http://home.mit.bme.hu/~bako/tonecalc/tonecalc.htm
@scudelletti
scudelletti / ssh_config
Last active April 22, 2016 10:27
Forward port on SSH
Host *.staging.something.com
User someuser
ForwardAgent yes
LocalForward localhost:43306 localhost:3306
LocalForward localhost:49200 localhost:9200
LocalForward localhost:49001 localhost:9001
@scudelletti
scudelletti / class_definition_in_specs.rb
Created May 27, 2016 07:21
How to avoid global constant in the specs
require 'spec_helper'
describe "Wow Coins" do
let(:klasz_class) do
Class.new do
attr_reader :title
def initialize(properties)
@title = properties[:title]
end
@scudelletti
scudelletti / lambda_calculus.rb
Last active November 22, 2016 11:54
If condition on lambda calculus
# Rules: A lamda always has 1 parameter, nothing more, nothing less
# Useful Content: https://en.wikipedia.org/wiki/Church_encoding
# Identity lambda
IDENTITY = ->x { x }
# True, returns the first argument
TT = ->x { ->y { x } }
# False, returns the last argument
@scudelletti
scudelletti / Dockerfile
Last active June 21, 2017 16:26
Run GUI Linux Apps through Docker with xQuartz on MacOS
# How to Use
# open -a XQuartz
# socat TCP-LISTEN:6000,reuseaddr,fork UNIX-CLIENT:\"$DISPLAY\"
# docker build . -t ds-xclock
# docker run -e DISPLAY=YOUR_LOCAL_IP_HERE:0 -it ds-xclock
#
# Useful Links:
# https://github.com/moby/moby/issues/8710
# http://kartoza.com/en/blog/how-to-run-a-linux-gui-application-on-osx-using-docker/
@scudelletti
scudelletti / export_env.sh
Created April 13, 2018 14:47
Export Env Variables stored on /etc/environment
# Loan Env Variables
while read line; do
export $(echo $line | sed 's/"//g')
done < /etc/environment