Skip to content

Instantly share code, notes, and snippets.

View fdelacruz's full-sized avatar

Francisco De La Cruz fdelacruz

View GitHub Profile
@fdelacruz
fdelacruz / gist:3acfb257dad5b6ea4c89f4ed9a5b4873
Last active July 29, 2024 13:19
Cross build to aarch64-unknown-linux-gnu
#!/bin/bash -xe
readonly TARGET_ARCH=aarch64-unknown-linux-gnu
readonly SOURCE_PATH="./target/$TARGET_ARCH/release/hello-world"
readonly TARGET_PATH=/home/fdelacruz/workspace/cross_build
# readonly PI_IP=192.168.1.x
readonly TARGET_HOST=fdelacruz@$PI_IP
readonly PORT=2202
cargo install -f cross
xcode-select --install
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew update
brew cask install iterm2
# update iterm2 settings -> solarized presets
brew install git
brew cask install spectacle
brew cask install alfred
# set CMD+space to launch alfred
brew cask install firefox
def proc_test
proc = Proc.new { return }
proc.call
puts "Hello world"
end
proc_test # calling proc_test prints nothing
def lambda_test
lam = lambda { return }
lam.call
puts "Hello world"
end
lambda_test # calling lambda_test prints 'Hello World'
proc = Proc.new { |x| puts x } # creates a proc that takes 1 argument
proc.call(2) # prints out 2
proc.call # returns nil
proc.call(1,2,3) # prints out 1 and forgets about the extra arguments
lam = lambda { |x| puts x } # creates a lambda that takes 1 argument
lam.call(2) # prints out 2
lam.call # ArgumentError: wrong number of arguments (0 for 1)
lam.call(1,2,3) # ArgumentError: wrong number of arguments (3 for 1)
lambda { puts "Hello!" }
#Is just about the same as
Proc.new { puts "Hello!" }
cube = Proc.new { |x| x ** 3 }
[1, 2, 3].collect!(&cube) #=>[ 1, 8, 27]
[4, 5, 6].map!(&cube) #=>[64, 125, 216]
array = [1, 2, 3, 4]
array.collect! do |n|
n ** 2
end
puts array.inspect # => [1, 4, 9, 16]
class Gear
attr_reader :chainring, :cog, :rim, :tire
def initialize(chainring, cog, rim, tire)
@chainring = chainring
@cog = cog
@rim = rim
@tire = tire
end
def ratio