Skip to content

Instantly share code, notes, and snippets.

View dannycroft's full-sized avatar

Danny Croft dannycroft

View GitHub Profile
@dannycroft
dannycroft / mergesort.elm
Created March 7, 2017 19:02
Elm - Mergesort
import Html exposing (text)
main =
text (toString (mergesort [5,3,8,1,9,4,7]))
{-| Sorts a list of values by:
1. If the list has zero or one element, it is sorted!
2. If it is longer, split it into two sublists
3. Sort those sublists
@dannycroft
dannycroft / quicksort.elm
Created March 7, 2017 19:00
Elm - Quicksort
import Html exposing (text)
main =
text (toString (quicksort [5,3,8,1,9,4,7]))
quicksort : List comparable -> List comparable
quicksort list =
case list of
[] ->
[]
npm config set cache-min 9999999
CACHE ALL THE THINGS!!!
─────────────────────────────▄██▄
─────────────────────────────▀███
────────────────────────────────█
───────────────▄▄▄▄▄────────────█
──────────────▀▄────▀▄──────────█
──────────▄▀▀▀▄─█▄▄▄▄█▄▄─▄▀▀▀▄──█
@dannycroft
dannycroft / repeat.js
Created February 1, 2017 17:58
Example alternative approach to String.prototype.repeat
String.prototype.repeat = function(n) {
const str = this;
return Array.apply(null, Array(n)).map(() => str).join('');
}
// "foo".repeat(3)
// foofoofoo
@dannycroft
dannycroft / flattenArray-test.js
Last active January 26, 2017 19:05
Flatten multi-dimensional array. Run the tests here: http://codepen.io/dannycroft/full/wgrmQo/
var flattenArray = require('../flattenArray');
describe("flattenArray()", function(){
it("should return an array", function() {
var test = flattenArray([1,2,3]);
expect(test).to.be.an('array');
expect(test.length).to.equal(3);
});
@dannycroft
dannycroft / hide.scss
Created July 25, 2016 14:12
Hide classes for Semantic UI
/* Mobile */
@media only screen and (max-width: 767px) {
[class*="mobile hidden"],
[class*="tablet only"]:not(.mobile),
[class*="computer only"]:not(.mobile),
[class*="large screen only"]:not(.mobile),
[class*="widescreen only"]:not(.mobile),
[class*="or lower hidden"] {
display: none !important;
@dannycroft
dannycroft / ip-track.sql
Created June 21, 2016 11:07
Sumologic Track IP
_sourceCategory=Apache/Access
| parse regex "(?<client_ip>\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})"
| parse regex "[A-Z]+ (?<url>.+) HTTP/1.1"
| where client_ip = "166.94.146.84"
| timeslice 1m
| count as hits by url, _timeslice
| transpose row _timeslice column url
@dannycroft
dannycroft / ip-frequency.sql
Created June 21, 2016 11:07
Sumologic IP Frequency
_sourceCategory=Apache/Access
| parse regex "(?<client_ip>\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})"
| timeslice 1m
| count as hits by _timeslice, client_ip
| transpose row _timeslice column client_ip
@dannycroft
dannycroft / bots.sql
Created June 21, 2016 11:05
Sumologic Find Bots
_sourceCategory=Apache/Access
| parse regex "\"[A-Z]+\s+\S+\s+HTTP/[\d\.]+\"\s+\S+\s+(?<size>\d+)\s+\S+\s+\"(?<agent>[^\"]+?)\""
| parse regex field=agent "(?<bot_name>facebook)externalhit?\W+" nodrop
| parse regex field=agent "Feedfetcher-(?<bot_name>Google?)\S+" nodrop
| parse regex field=agent "(?<bot_name>PaperLiBot?)/.+" nodrop
| parse regex field=agent "(?<bot_name>TweetmemeBot?)/.+" nodrop
| parse regex field=agent "(?<bot_name>msn?)bot\W" nodrop
| parse regex field=agent "(?<bot_name>Nutch?)-.+" nodrop
| parse regex field=agent "(?<bot_name>Google?)bot\W" nodrop
| parse regex field=agent "Feedfetcher-(?<bot_name>Google?)\W" nodrop
@dannycroft
dannycroft / install.sh
Created May 7, 2016 10:43
Install DynamoDB locally on Ubuntu
sudo apt-get install openjdk-7-jre-headless -y
cd /home/user/
mkdir -p dynamodb && cd dynamodb
wget http://dynamodb-local.s3-website-us-west-2.amazonaws.com/dynamodb_local_latest
tar -xvzf dynamodb_local_latest
mv dynamodb_local_latest/ dynamodb/
cat >> dynamodb.conf << EOF