This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # simple match all query with term facet | |
| ejs.Request() | |
| .indices("myindex") | |
| .types("mytype") | |
| .query(ejs.MatchAllQuery()) | |
| .facet( | |
| ejs.TermsFacet('url') | |
| .field('url') | |
| .size(20)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "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", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| tcpdump -s0 -AX | tee -a filename.extension |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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!) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <meta charset="utf-8"> | |
| <style> | |
| svg { | |
| font: 10px sans-serif; | |
| } | |
| .area { | |
| fill: steelblue; |