Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import subprocess
import sys
import re
import argparse
ZSH=$HOME/.oh-my-zsh
# Set name of the theme to load.
# Look in ~/.oh-my-zsh/themes/
# Optionally, if you set this to "random", it'll load a random theme each
# time that oh-my-zsh is loaded.
ZSH_THEME="robbyrussell"
# Example aliases
# alias zshconfig="mate ~/.zshrc"
@ehayon
ehayon / monitor_latency
Created August 23, 2013 19:13
Monitor the latency to a server (pass IP's in as cli arguments)
#!/bin/bash
PREV_IFS=$IFS;
IFS=$'\n';
HOSTNAME=$(hostname)
ERRORS=();
for ip in ${*}
do
LATENCY=$(ping -c 1 $ip | grep -oEi "time=([0-9.]*)" |awk -F'=' '{print $2}')
@ehayon
ehayon / git_status
Created August 21, 2013 15:04
Show status of all nested git repos in a directory
#!/bin/bash
HIGHLIGHT="\e[01;34m"
NORMAL='\e[00m'
find . -name .git -type d -prune | cut -d. -f2 | while read file
do
STATUS=$(cd .$file; git status);
echo -e '\n'${HIGHLIGHT}$file ${NORMAL}'\n\t'$STATUS
done
@ehayon
ehayon / monitor_du
Last active February 14, 2022 16:34
shell script for monitoring server disk usage
#!/bin/sh
EXCLUDE=( Filesystem devtmpfs tmpfs );
USAGE_THRESHOLD=85;
PREV_IFS=$IFS; # save the old IFS so we can restore it later
IFS="|"; # change the internal field separator to a pipe
EX="${EXCLUDE[*]}"; # join exclude partitions with pipe separator
IFS=$PREV_IFS; # restore IFS
df -h | grep -Ev "^${EX}" | awk '{print $5 " " $1}' | while read output;
@ehayon
ehayon / gist:2606867
Created May 6, 2012 01:30
prim's algorithm
#include "zombies.h"
t_graph *prim(t_graph *graph, int s) {
t_graph *prim;
if(graph != NULL && graph->v > 0 && graph->e > 0) {
prim = new_graph(graph->v);
unsigned int i;
unsigned int j;
int visited[graph->v];
int known;
@ehayon
ehayon / gist:2606837
Created May 6, 2012 01:24
modified dijkstra
#include "zombies.h"
int *dijkstra(t_graph *graph, int s) {
// compute the safest path from starting node s to every other node
// safest path means smallest sum of strength on vertices
// we don't need to worry about the weight of the edges
if(graph != NULL && graph->v > 0) {
int p[graph->v];
int d[graph->v];
int paths[graph->v][graph->v];
@ehayon
ehayon / gist:1425086
Created December 2, 2011 22:18
Koch Snowflake
package recursion;
import cos126.StdDraw;
import java.awt.geom.*;
import java.lang.Math;
public class KochSnowflake
{
public static Point2D.Double ref;
public static int rotation = 0;
max_n1, max_n2, max_prod = 0, 0, 0
for n1 in range(100, 1000):
for n2 in range(100, 1000):
product = str(n2 * n1)
if product == product[::-1]:
if max_prod < int(product):
max_prod = int(product)
max_n1 = n1
max_n2 = n2