Some interesting Julia codes
Julia is fast, composable, dynamic, general, reproducible and open source. The codes below were taken from https://julialang.org. I found it very illustrating.
Multiple dispatch
struct Dog end
struct Cat end
dog, cat = Dog(), Cat()
meet(a::Dog, b::Dog) = "The dogs play together"
meet(a::Dog, b::Cat) = "The dog chases the cat"
meet(a::Cat, b::Dog) = "The cat hisses at the dog"
meet(a::Cat, b::Cat) = "The cats ignore each other"
meet(dog, cat)
meet(dog, dog)
meet(cat, cat)
Display customization
struct Nutshell{T}
contents::T
end
Base.show(io::IO, n::Nutshell) = print(io, "🥜 ", n.contents, " 🥜")
Nutshell("Julia")
Unicode and math
α, β = .5, .3
f(x) = α * x + β
Σ(v) = reduce(+, v)
Σ(f.(1:5))
Comprehensions
[x^2 for x in 1:5]
Broadcasting
A = [1 2; 3 4]
sin.(A) .+ 1
Dict(c => i for (i, c) in enumerate("julia")
Piping and composition
1:5 |> sum |> sqrt
(sqrt ∘ sum)(1:5) # equiv. above
map(exp ∘ abs, [-1, 2, -3])
Destructuring
(a, b, c) = 1:3
a, c # => (1, 3)
head, tail... = ["first", "second", "third"]
head, tail # => ("first", ["second", "third"])
Metaprogramming
ex = :(1 + 2 * 3)
typeof(ex) # => Expr
eval(ex) # => 7
Easy package install
using DataFrames
# if not installed, prompted for installation, after 'y' answer
df = DataFrame(name = ["Alice", "Bob"], age = [25, 30])
Defaults and keywords args
function greet(name, greeting = "Hello"; punctuation = "!")
"$greeting, $name$puctuation"
end
greet("Julia") # "Hello, Julia!"
greet("world", "Hi"; puctuation = ".") # "Hi, world."
Multi-threading
function fib(n)
n < 2 && return n
t = Threads.@spawn fib(n-2)
return fib(n-1) + fetch(t)
end
fib(10)
Threads.nthreads() # => threads assigned to Julia
Build-in REPL modes
# Default Julia mode, backspace from other modes
# Press ] for package mode
# Press ; for shell mode
# Press ? for helps
# Press $ for R mode, if RCall.jl is installed
Code introspection (simplified)
f(x, y) = x + y
@code_warntype f(1, 2)
@code_llvm f(1, 2)
@code_native f(1, 2)
Running ASReml on Linux
To run ASReml on a Linux system can be very tricky. This software has built its reputation. It then don’t care very much about its custormers. The following valid instructions were after many combination tests. Had you any other alternatives, I would not recommend ASReml, especially on Linux, where most serious computations are carried on nowadays.
The following instructions are to run a cloud instance of AlmaLinux9 one a AlmaLinux 10 system.
Resize root partition on an AlmaLinux OS
Resizing Root Partition on AlmaLinux 10 (LVM + XFS)
Since XFS filesystems cannot be shrunk, increasing the root partition requires backing up the /home partition, deleting it, expanding /root, and then recreating /home.
Prerequisites
- A backup location with enough space (e.g.,
/mnt/w). - Root or sudo access.
Step 1: Backup Home Data
Backup all data from /home to a temporary location.
sudo mkdir -p /mnt/w/home_backup
sudo rsync -aHAX --progress /home/ /mnt/w/home_backup/
Step 2: Unmount and Remove the Home Volume
Ensure no processes are using /home, then unmount it and remove the Logical Volume (LV).