[ADD] old files

This commit is contained in:
Eduardo Cueto Mendoza 2020-05-07 11:05:12 -06:00
parent 400bdc6f01
commit f6f36bdd34
12 changed files with 215 additions and 0 deletions

22
ConversionPromotion.jl Executable file
View File

@ -0,0 +1,22 @@
# Conversion
function foobar(a,b)
x::Int8 = a
y::Int8 = b
x+y
end
println(isa(2,Float64))
println(isa(Int8,Type{Int8}))
println(convert(Int8,4))
Base.convert(::Type{Int8},x::String) = parse(Int8,x)
println(1+2.0+Int8(3))
println(typeof(1+2.0+Int8(3)))
println(promote(1,2.0,Int8(3)))
a = (3,2)
println(+(a...)) # Tuple unpacking notation
# @edit 2 + 4.0 macro to get

20
Files.jl Executable file
View File

@ -0,0 +1,20 @@
elements = readdlm("elements.txt")
#elements = readdlm("elements.txt",'\t')
println(elements[1, 1])
#println(elements[1])
println(typeof(elements[1,3]))
println(typeof(elements[1,1]))
println(collect(1:9))
m = reshape(collect(1:9),(3,3))
writedlm("numbers.txt",m,'\t')
m2 = readdlm("numbers.txt",Int8)
elements = readcsv("elements.csv")
elements, header = readcsv("elements.csv"; header=true)

49
InputOutput.jl Executable file
View File

@ -0,0 +1,49 @@
s = readstring("elements.txt")
println(s)
stream = open("elements.txt","r")
line = readline(stream)
println(line)
println(eof(stream))
println(position(stream))
println(read(stream, Char))
println(position(stream))
println(readline(stream))
println(read(stream, Int8))
println(readstring(stream))
myread(s::IOStream) = read(s,Char)
println(open(myread,"elements.txt"))
open("elements.txt") do stream
for line in eachline(stream)
println(line)
end
end
function f(stream)
for line in eachline(stream)
println(line)
end
end
println(open(f,"elements.txt"))
write("foobar.txt", "Hello world")
open("alpha.txt", "w") do io
for ch in 'A':'Z'
write(io, ch)
end
end

15
ModulesAndPackages.jl Executable file
View File

@ -0,0 +1,15 @@
workspace()
push!(LOAD_PATH, "/Users/eddie/Documents/Programming/Julia")
using Volume
println(LOAD_PATH)
workspace()
import Volume
println(Volume.sphere_volume(1))
workspace()
importall Volume
println(sphere_volume(1))

16
Networking.jl Executable file
View File

@ -0,0 +1,16 @@
conn = connect(1234)
write(conn, "Hello world!\n")
println(conn, "hello again")
function foo()
for i in 5:8
produce(i)
end
end
t = Task(foo)
consume(t)

31
NewType.jl Executable file
View File

@ -0,0 +1,31 @@
abstract Shape
type Circle <: Shape
x::Float64
y::Float64
radius::Float64
end
getposition(c::Circle) = (c.x,c.y)
function setposition(c::Circle,x,y)
c.x = x
c.y = y
end
type Rectangle <: Shape
x:: Float64
y::Float64
width::Float64
height::Float64
end
type ShapeGroup <: Shape
members::Vector{Shape}
end
function group(shapes::Shape...)
ShapeGroup(collect(shapes))
end

0
OOP.jl Executable file
View File

9
Package.jl Executable file
View File

@ -0,0 +1,9 @@
Pkg.add("Colors")
Pkg.resolve()
Pkg.rm("Colors")
using Colors
c = parse(Colorant, "red")

11
TypeHierarchiesMultiple.jl Executable file
View File

@ -0,0 +1,11 @@
telltype(x) = "Unknown Type"
telltype(x::Integer) = "Integer Type"
telltype(::AbstractFloat) = "Floatingpoint Type"
telltype(::Int64) = "64 Bytes Integer"
counargs(a) = "one"
counargs(a,b) = "two"
counargs(a,b,c) = "three"
foo(a,b) = "Two variables"
foo(a::Integer,b::Integer) = "Two integers"
foo(a::Integer,b::AbstractFloat) = "An integer and a float"
foo(a::AbstractFloat,b::Integer) = "An float and an integer"

23
Volume.jl Executable file
View File

@ -0,0 +1,23 @@
module Volume
export sphere_volume, cylinder_volume
"Volume of sphere with radius `r`"
sphere_volume(r) = (4/3)*π*r^3
"Volume of cylinder with radius `r` and height `h`"
cylinder_volume(r,h) = circle_area(r)*h
"Surface area of a cylinder of height `h` and radius `r`"
cylinder_area(r) = 2*circle_area(r) + 2*π*r*h
"Area of a triangle"
trianle_area(b,h) = b*h/2
"Area of circle with radius `r`"
circle_area(r) = π*r^2
"Rectangle area"
rectangle_area(h,w) = h*w
end

12
server.jl Executable file
View File

@ -0,0 +1,12 @@
@async begin
server = listen(1234)
while true
conn = accept(server)
println("Client connected")
@async while isopen(conn)
line = readline(conn)
print("From client: $line")
write(conn,uppercase(line))
end
end
end

7
test.jl Executable file
View File

@ -0,0 +1,7 @@
println("Hello World!")
println(3 + 4)
println(sqrt(36))
println(lowercase("HELLO WORLD!"))