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 / 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)
@digital-carver
digital-carver / tabular_after.vim
Last active August 27, 2015 12:32
An `after/plugin` function for Tabular.vim to allow PCRE (using eregex.vim)
if exists(':E2v')
function! AlignByRE() range
let range = a:firstline . ',' . a:lastline
let cmd = range
let re = input('Enter PCRE to align by: ')
if re == ""
" Run empty to use previous pattern
let cmd .= 'Tabularize'
execute cmd
else