Skip to content

Instantly share code, notes, and snippets.

View ivarne's full-sized avatar

Ivar Nesje ivarne

  • Oslo, Norway
  • 08:24 (UTC +01: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"])
);

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)
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)
@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
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
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