More #AdventOfCode in #JuliaLang. Updated my graphics for 2022 day 14 and learnt to make animated gifs direct from data. (Un)surprisingly easy 😸

As always, full code at https://github.com/screwdog/AoC, including hints for #JuliaBeginners for each day up to 14

GitHub - screwdog/AoC

Contribute to screwdog/AoC development by creating an account on GitHub.

GitHub

Went back to my #AdventOfCode solution for day 12 and drew the results. Good opportunity to learn a little of #JuliaLang Images.jl and related packages.

Full solutions (including hints for #JuliaBeginners!) available at https://github.com/screwdog/AoC

GitHub - screwdog/AoC

Contribute to screwdog/AoC development by creating an account on GitHub.

GitHub

Just finished #AdventOfCode 2015 in #JuliaLang, after finishing 2022 a week ago. Had started it to complement my 2022 attempt and happy to get both done.

All my solutions are available at https://github.com/screwdog/AoC if anyone is interested.

I'm slowly going through my 2022 solutions and adding hints and comments to help any #JuliaBeginners

GitHub - screwdog/AoC

Contribute to screwdog/AoC development by creating an account on GitHub.

GitHub

#JuliaTipOfTheDay#JuliaBeginners
2022-12-01

To quickly create a new #JuliaLang project environment to try out some piece of code, use
`]activate --temp`
or
`Pkg.activate(; temp = true)`

A fresh Julia environment is created, independent of your current env, where you can install any packages needed for that code. When you exit your Julia session, this temporary env will be deleted.

Very useful for running code you don't intend to keep saved, eg. when debugging someone else's Julia code.

@screw_dog

Nice! You can consider also tagging them with #JuliaBeginners, since you're also including descriptions that are useful to beginners. That may help separate it from other posts that just want to post their solutions or show off different advanced ways of solving them.

@Logan

#JuliaTipOfTheDay#JuliaBeginners
2022-11-28

Say you define a type
```
struct Point2D
x::Int
y::Int
end
```
then x and y are the "fields" of this struct. `fieldnames(Point2D)` returns `(:x, :y)`.

If you define `mypt = Point2D(4, 8)`, then
`mypt.x` calls `getproperty(mypt, :x)` (see prev. post),
which by default calls `getfield(mypt, :x)`,
which is automatically defined by #JuliaLang to return `x`'s value.

(contd. from previous: https://julialang.social/@Sundar/109411842573985228
as part 2 of #FieldsAndProperties)

Sundar R :julia: (@[email protected])

#JuliaBeginners #JuliaTipOfTheDay​ 2022-11-26 When you see `foo.bar` in your #JuliaLang code, Julia sees that as the call `getproperty(foo, :bar)`. Let's say you load data into a #DataFrame `df`. When you access `df.Species`, that calls `getproperty(df, :Species)`. DataFrames.jl has a matching method for that call, which returns `df[!, :Species]` i.e. makes it a column access. You can do that for your custom types too! (Useful to understand "fields" before that, a post on those is upcoming.)

JuliaLang

#JuliaBeginners #JuliaTipOfTheDay
2022-11-26

When you see `foo.bar` in your #JuliaLang code, Julia sees that as the call `getproperty(foo, :bar)`.

Let's say you load data into a #DataFrame `df`. When you access `df.Species`, that calls `getproperty(df, :Species)`.
DataFrames.jl has a matching method for that call, which returns `df[!, :Species]` i.e. makes it a column access.

You can do that for your custom types too! (Useful to understand "fields" before that, a post on those is upcoming.)

#JuliaBeginners #JuliaLang #JuliaTipOfTheDay
2022-11-23

"I call `plot`, but I see no plot!"
This is a common source of confusion for beginners in Julia - calling `plot(..)` seems to work in the REPL and in notebooks, but not in a script.

Calling `plot(..)` only creates a Plot object. It's the job of `display` to actually show it. The REPL and notebooks automatically call `display` for you, but scripts need to do
`p = plot(..); display(p)`
or add a `show = true` argument to the `plot` call.

#JuliaBeginners #JuliaLang #JuliaTipOfTheDay
2022-11-21

The search on the JuliaHub site (https://juliahub.com/ui/Search) is an incredible resource.

Came across a macro in a snippet of code, and need to know where the macro is from? Try searching for it via the Symbols tab, filtering by "definition" and "macro".

You can also search across the documentations of all registered packages, regex-search through public Julia code, etc.

#JuliaHub #Search

JuliaHub

#JuliaBeginners #JuliaLang #JuliaTipOfTheDay
2022-11-18

Say you're working at the REPL, and get an ERROR message with a Stacktrace. To look up the fourth method in the call chain, just type 4 and press Ctrl-Q. Your editor will instantly be opened, with the cursor on the location where that method is defined.

Also works for the results of `methods` and `methodswith` calls; just use the number in square brackets next to the method you want. Such a neat little quality-of-life feature of the REPL.