Skip to content

Instantly share code, notes, and snippets.

View kkirsche's full-sized avatar

Kevin Kirsche kkirsche

View GitHub Profile
@kkirsche
kkirsche / DSL Examples
Last active August 29, 2015 14:19 — forked from egaumer/DSL Examples
# simple match all query with term facet
ejs.Request()
.indices("myindex")
.types("mytype")
.query(ejs.MatchAllQuery())
.facet(
ejs.TermsFacet('url')
.field('url')
.size(20))
@kkirsche
kkirsche / validate_ip.py
Last active August 29, 2015 14:21
For Validating IP Addresses in Python
def is_valid_ipv4(ip):
"""Validates IPv4 addresses.
"""
pattern = re.compile(r"""
^
(?:
# Dotted variants:
(?:
# Decimal 1-255 (no leading 0's)
[3-9]\d?|2(?:5[0-5]|[0-4]?\d)?|1\d{0,2}
@kkirsche
kkirsche / syn-poc.rb
Last active August 29, 2015 14:23 — forked from KINGSABRI/syn-poc.rb
#!/usr/bin/env ruby
# Full Contol on Ethnet, IP & TCP headers. Play with it ;)
# to test it: nc -lvp 4444
# as root: tcpdump -nvvvv 'tcp port 4444' -i wlan0 # change wlan0 to your interface
# or use packetfu to monitor as tcpdump
## cap = PacketFu::Capture.new(:iface => 'wlan0' , :promisc=> true)
## cap.show_live(:filter => 'tcp and port 4444')
# libpcap should be installed
# gem install pcaprub packetfu
@kkirsche
kkirsche / american_flag.exs
Created July 13, 2015 23:07
Print American Flag
defmodule Recursion do
require Integer
# Recursion for star rows
def print_star_row_pair_n_minus_1_times(n) when n <= 1 do
print_row AmericanFlag.star_row(IO.ANSI.white_background)
end
def print_star_row_pair_n_minus_1_times(n) do
print_row AmericanFlag.star_row(IO.ANSI.white_background)
print_row AmericanFlag.star_row(IO.ANSI.red_background)
@kkirsche
kkirsche / config.json
Created July 27, 2015 13:47
Fixed config.json for twbs#16893
{
"vars": {
"@gray-base": "#000",
"@gray-darker": "lighten(@gray-base, 13.5%)",
"@gray-dark": "lighten(@gray-base, 20%)",
"@gray": "lighten(@gray-base, 33.5%)",
"@gray-light": "lighten(@gray-base, 46.7%)",
"@gray-lighter": "lighten(@gray-base, 93.5%)",
"@brand-primary": "darken(#428bca, 6.5%)",
"@brand-success": "#5cb85c",
@kkirsche
kkirsche / TCPDumpDataToFile.sh
Created October 16, 2015 12:44
Use TCP dump to output data to stdout and file
tcpdump -s0 -AX | tee -a filename.extension
@kkirsche
kkirsche / swift_closure_shorthand.swift
Last active March 20, 2017 21:47
Swift Closure Shorthand Syntax
// Closure Shorthand Syntax
// Rule #1: Full closure syntax
[1,2,3,4,5].map({ (i: Int) -> Int in return i * 3 })
// Rule #2: Inferring types from context
[1,2,3,4,5].map({ i in return i * 3 })
// Rule #3: Implicit Returns from Single Expression Closures
[1,2,3,4,5].map({i in i * 3})
let baseURL = NSURL(string: "https://api.forecast.io/forecast/\(forecastAPIKey)/")
let forecastURL = NSURL(string: "60.7142,-80.0064", relativeToURL: baseURL)
let configuration = NSURLSessionConfiguration.defaultSessionConfiguration()
let session = NSURLSession(configuration: configuration)
let request = NSURLRequest(URL: forecastURL!)
let dataTask = session.dataTaskWithRequest(request, completionHandler: {
(data: NSData?, response: NSURLResponse?, error: NSError?) -> Void in
print(data!)
@kkirsche
kkirsche / go_scp.go
Created December 2, 2015 11:27 — forked from jedy/go_scp.go
an example of scp in golang
// https://blogs.oracle.com/janp/entry/how_the_scp_protocol_works
package main
import (
"fmt"
"golang.org/x/crypto/ssh"
)
const privateKey = `content of id_rsa`
<!DOCTYPE html>
<meta charset="utf-8">
<style>
svg {
font: 10px sans-serif;
}
.area {
fill: steelblue;