Skip to content

Instantly share code, notes, and snippets.

@squito
squito / bash_trim_array.sh
Last active March 15, 2024 13:19
remove an arg from a command line argument in bash
#!/bin/bash
# this is a demo of how to remove an argument given with the [-arg value] notation for a specific
# [arg] (-T in this case, but easy to modify)
echo $@
echo $#
i=0
ORIGINAL_ARGS=("$@")
TRIMMED_ARGS=()
@squito
squito / test_loop.py
Created January 31, 2023 20:42
Pytest test looper
#!/usr/bin/env python
## Makes it easy to run tests in a loop
## Just a small bit of automation around something like
## ls quanta_cache.py test/test_quanta_cache.py | entr -r python -m pytest test/test_quanta_cache.py
## but that is just complex enough I would never remember
## If you want to test `jira.py` in a loop, run:
##
## test/test_loop.py --test jira.py
@squito
squito / bash_vars.sh
Last active September 12, 2021 00:34
working with bash variables
#!/bin/bash
my_func() {(
# this takes a big shortcut around doing testing & unsetting -- because this entire function
# is wrapped in "()", it executes in a subsell, so we can unconditionally unset, without
# effecting vars outside
unset MASTER
echo "do something with MASTER=${MASTER-unset}"
)}
@squito
squito / AccessControlCheck.scala
Last active May 1, 2021 03:27
Nested UGIs , doAs, proxy users
import java.security.PrivilegedExceptionAction
import org.apache.hadoop.security.UserGroupInformation
import org.apache.hadoop.fs.Path
import org.apache.hadoop.fs.FileSystem
import org.apache.hadoop.conf.Configuration
object AccessControlCheck {
val privilegedPath = "/some/path/with/limited/access"
@squito
squito / reflector.scala
Last active September 24, 2020 01:09
utils for accessing field & methods that are private in the scala repl via reflection
/* For example, I want to do this:
*
* sqlContext.catalog.client.getTable("default", "blah").properties
*
* but none of that is public to me in the shell. Using this, I can now do:
*
* sqlContext.reflectField("catalog").reflectField("client").reflectMethod("getTable", Seq("default", "blah")).reflectField("properties")
*
* not perfect, but usable.
*/
@squito
squito / badValDefMacro.scala
Last active August 12, 2020 20:57
some basic macros with quasiquotes. Accompanies this blog post <http://imranrashid.com/posts/learning-scala-macros/>. Partially a translation of this example <http://www.warski.org/blog/2012/12/starting-with-scala-macros-a-short-tutorial/> to quasiquotes.
def getValMacro(c: Context)(s: c.Expr[Any]) : c.Expr[Any] = {
import c.universe._
val q"val $name = $value" = s.tree
c.Expr(value)
}
def getVal(s: Any) = macro getValMacro
getVal{val x = 17}
error: exception during macro expansion:
logfile screenlogs/log.%n
deflog on
defscrollback 10000
screen 1
#other settings
hardstatus alwayslastline
hardstatus string '%{= kG}[ %{G}%H %{g}][%= %{= kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B} %d/%m %{W}%c %{g}]'
vbell off
autodetach on
#Binds
@squito
squito / _summary.md
Last active February 5, 2020 14:15
spark sql timestamp semantics, and how they changed from 2.0.0 to 2.0.1 (see query_output_2_0_0.txt vs query_output_2_0_1.txt) changed by SPARK-16216

Spark "Timestamp" Behavior

Reading data in different timezones

Note that the ansi sql standard defines "timestamp" as equivalent to "timestamp without time zone". However Spark's behavior depends on both the version of spark and the file format

format \ spark version <= 2.0.0 >= 2.0.1
@squito
squito / Test.java
Last active June 24, 2019 15:35
Interrupts, joins, OOMs, and uncaught exception handlers
import java.util.ArrayList;
public class Test implements Runnable {
public static class OOMer implements Runnable {
public void run() {
System.out.println("Starting oomer");
ArrayList<byte[]> stuff = new ArrayList<>();
while (true) {
stuff.add(new byte[100000000]);
@squito
squito / mylib.R
Last active June 13, 2019 19:09
searchable source dirs for R (aka, a "classpath" for R)
## this should get loaded by your ~/.Rprofile
## either just stick all these definitions right in ~/.Rprofile, or
## have ~/.Rprofile source this file, etc.
source.dirs <- c(
## add any "base" locations here. this is like a "classpath" in java
## my default is c("~/myRUtils/src","~/companyRUtils/src","~/publicRUtils"),
## but you can use whatever you like
paste(Sys.getenv("HOME"),"myRUtils","src", sep="/"),
paste(Sys.getenv("HOME"),"companyRUtils","src", sep="/"),