Skip to content

Instantly share code, notes, and snippets.

View cfeduke's full-sized avatar

Charles Feduke cfeduke

View GitHub Profile
@cfeduke
cfeduke / DumbSpamFilter.js
Last active October 3, 2022 16:30
Gmail spam is entirely out of control in 2022
// hah silly human # is for Python comments!
// created in Google Apps Script and scheduled to run every minute
function processInboxEmailSubjects() {
var threads = GmailApp.search("is:unread newer_than:1d -label:spam")
Logger.log("Examining " + threads.length + " threads for spam by checking the subject line")
for (var i = 0; i < threads.length; i++) {
var subject = threads[i].getFirstMessageSubject()
const regex = /confirmation#/i
let isSpam = regex.test(subject)
// TODO other tests as necessary for your particular spam hell
@cfeduke
cfeduke / aliases
Created January 28, 2015 13:40
find-java-class
find-java-class () {
find . -name '*.jar' -type f -exec sh -c "jar -tf {} | grep -H --label {} \"$1\.class$\"" \;
}
@cfeduke
cfeduke / bin_deploy
Last active August 29, 2015 14:14
Scala Spark with sbt-assembly example configuration
#!/usr/bin/env bash
set -o nounset
set -o errexit
readonly default_env="${0#*-}"
readonly ENV=${1:-$default_env}
readonly JAR_NAME="your-analytics.jar"
readonly UPLOAD_JAR=`dirname $0`/../target/scala-2.10/$JAR_NAME
@cfeduke
cfeduke / ShardedJdbcRDD.scala
Last active August 29, 2015 14:14
JDBC RDD for Spark when data is pre-sharded across databases.
package org.apache.spark.rdd
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
@cfeduke
cfeduke / netsh
Created November 18, 2014 15:21
Generate command for forwarding Windows local port to OSX host for accessing OSX hosted web application as localhost
#!/usr/bin/env bash
# Prints out the Windows netsh command necessary to port forward on localhost to another
# IP address. Especially useful when testing IE11 with APIs like Google Maps that only
# permit localhost connectivity but the actual server is on your local OSX host machine
# usage:
# netsh [interface] [port]
#
# e.g.,
@cfeduke
cfeduke / patch-osx-bash-3.2
Last active August 29, 2015 14:06
Recompile and install OSX bash from Apple's source code archives with GNU patches applied (to prevent shellshock vulnerability)
# from https://gist.github.com/JonRowe/8f128cbfca40d61547bc with comments for 2nd patch
# original script author JonRow, 2nd patch script: rwebler
# recommend running these commands manually from Terminal, requires sudo for install
# you can:
# curl -L _this-url_ | sh
# if you are lazy
mkdir /tmp/bash-fix
cd cd /tmp/bash-fix
curl https://opensource.apple.com/tarballs/bash/bash-92.tar.gz | tar zxf -
cd bash-92/bash-3.2
Next Time Someone Claims To Be
An 'Engineer,' Give Them This Test.
Engineering is so trendy these days that everybody
wants to be one. The word "engineer" is greatly
overused. If there's somebody in your life who you
think is trying to pass as an engineer, give him this
test to discern the truth.
ENGINEER IDENTIFICATION TEST
You walk into a room and notice that a picture is
hanging crooked. You...
; Joy of Clojure pp85-86
(defn neighbors
([size yx] (neighbors [[-1 0] [1 0] [0 -1] [0 1]] size yx))
([deltas size yx]
(filter (fn [new-yx]
(every? #(< -1 % size) new-yx))
(map #(map + yx %) deltas))))
; usage
(def matrix
@cfeduke
cfeduke / add-hostname-to-etc-hosts.sh
Created January 7, 2014 15:45
Adds hostname to /etc/hosts (place in /etc/rc.local).
#!/bin/bash
HOSTNAME=`hostname`
ETC_HOSTS=/etc/hosts
if ! grep $HOSTNAME $ETC_HOSTS > /dev/null ; then
if grep "127.0.0.1" $ETC_HOSTS > /dev/null ; then
sed -i "s/127\.0\.0\.1.*$/& $HOSTNAME/" $ETC_HOSTS
else
echo "127.0.0.1 localhost $HOSTNAME" >> $ETC_HOSTS
fi
@cfeduke
cfeduke / prepare-logs-for-ami.sh
Created January 7, 2014 15:43
Clears the log file drive in preparation to create an AMI. Place in /root.
#!/bin/sh
LOG_DIR=/var/log/trafficland
find $LOG_DIR -type d -print0 | while IFS= read -r -d '' dir
do
rm $dir/*.log > /dev/null 2>&1
done