Skip to content

Instantly share code, notes, and snippets.

View andrewvc's full-sized avatar

Andrew Cholakian andrewvc

View GitHub Profile
import { journey, step, monitor, expect } from '@elastic/synthetics';
import { request } from 'playwright-core'
journey('My Example Journey', ({ page, params, context }) => {
// Only relevant for the push command to create
// monitors in Kibana
monitor.use({
id: 'example-monitor',
@andrewvc
andrewvc / wsl2net-fix.ps1
Created August 6, 2019 01:51
Attempt to fix networking issues described in https://github.com/microsoft/WSL/issues/3438
# Attempt to fix broken network in WSL2.0
$guest_ip = bash -c "/sbin/ifconfig eth0 | egrep -o 'inet [0-9\.]+' | cut -d ' ' -f2"
Write-Output "Guest IP IS: $guest_ip"
$gateway_ips = Get-NetIPAddress -InterfaceAlias "vEthernet (WSL)" | select IPAddress
$gateway_ip = $gateway_ips[1].IPAddress
Write-Output "Gateway (local WSL adapter) IP is: $gateway_ip"
bash -c "sudo ifconfig eth0 netmask 255.255.240.0"
bash -c "sudo ip route add default via $gateway_ip"
@andrewvc
andrewvc / gist:54b54193fb7c69e75281c3b88d4e6f1c
Created October 1, 2021 18:55
Running Beats arm on x86`
# Follow the instructions on https://www.stereolabs.com/docs/docker/building-arm-container-on-x86/
Then run
docker run --rm -it --user root --platform linux/arm64/v8 --entrypoint=/bin/bash -i docker.elastic.co/beats/elastic-agent:7.15.0-arm64
@andrewvc
andrewvc / preg_avgs_shell.sh
Created September 30, 2012 17:26
Thinking Stats first exercise, using shell instead of python
#!/bin/sh
split_cmd='cut -b 275,276,277,278,279 2002FemPreg.dat'
first_avg=`$split_cmd | grep '1 1$' | cut -b 1,2 | awk '{s += $1} END { print s/NR }'`
other_avg=`$split_cmd | grep -v ' 1$' | grep '1..$' | cut -b 1,2 | awk '{s += $1} END { print s/NR }'`
hours_diff=`echo "($first_avg-$other_avg)*168" | bc`
echo First borns: $first_avg weeks
echo Non-first borns: $other_avg weeks
echo Difference: $hours_diff hours
@andrewvc
andrewvc / elastic_search_crash_course.md
Last active November 2, 2020 06:24
Elastic Search Crash Course for LA Hacker News

#elasticsearch Crash Course!

By Andrew Cholakian

What is elasticsearch?

  1. A way to search... things
  2. A way to search your data in terms of natural language, and so much more
  3. A distributed version of lucene with a JSON API.
  4. A fancy clustered database
@andrewvc
andrewvc / count-clj-sloc.sh
Created July 23, 2012 04:19
Counting SLOC in clojure is pretty easy since the syntax is so simple.
# Count SLOC
export SLF=`mktemp -t cljsloc`; find src test -name "*.clj" | xargs egrep -v "(^[[:space:]]*$|^[[:space:]]*;)" | cut -d: -f1 > $SLF && echo "Files"; uniq -c $SLF; echo "Total" `cat $SLF | wc -l`; rm $SLF
@andrewvc
andrewvc / elasticsearch.conf
Created October 3, 2013 17:05
Upstart script for elasticsearch on ubuntu.... that actually works. Install the deb, and then run `sudo update-rc.d elasticsearch remove -f` to disable the init script.
# ElasticSearch upstart script
description "ElasticSearch service"
start on (net-device-up
and local-filesystems
and runlevel [2345])
stop on runlevel [016]
@andrewvc
andrewvc / iptables_rules
Created May 13, 2010 21:34
Simple iptables rules presets
*filter
# Internal interfaces
-A INPUT -i lo -j ACCEPT
-A OUTPUT -o lo -j ACCEPT
#Allow all established traffic
-A INPUT -m state --state ESTABLISHED -j ACCEPT
#SSH
filter {
ruby {
code => "io = StringIO.new(event.get('message')); enum = io.each_line; enum.next; event.set('mydate', enum.next); io.close"
}
}
input { generator {} }
filter {
ruby {
# Add a \t (tab) by using its ASCII code (9)
code => 'event.set("message", 9.chr + event.get("message"))'
}
ruby {
# Make a new field with the tab removed
code => 'event.set("tabless", event.get("message").gsub(9.chr, ""))'