Skip to content

Instantly share code, notes, and snippets.

View fonsp's full-sized avatar
🌳
climbing

Fons van der Plas fonsp

🌳
climbing
View GitHub Profile
using Test
"asdf"
function jl_is_runnable(path)
🏡 = Core.eval(Main, :(module asdf end))
try
Core.eval(🏡, :(include($path)))
catch ex
println.(enumerate(readlines(path; keep=true)))
### A Pluto.jl notebook ###
# v0.10.9
using Markdown
using InteractiveUtils
# This Pluto notebook uses @bind for interactivity. When running this notebook outside of Pluto, the following 'mock version' of @bind gives bound variables a default value (instead of an error).
macro bind(def, element)
quote
local el = $(esc(element))
@fonsp
fonsp / lenses.jl
Last active October 22, 2020 16:24
Interactive lensing
### A Pluto.jl notebook ###
# v0.12.4
using Markdown
using InteractiveUtils
# This Pluto notebook uses @bind for interactivity. When running this notebook outside of Pluto, the following 'mock version' of @bind gives bound variables a default value (instead of an error).
macro bind(def, element)
quote
local el = $(esc(element))

Deploying Julia on heroku

Let's assume that you can run your web server on your own computer, and that you can open it in your own browser (through localhost or 127.0.0.1). This guide will go through the steps of putting that app online!

This guide will be based on a hello world sample project that uses Genie.jl, but the steps from this guide apply to any Julia web framework.

heroku has tons of features, but for a simple app, we only need the basics. In particular, we do not need the heroku command line, we can do everything through the online GUI.

Basics

heroku uses git for deployment: to package your app, you create a git repository, and to put a new version of your app online, you push to the git repository. If you already know git, then you now know how to manage a web server! It's like GitHub pages, but more powerful (and more complicated). Read heroku's introduction for a basi

Here's a handy function:

function two_cols(left, right)
	HTML("""
		<style>
		div.two-cols {
			display: flex;
			width: 100%;
		}
@fonsp
fonsp / Pluto.jl Zulip discussion about redirecting stdout & stdin to the browser.md
Created August 12, 2020 10:18
Pluto.jl Zulip discussion about redirecting stdout & stdin to the browser

Michael Alexander: I am trying to convert a Jupyter notebook and would like the output of Pkg.status() and Pkg.instantiate() to show within the Pluto notebook, not in the terminal. Is there a way to force certain messages to show in the notebook? (PS - I love Pluto and the JuliaCon talk was "out of this world"!)

karl: I don't think that is possible. Unless you find a way to relay the printed messages into a string and return that string as the output of a cell.

karl: For what do you need the output inside the notebook?

James Fairbanks: just guessing, but this is a technique people do in notebooks to help users make sure they have the same versions as the author. Maybe you could do Pkg.instantiate() and then ;cat Manifest.toml to get the version numbers to appear?

karl: Does pluto support shell commands like ;cat?

@fonsp
fonsp / a.jl
Last active August 12, 2020 19:03
Download both into the same directory.
### A Pluto.jl notebook ###
# v0.11.4
using Markdown
using InteractiveUtils
# ╔═╡ fcd73180-dcc9-11ea-25e7-2dab70526b7d
x = 1
# ╔═╡ 09c77f6c-dcca-11ea-3b55-2dba2bfce9f8
using Unitful, BSON
ufoo = 3.0u"m/s"
BSON.@save "test.bson" ufoo
function get_ufoo()
BSON.@load "test.bson" ufoo
return ufoo
@info "Welcome to Julia! Let's get started"
@info "Setting up the environment - grab a cup of tea"
import Pkg
# we activate a clean environment called "pluto" - this does not affect the environment that your code runs in
# for using fool-proof package environments inside notebooks, see https://github.com/fonsp/Pluto.jl/issues/142#issuecomment-642049815
Pkg.activate("pluto")
Pkg.Registry.update()
Pkg.add("Pluto")
# this time i _did_ run the code - copy paste this into the REPL
# https://www.youtube.com/watch?v=m2DvmHusyk4
# put something.jl from this gist in the same dir
import Pluto
session = Pluto.ServerSession()
try