Skip to content

Instantly share code, notes, and snippets.

@jaytaylor
jaytaylor / dataloop_post_install.sh
Last active August 29, 2015 14:04
DataLoop ubuntu post-install cleanup script.
#!/usr/bin/env bash
set -e -x
# Shutdown the dataloop agent.
sudo service dataloop-agent stop || true
# Kill stragglers in the even that the service control didn't work right.
agentPids=$(ps -ef | grep 'dataloop-lin-agent' | grep -v 'grep' | sed 's/ \+/ /g' | cut -d' ' -f2)
test -n "${agentPids}" && sudo kill -9 ${agentPids}
@jaytaylor
jaytaylor / build.sbt
Created July 31, 2014 20:35
Scala SBT `build.sbt` example of hooking/injecting arbitrary shell commands and using non-native libraries in the build definition via a task run after successful compilation.
organization := "org.foo.bar"
name := "JustAnExample"
version := "1.0"
scalaVersion := "2.10.3"
scalacOptions := Seq("-unchecked", "-deprecation", "-encoding", "utf8")
@jaytaylor
jaytaylor / es_delete_matching_indices_and_aliases.sh
Last active August 29, 2015 14:04
Deletes all Elasticsearch indices and aliases matching a certain pattern.
#!/usr/bin/env bash
##
# NB: The example below is useful when you want to delete indexes and aliases which match a certain pattern.
# To simply delete everything (and assuming the "action.disable_delete_all_indices" configuration isn't set to "false"),
# you can use:
# curl -XDELETE http://localhost:9200/_all
test -z $1 && echo 'error: missing required parameter: match-pattern (or "_all" to delete all indices)' 1>&2 && exit 1
@jaytaylor
jaytaylor / threatstream_intelligence_walker.py
Last active August 29, 2015 14:05
ThreatStream API Intelligence downloader, separates intel into different files based on i-type.
#!/usr/bin/env python
"""ThreatStream Raw Intelligence downloader. Puts into 1 file for each itype."""
__author__ = 'Jay Taylor [@jtaylor]'
import io, json, requests, os
################################################################################
# Begin configuration
@jaytaylor
jaytaylor / EnvHacker.scala
Created August 21, 2014 02:41
Setting environment variables in Scala JVM
trait EnvHacker {
/**
* Portable method for setting env vars on both *nix and Windows.
* @see http://stackoverflow.com/a/7201825/293064
*/
def setEnv(newEnv: Map[String, String]): Unit = {
try {
val processEnvironmentClass = Class.forName("java.lang.ProcessEnvironment")
val theEnvironmentField = processEnvironmentClass.getDeclaredField("theEnvironment")
theEnvironmentField.setAccessible(true)
@jaytaylor
jaytaylor / es-idx-pattern-doc-counter.sh
Created August 26, 2014 23:53
Elasticsearch document sum counter for a set of indices matching a particular pattern.
#!/usr/bin/env bash
pattern=''
host='localhost:9200'
expr $(
curl --fail --silent http://${host}/_cat/indices?v | \
sed 's/ \{1,\}/ /g' | \
grep " ${pattern}.*" | \
@jaytaylor
jaytaylor / postgresql_log_settings.conf
Created September 30, 2014 17:12
Postgresql development logging configuration
logging_collector = on
log_directory = '/tmp'
log_filename = 'postgresql-%Y-%m-%d.log'
log_rotation_age = 1d
log_checkpoints = on
log_connections = on
log_disconnections = on
log_duration = on
log_hostname = on
log_line_prefix = '[%m] [pid=%p user=%u@%r db=%d xid=%x] %q[sid=%c line=%l] '
@jaytaylor
jaytaylor / install-shipbuilder-cleanup.sh
Last active August 29, 2015 14:07
ShipBuilder cleanup maintenance script.
#!/usr/bin/env bash
set -e -x
target='/usr/local/bin/shipbuilder-cleanup'
sudo curl --location --fail --silent --show-error --remote-name "${target}" 'https://gist.github.com/jaytaylor/2604ff09845d4c6189c8/raw/shipbuilder-cleanup'
sudo chmod a+x "${target}"
echo "1 * * * * service ntp stop && /usr/sbin/ntpdate 0.pool.ntp.org 1.pool.ntp.org time.apple.com time.windows.com && service ntp start
@jaytaylor
jaytaylor / get_decorators_above_fn.py
Last active August 29, 2015 14:09
Given a function declaration fragment string and a target class, will return the names of any decorators for the function.
# -*- coding: utf-8 -*-
import inspect, string
def get_decorators_above_fn(function_declaration_fragment, class_of_interest, trim_dec_fn_names=False):
"""
Given a function declaration fragment string and a target class, will return the names of any decorators for the
function.
Note: the function_declaration_fragment parameter has .strip() applied to reduce the odds of spacing breaking detection.
@jaytaylor
jaytaylor / WIP--auto-unrar-updated-for-2020.sh
Last active March 18, 2020 18:06
Busy-box compatible automatic RAR extraction system.
#!/usr/bin/env bash
##
#
# @author Jay Taylor [@jtaylor]
#
# @date
#
# @description Busy-box compatible automatic RAR extraction system.
#