Skip to content

Instantly share code, notes, and snippets.

View digital-carver's full-sized avatar

SundaraRaman R digital-carver

View GitHub Profile
@digital-carver
digital-carver / errorreturns.md
Last active December 9, 2025 23:05
Error returns Julia RFC

Context: JuliaLang/julia#60344

Error returns vs Exceptions

Since we already have exceptions in Julia with the try-catch mechanism, adding something like this which is similar to but works different from them adds cognitive burden on the user. I think the gain here outweighs that, but it's worth minimizing that burden and not accidentally adding to that in design decisions and communication: For eg., Except{...} syntax or an except keyword would be misleading or at the least unnecessarily confusing.

This feature neatly separates expected error types from truly exceptional, unexpected errors, and reserving the "exception" terminology to only the latter, would let that clearly come through.

The name "declared exceptions" also made more sense in Stefan's original context, but with this (or similar) implementation, "declared error returns" would be a better name: despite Exception being the supertype for these error return types, it's useful to clearly distinguish betwee

@digital-carver
digital-carver / getuniqueindices.jl
Last active October 16, 2022 04:50
Indices of each unique element in an array - threaded
function unique_ids3(itr)
# create individual dictionaries for each thread,
# where keys have the type of itr's elements
d = [Dict{eltype(itr), Vector{Int}}() for _ in 1:Threads.nthreads()]
# iterate through itr, using automatic threading
# :static ensures that threadid() remains constant within an iteration
Threads.@threads :static for index in eachindex(itr)
id = Threads.threadid()
@inbounds val = itr[index]
# check if the dictionary
using BenchmarkTools
function bubble_sort(v::AbstractArray{T}) where T<:Real
for _ in 1:length(v)-1
for i in 1:length(v)-1
@inbounds if v[i] > v[i+1]
v[i], v[i+1] = v[i+1], v[i]
end
end
end
@digital-carver
digital-carver / TablesDocsPartial-discountoutput.html
Last active April 11, 2022 14:43
Discount markdown parser testing
<h3><code>Tables.columns</code> usage</h3>
<p><pre><code class=", now let's take a look at a case utlizing [`Tables.columns`](@ref).">
The following code is taken from the [DataFrames.jl](https://github.com/JuliaData/DataFrames.jl/blob/master/src/other/tables.jl)
Tables.jl implementation:
</code></pre>
getvector(x::AbstractVector) = x
getvector(x) = collect(x)</p>
<h1>note that copycols is ignored in this definition (Tables.CopiedColumns implies copies have already been made)</h1>
@digital-carver
digital-carver / showsource.jl
Created November 28, 2021 23:29
Quick and dirty macro/function to show some source code of a function
macro showsource(ex0...)
InteractiveUtils.gen_call_with_extracted_types_and_kwargs(__module__, :showsource, ex0)
end
showsource(f, @nospecialize t; kwargs...) = showsource(functionloc(f,t)...; kwargs...)
function showsource(file::AbstractString, line::Integer; nlines = 10)
run(pipeline(`tail -n +$(line) $file`, `head -n $(nlines)`))
nothing
end
" Easy insertion of emojis with C-K
execute 'digraph :x 128544'
execute 'digraph :) 128578'
execute 'digraph :D 128512'
execute 'digraph =D 128513'
execute 'digraph :P 128523'
execute 'digraph :\| 128528'
execute 'digraph =\| 128529'
execute 'digraph :O 128558'
execute 'digraph :/ 128533'
@digital-carver
digital-carver / YourbanPro.user.js
Last active November 16, 2020 21:44
Userscript for use with UrbanPro website
// ==UserScript==
// @name YourbanPro
// @namespace aaressaar
// @match http*://www.urbanpro.com/*
// @grant none
// @version 0.5
// @author SundaraRaman
// @description Remove annoyances and improve UrbanPro interface
// ==/UserScript==
import random
# import matplotlib.pyplot as plt
suits = ['hearts', 'diamonds', 'spades', 'clubs']
value = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
cards = []
for item in suits:
for number in value:
cards.append([number, item])
@digital-carver
digital-carver / gcc_predef_macros_cygwin.c
Created May 3, 2018 08:31
Output of `gcc -dM -E - <<<''` on Cygwin 2.10.0 x86_64 with gcc 6.4.0
#define __DBL_MIN_EXP__ (-1021)
#define __UINT_LEAST16_MAX__ 0xffff
#define __ATOMIC_ACQUIRE 2
#define __FLT_MIN__ 1.17549435082228750797e-38F
#define __GCC_IEC_559_COMPLEX 2
#define __UINT_LEAST8_TYPE__ unsigned char
#define __SIZEOF_FLOAT80__ 16
#define __INTMAX_C(c) c ## L
#define __CHAR_BIT__ 8
#define __UINT8_MAX__ 0xff
@digital-carver
digital-carver / cyg_removable_deps.sh
Created March 2, 2018 10:34
List unneeded dependencies from Cygwin
#!/bin/bash
# Print a list of packages that no other package depends on
# Script taken from https://superuser.com/a/570575/3200
PackageCount=0
PackageIter=0
# Populate package array
declare -A Packages
PackageList=$(cygcheck.exe -c | cut -d' ' -f1 | tail -n +3)