Skip to content

Instantly share code, notes, and snippets.

View ivarne's full-sized avatar

Ivar Nesje ivarne

  • Oslo, Norway
  • 04:35 (UTC +02:00)
View GitHub Profile
@ivarne
ivarne / Sample Usage.cs
Last active February 22, 2024 22:17
Suggested ServiceResult implementation for Altinn apps
public class TestService
{
public ServiceResult<string> GetResult(bool success)
{
if (success)
{
return "Hello, World!";
}
else
{
const fs = require("fs");
const path = require("path");
const asset_manifest = JSON.parse(
fs.readFileSync("./build/asset-manifest.json", { encoding: "utf8" })
);
const startupScript = fs.readFileSync(
path.join("./build", asset_manifest["runtime~main.js"])
);
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

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");
#!/bin/bash
gfortran -o $2 -fno-underscoring $1 libhgraph.a libg2c.so -L/usr/X11R6/lib64 -lX11
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()
@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
"""
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

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

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)