Skip to content

Instantly share code, notes, and snippets.

View JeffreySarnoff's full-sized avatar

Jeffrey Sarnoff JeffreySarnoff

View GitHub Profile
@JeffreySarnoff
JeffreySarnoff / dispatchingNamedTuples.jl
Created February 1, 2018 01:52
dispatching with NamedTuples
julia> nt_proto_a_names = (:first, :last)
(:first, :last)
julia> nt_proto_b_names = (:larger, :smaller)
(:larger, :smaller)
julia> nt_proto_a = NamedTuple{nt_proto_a_names}
NamedTuple{(:first, :last),T} where T<:Tuple
julia> nt_proto_b = NamedTuple{nt_proto_b_names}
@JeffreySarnoff
JeffreySarnoff / dispatchingNamedTuples.jl
Created February 1, 2018 01:52
dispatching with NamedTuples
julia> nt_proto_a_names = (:first, :last)
(:first, :last)
julia> nt_proto_b_names = (:larger, :smaller)
(:larger, :smaller)
julia> nt_proto_a = NamedTuple{nt_proto_a_names}
NamedTuple{(:first, :last),T} where T<:Tuple
julia> nt_proto_b = NamedTuple{nt_proto_b_names}
@JeffreySarnoff
JeffreySarnoff / usingC.jl
Last active April 4, 2018 12:29
using C in Julia
using BenchmarkTools
C_code = raw"""
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int compare(const void* l, const void* r){
char* cl = *(char**)l+8;
char* cr = *(char**)r+8;
return strcmp(cl, cr);
@JeffreySarnoff
JeffreySarnoff / meetup_2018-09-12_draft.html
Created September 8, 2018 08:42
evolving list of meetup meeting-ups (includes some who may be removed tomorrow)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title></title>
<meta name="generator" content="LibreOffice 5.4.2.2 (Linux)"/>
<meta name="author" content="Jeffrey Sarnoff"/>
<meta name="created" content="2018-09-07T22:36:43.113857750"/>
@JeffreySarnoff
JeffreySarnoff / more_bitops.jl
Last active October 6, 2018 19:35
integer bit ops
# some more bit related operators for Julia
# Jeffrey Sarnoff (2012-Oct-07)
# bitsizeof, allbits1, lsbs1, lsbs0, msbs1, msbs0,
# rol, ror, ispow2, pow2lte, pow2gte, pow2lt, pow2gt,
# signs_differ, signs_same, floor_avg, ceil_avg
bitsizeof(x) = sizeof(x)<<3
SUS = Union{Signed,Unsigned}
@JeffreySarnoff
JeffreySarnoff / BitOps.jl
Last active October 7, 2018 02:35
BitOps for Julia
"""
BitOps exports functions using low level bit manipulation to modify standard Int and UInt values.
Note: Functions that check their arguments are named `safe_..`, others do no checking.
Copyright 2017 by Jeffrey Sarnoff. Released under the MIT License.
"""
module BitOps
export bitsizeof, clr_bit, set_bit, flp_bit,
@JeffreySarnoff
JeffreySarnoff / DayCountConventions.jl
Created January 22, 2019 23:33
another approach to encoding financial day counts
using Dates
const DTM = Union{Date, DateTime}
value(dtm::DTM) = dtm.instant.periods.value
abstract type AbstractDayCountConvention end
struct ActualActualConvention <: AbstractDayCountConvention end
@JeffreySarnoff
JeffreySarnoff / curriedcomparisons.md
Created January 31, 2019 01:05
curried comparisons

add in Base/operators.jl

"""
    !=(x)

Create a function that compares its argument to `x` using [`!=`](@ref), i.e.
a function equivalent to `y -> y != x`.
The returned function is of type `Base.Fix2{typeof(!=)}`, which can be
used to implement specialized methods.
# https://gist.github.com/pfitzseb/240744ce79a9d7561c1277de7dbfa43e
module TraceCalls
using Cassette
mutable struct Trace
level::Int
cutoff::Int
end
# within Base/mpfr.jl
function _duplicate(x::BigFloat)
z = BigFloat(; precision = precision(x))
ccall((:mpfr_set, :libmpfr), Int32, (Ref{BigFloat}, Ref{BigFloat}, Int32), z, x, 0)
return z
end
function nextfloat!(x::BigFloat)
ccall((:mpfr_nextabove, :libmpfr), Int32, (Ref{BigFloat},), x) != 0