Skip to content

Instantly share code, notes, and snippets.

View dannycroft's full-sized avatar

Danny Croft dannycroft

View GitHub Profile
@dannycroft
dannycroft / .eslintrc
Created July 14, 2015 10:47
Formatting and validation for node apps
{
"env": {
"browser": true,
"node": true,
"amd": true
},
"rules": {
"no-console": 2,
"no-comma-dangle": 2,
@dannycroft
dannycroft / .vimrx
Created January 14, 2016 15:17
Temp vimrc
set nocompatible
set t_Co=256
filetype off
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Bundle 'gmarik/Vundle.vim'
@dannycroft
dannycroft / roles.js
Created April 27, 2016 16:24
User roles & routing demo
function requireRole(role) {
return function(req, res, next) {
if (req.session.user && req.session.user.role === role) {
next();
else {
res.send(403);
}
}
}
@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
@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 / 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 / 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 / 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 / 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 / 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