Skip to content

Instantly share code, notes, and snippets.

View abates's full-sized avatar

Andrew Bates abates

  • 21:13 (UTC -04:00)
View GitHub Profile
#!/usr/bin/env ruby
def demonstrate ret=false
puts "Before enumeration"
%w(one two three four five).each do |word|
puts "\tWord: #{word}"
return if ret
end
puts "After enumeration"
end

Installation

For anyone who wants to hack with Go tonight, here are some installation suggestions:

Go can be installed in a few different ways. You can install using a package manager or using the Google provided binaries. I prefer to use Go Version Manager which is similar to rvm and nvm. gvm can be installed by following the instructions here

Once gvm is installed it is trivial to install different versions of Go as well as install the cross compilers.

To install Go 1.4.2 (current) simply run:

gvm install go1.4.2
package main
import (
"fmt"
"runtime"
"time"
)
func main() {
runtime.GOMAXPROCS(2)
@abates
abates / stupid_math_problem.rb
Created April 16, 2015 00:36
Stupid Math Problem
#!/usr/bin/env ruby
1 + 1 + 1 + 1 + 1
1 + 1 + 1 + 1 + 1
o = 1 + 1*0 + 1
puts "The result is: #{o}"
# Run this and you'll get:
# The result is: 2
#!/bin/bash
# rshark is a script that will execute tcpdump over ssh
# and pipe the output back to a local wireshark instance.
# This allows viewing of remote packet captures locally
# with the wireshark gui
#
# In order for this script to work, the /usr/sbin/tcpdump
# binary must exist on the remote host and the user
# running the script must have sudo access on the remote host
#
@abates
abates / await.log
Last active January 17, 2022 17:14
(webos) abates@hawkeye:~/local/devel/webos$ python webos.py
2022-01-17 12:13:52 INFO (MainThread) [__main__] Setting up host variables
2022-01-17 12:13:52 INFO (MainThread) [sqlitedict] opening Sqlite table 'unnamed' in '/home/abates/local/devel/webos/.aiopylgtv.sqlite'
2022-01-17 12:13:52 INFO (MainThread) [__main__] Connecting
2022-01-17 12:13:54 INFO (MainThread) [__main__] Failed to connect: TimeoutError
2022-01-17 12:13:59 INFO (MainThread) [__main__] Connecting
2022-01-17 12:14:01 INFO (MainThread) [__main__] Failed to connect: TimeoutError
2022-01-17 12:14:06 INFO (MainThread) [__main__] Connecting
2022-01-17 12:14:07 INFO (MainThread) [__main__] State update {'state': 'Active'}
2022-01-17 12:14:07 INFO (MainThread) [__main__] Connected!

Keybase proof

I hereby claim:

  • I am abates on github.
  • I am abates314 (https://keybase.io/abates314) on keybase.
  • I have a public key ASAvSRTbdBM4dEtpeawRsK2ZpUDKDfoy1oik7l_W_j-sfwo

To claim this, I am signing this object:

@abates
abates / yield_demo.py
Created July 27, 2022 16:51
Demonstrating yield in python3
#!/usr/bin/env python3
data = [
[1, 2, 3, 4, 5],
[6, 7, 8, 9, 10],
[11, 12, 13, 14, 15],
]
def iterate_data():
for row in data:
@abates
abates / main.py
Created June 26, 2023 19:31
Explaining python's operator.attrgetter
#!/usr/bin/env python3
class Three:
def __init__(self, value):
self._value = value
@property
def four(self):
return self._value
@abates
abates / com.omeganetserv.toggleairport.plist
Created January 18, 2024 13:49
Enable/Disable wifi based on wired network connectivity
<!-- Place this file in $HOME/Library/LaunchAgents -->
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.omeganetserv.toggleairport</string>
<key>OnDemand</key>
<true/>
<key>ProgramArguments</key>