Skip to content

Instantly share code, notes, and snippets.

View mchirico's full-sized avatar
💭
Kubernetes... API Server Development

Mike Chirico mchirico

💭
Kubernetes... API Server Development
View GitHub Profile
@mchirico
mchirico / accessLogCombin.sh
Created December 28, 2014 21:12
Awk call in a bash program to list out strings, inclosed in "quotes" as one variable. Below it's assigned to $6.
#!/bin/bash
grep -h 'blog' httpd/data/access*|grep -v '^76.124.247.181'|grep -v 'www.google.com'|grep -v 'spider'|
awk '{
split($0, a, "\"")
$6 = a[2]
$7 = $(NF - 1)
$8 = $NF
printf("%s %s,%s,\"%s\"\n",$4,$5,$1,$6)
}'
@mchirico
mchirico / gist:0bfc84ca3f9a00969bf0
Last active August 29, 2015 14:12
Sample iptables used to reject some ip addresses on port 80. Note that the rules start at the top. Once a connection matches a rule, no more checking it done. So make sure accept rules are at the end.
# Iptables works from top down. So you want to put your accepts last
#
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
# Amazon AWS can block port 22, so keep open.
@mchirico
mchirico / gist:52536ae22841cae5a96d
Created March 5, 2015 11:57
Python curses program ... trying to get something that seems alive
#!/usr/bin/env python
"""
Created by mchirico@gmail.com
"""
import os,time,sys,signal,getopt,popen2,re,curses,datetime,random
import thread,threading
lock = threading.Lock()
@mchirico
mchirico / callDate.awk
Created April 11, 2015 12:34
AWK statement to execute an OS command, in this case the date command, when a particular string is found.
echo "<callDate>"|awk 'BEGIN{cmd="date +%Y-%m-%d_%H:%M:%S"} /<callDate>/{cmd|getline D; close(cmd); print D,$1}'
df.dropna(how='all') #drop only if ALL columns are NaN
df.dropna() #drop all rows that have any NaN values
df.dropna(thresh=2) #Drop row if it does not have at least two values that are **not** NaN
df.dropna(subset=[1]) #Drop only if NaN in specific column
@mchirico
mchirico / pandasCommon00.py
Created May 16, 2015 11:49
Some common commands in Python Pandas: Reading, Changing Headers, Applying function, Dropping Columns, Merge, and Selective csv format output
"""
Some commands in Python Pandas to do the following:
1. Read in a file
2. Get a list of the headers
3. Change a header (rename)
4. Drop one of the headers (just happends to be the one we renamed)
5. Apply a function to each one of the rows
6. Merge it with another DataFrame (pm)
7. Assuming it has a datetime index, write out
@mchirico
mchirico / crime.R
Last active August 29, 2015 14:22
Using Google maps in R.... Kaggle knowledge
# Kaggle knowledge
# Using Google maps
# Adapted from Ben Hamner's code
# Ref https://www.kaggle.com/benhamner/sf-crime/san-francisco-top-crimes-map?scriptVersionId=11462
#
#
library(dplyr)
library(ggmap)
library(ggplot2)
from keras.layers.core import Dense, Activation
model.add(Dense(input_dim=100, output_dim=64, init="uniform"))
model.add(Activation("relu"))
model.add(Dense(input_dim=64, output_dim=64, init="uniform"))
model.add(Activation("softmax"))
model.add(Dense(input_dim=64, output_dim=10, init="uniform"))
model.add(PReLU((hn,)))
@mchirico
mchirico / exampleDropBox.swift
Created June 23, 2015 14:57
Correction to Dropbox Developer blogs...The AppDelegate.swift code in the example always returned false.
/*
The Dropbox Developer blogs example has an error in the code
https://blogs.dropbox.com/developers/2015/05/try-out-swiftydropbox-the-new-swift-sdk-for-dropbox-api-v2/#.VYh2ane5W_4.twitter
*/
// AppDelegate.swift
func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject?) -> Bool {
if let authResult = Dropbox.handleRedirectURL(url) {
@mchirico
mchirico / vowpal_wabbit_ex1.sh
Created June 24, 2015 18:55
vowpal_wabbit: Very simple example...
#!/bin/bash
# First, just build the training set.
echo "1 'example1 | a b c" > train.vw
echo "2 'example2 | x y z" >> train.vw
echo "3 'example3 | a x c" >> train.vw
echo "4 'example4 | x x a" >> train.vw
echo 'Our training set train.vw'
cat train.vw