Skip to content

Instantly share code, notes, and snippets.

View ivarne's full-sized avatar

Ivar Nesje ivarne

  • Oslo, Norway
  • 23:39 (UTC +02:00)
View GitHub Profile
module testsums
export sum5, sum5b, dosums
function sum5(scale, sa1, a1, sa2, a2, sa3, a3, sa4, a4, sa5, a5, out)
for i=1:length(out)
@inbounds out[i] = scale*(sa1*a1[i] + sa2*a2[i] + sa3*a3[i]
+ sa4*a4[i] + sa5*a5[i])
end
end
@ivarne
ivarne / interfaces.jl
Last active August 29, 2015 14:01 — forked from tknopp/interfaces.jl
const _interfaces = Dict{Function,Vector{DataType}}()
function addInterface(d::DataType, f::Function...)
for g in f
if haskey(_interfaces, g)
push!(_interfaces[g], d)
else
_interfaces[g] = DataType[d]
end
end
diff --git a/base/REPLCompletions.jl b/base/REPLCompletions.jl
index df8c965..d9a8a2c 100644
--- a/base/REPLCompletions.jl
+++ b/base/REPLCompletions.jl
@@ -183,6 +183,17 @@ function latex_completions(string, pos)
end
function completions(string, pos)
+ try
+ if isdefined(Main, :CUSTOM_AUTOCOMPLETION_HOOK)
num = rand(1_000_000)
len = map(rand(1_000_000)) do a
e = string(a)
if e[1] == '0'
length(e)-2
else
length(e)-4
end
end
h = hist(len)

Backporting policy

Becasue Julia is in rapid development and we need the freedom to to backwards incompatible changes on the master branch, the Julia community has decided that we want to do regular releases for people who wants a more stable enviroment to get the Julia experience. As bugs are discovered in the released versions, we will make a best effort attempt to fix them and release bugfix releases. We call this process backporting because usually it involves cherry-picking commits from the master branch onto the release branch.

Backwards Compatibility

  1. The fundamental rule for compatibility is that a program that doesn't rely on something we consider a bug (eg. exceptions and wrong method results), that works on 0.3.x must work without modification on 0.3.y where y > x.

Forwards compatibility

"""
Somewhat minimal example demonstrating how the Python dropbox api has inconcistent UTF-8 handeling
for filenames and paths.
To simpelify upload of many files i let users copy their files to a upload folder under an
application specific dropox folder named upload. Then I download theese files to my server and makes
them availible to the application.
My problem was that if filenames contains non ASCII characters like æøå I got an encoding error when
I tried to delete the file. The problem was resolved when i encoded f['path'] to utf-8, but I have
@ivarne
ivarne / REPL.jl
Last active December 25, 2015 03:29 — forked from quinnj/gist:6908779
_
_ _ _(_)_ | A fresh approach to technical computing
(_) | (_) (_) | Documentation: http://docs.julialang.org
_ _ _| |_ __ _ | Type "help()" to list help topics
| | | | | | |/ _` | |
| | |_| | | | (_| | | Version 0.2.0-prerelease+3952
_/ |\__'_|_|_|\__'_| | Commit d0c2058 2013-10-06 19:08:09 UTC
|__/ | x86_64-w64-mingw32
julia> abstract BTree
function old_colon{T<:Integer}(start::T, step::T, stop::T)
Range(start, step, max(0, div(stop-start+step, step)))
end
function new_colon{T<:Integer}(start::T, step::T, stop::T)
len,rem = divrem(stop-start,step)
Range(start, step, max(0, len+div(rem+step,step)))
end
function range_test_old()
#!/bin/bash
gfortran -o $2 -fno-underscoring $1 libhgraph.a libg2c.so -L/usr/X11R6/lib64 -lX11

Dealing with errno in c-APIs in Julia

Lots of C APIs that you might want to call from julia uses a special thread local global integer errno to indicate errors because C only allows one return value and does not provide exceptions to indicate errors. Usually the function interface will define a special return value to indicate an error, and let set errno to a number that represents an index into an array of standard error messages. Some functions, like unix strtoul, do not have a special value to indicate error, but says it will change errno to an appropriate value if an error is encountered. This will require a cautious programmer to set errno = 0; before calling the function and check if it is different from 0 after calling the function.

Example usage in c

errno = 0;
arg = strtoul (buf, NULL, 0);
if (errno)
    perror ("strtoul");