Skip to content

Instantly share code, notes, and snippets.

View mtso's full-sized avatar
shipping

Matthew mtso

shipping
View GitHub Profile
@mtso
mtso / Printfln.go
Created January 8, 2018 07:40
Print formatted line in go.
package fmt
import "fmt"
func Printfln(format string, args ...interface{}) {
fmt.Printf(format + "\n", args...)
}
@mtso
mtso / gemsize.sh
Created December 30, 2017 22:23
bash function to find size of ruby gem
gemsize(gemname) {
curl -s https://rubygems.org/api/v1/gems/$gemname.yaml | sed -n "s/gem_uri: //p" | xargs curl -sLI | grep Content-Length | tail -1
}
# Removes all newlines and whitespace-only lines from a file
minify(filename) {
echo $(cat $filename | grep -v '^[[:space:]]*$') > $filename
}
import { Component } from 'react';
import { withRouter } from 'react-router-dom';
class ScrollToTop extends Component {
componentDidUpdate(prevProps) {
if (this.props.location !== prevProps.location) {
window.scrollTo(0, 0)
}
}
@mtso
mtso / middleware.js
Created December 18, 2017 02:17
Node.js and AWS: redirect HTTP to HTTPS
// Expected possible values:
// X-Forwarded-Proto: https,http,http,http,http
// X-Forwarded-Proto: http,http,http,http,http
// X-Forwarded-Proto: https
// X-Forwarded-Proto: http
// X-Forwarded-Proto: wss
export default (req, res, next) => {
const protos = req.get('X-Forwarded-Proto')
const clientToLb = protos && protos.split(',')[0]
@mtso
mtso / request.js
Created December 11, 2017 04:50
HTTP Client Request Promise
const http = require('http')
function Request(options, body) {
return new Promise((resolve, reject) => {
const onSuccess = function(res) {
let buffer = []
res.setEncoding('utf8')
res.on('data', function(chunk) {
@mtso
mtso / Select.jsx
Created December 6, 2017 19:07
Select component using UIKit UITable scrolling logic
// Select is a drop-in replacement for HTML <select> elements for
// React apps. It uses table UI components to simulate the quick
// rendering of components that scroll into view.
class Select extends Component {
}
class TableView extends Component {
}
@mtso
mtso / rename-plaintext.sh
Last active December 1, 2017 02:40
Bash: Script to rename all plaintext substrings with sed
find . -type f -print0 | xargs -0 sed -i "" 's/DiffNameTwo/DiffNameThree/g'
find . -type f | xargs sed -i '' 's/DiffNameTwo/DiffNameThree/g'
find . -type f -exec rename 's/DiffNameTwo/DiffNameThree/g' {} \;
perl -pi -w -e 's/DiffNameTwo/DiffNameThree/g;' ./*
@mtso
mtso / bulletin.sql
Created November 23, 2017 20:34
Funnel app SQL scripts
SELECT
b.id,
b.url,
b.archive_url,
b.summary,
t.name as tag,
b.date
FROM
bulletin b
INNER JOIN
@mtso
mtso / App.java
Last active November 18, 2017 03:04
Connect-style route handler registration sketch
/*
* This Java source file was generated by the Gradle 'init' task.
*/
public class App {
public String getGreeting() {
return "Hello world.";
}
public static void main(String[] args) {