Skip to content

Instantly share code, notes, and snippets.

View ivarne's full-sized avatar

Ivar Nesje ivarne

  • Oslo, Norway
  • 08:06 (UTC +02:00)
View GitHub Profile
"""
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");
src/e_j0.c:281:10: warning: variable 'p' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
else if(ix>=0x40000000){p = pR2; q= pS2;}
^~~~~~~~~~~~~~
src/e_j0.c:283:6: note: uninitialized use occurs here
r = p[0]+z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5]))));
^
src/e_j0.c:281:7: note: remove the 'if' if its condition is always true
else if(ix>=0x40000000){p = pR2; q= pS2;}
^~~~~~~~~~~~~~~~~~
src/e_j0.c:273:17: note: initialize the variable 'p' to silence this warning
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)