Skip to content

Instantly share code, notes, and snippets.

View liddiard's full-sized avatar
🙃

Harrison Liddiard liddiard

🙃
View GitHub Profile
; <<>> DiG 9.8.3-P1 <<>> dailybruin.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 9189
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 0
;; QUESTION SECTION:
;dailybruin.com. IN A
;; AUTHORITY SECTION:
@liddiard
liddiard / location.sh
Last active September 14, 2015 18:35
Bash script to show the current location of the machine you're running on using GeoIP in the format: "City, State, Country".
#!/bin/bash
API_URL="http://freegeoip.net/csv/"
# Get current external IP (http://askubuntu.com/a/95911)
IP=$(curl -s checkip.dyndns.org | sed -e 's/.*Current IP Address: //' -e 's/<.*$//')
LOCATION=$(curl -s ${API_URL}${IP})
echo "$LOCATION" | awk -F "," '{print $6 ",", $5 ",", $3}'
var http = require('http');
var fs = require('fs');
var argv = require('yargs').argv;
var cheerio = require('cheerio');
var DEFAULT_TEMPLATE = "http://uclabruins.com/ViewArticle.dbml?ATCLID=209624560&DB_OEM_ID=30500";
var template = argv.template || DEFAULT_TEMPLATE;
var pageFilename = argv._[0];
<style>
#article-content h1 {
float: left;
margin-right: 1rem;
}
#article-content h2 {
color: #666;
}
@liddiard
liddiard / fullwidth.scss
Last active August 25, 2015 21:43
100 percent screen width element inside a narrower, fixed width container/wrapper element. Useful for things like full-width photos and graphics inside an article text container with fixed width. Works in IE 9+.
.fullwidth {
width: 100vw;
margin-left: calc((100vw - $wrapper_width)/-2);
}
var request = require('superagent');
var React = require('react');
// require('./app.scss');
var API_ROOT = '/api/';
var App = React.createClass({
@liddiard
liddiard / navigator.html
Created May 19, 2015 18:26
Some code I was playing with to inject JavaScript into an iframe
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
</head>
<body>
<style>
iframe {
width: 960px;
var ALL_SPORTS = "[all sports]";
var ALL_YEARS = "[all years]";
var FilterableChampionshipList = React.createClass({
getInitialState: function() {
return {
viewingSport: ALL_SPORTS,
viewingYear: ALL_YEARS
};
},
@liddiard
liddiard / cache_drf_list_view.py
Created April 23, 2015 22:28
Custom full-response caching setup for Django Rest Framework list view where keys are unique URLs. Opted to not continue with the invalidation on model save code cause cache invalidation is hard.
def list(self, request, *args, **kwargs):
# get the base url without any query params
url = request.path
params = []
# build a list of 2-value tuples which contains query params
for key, value in request.GET.iteritems():
params.append((key, value))
if params:
# sort the params so e.g., ?bunny=cute&fox=sly is treated as the
# same key as ?fox=sly&bunny=cute
function astContains(ast, nodeType) {
walk(ast, function(node) {
if (node.type === nodeType)
return true;
});
return false;
}