Skip to content

Instantly share code, notes, and snippets.

@tbutts
tbutts / tmux-migrate-options.py
Last active November 27, 2024 08:29
For tmux configs: Merge deprecated/removed -fg, -bg, and -attr options into the -style option
#!/usr/bin/env python
# vim: set fileencoding=utf-8
#
# USAGE:
# Back up your tmux old config, run the script and redirect stdout to your conf
# file. Example:
#
# $ cp ~/.tmux.conf ~/.tmux.conf.orig
# $ python ./tmux-migrate-options.py ~/.tmux.conf.orig > ~/.tmux.conf
#
@DavidWells
DavidWells / aws-lambda-redirect.js
Created June 28, 2018 20:48
How to do a 301 redirect from an AWS lambda function
exports.handler = (event, context, callback) => {
const response = {
statusCode: 301,
headers: {
Location: 'https://google.com',
}
};
return callback(null, response);
}
@nrollr
nrollr / nginx.conf
Last active February 22, 2025 10:42
NGINX config for SSL with Let's Encrypt certs
# UPDATED 17 February 2019
# Redirect all HTTP traffic to HTTPS
server {
listen 80;
listen [::]:80;
server_name www.domain.com domain.com;
return 301 https://$host$request_uri;
}
# SSL configuration
@dcode
dcode / GitHub Flavored Asciidoc (GFA).adoc
Last active February 6, 2025 22:08
Demo of some useful tips for using Asciidoc on GitHub

GitHub Flavored Asciidoc (GFA)

@kaikuchn
kaikuchn / benchmark.rb
Last active December 7, 2015 08:47
bulk insert benchmark
#!/usr/bin/env ruby
require 'benchmark'
require File.expand_path('../config/environment', __FILE__)
begin
@list = (0..10_000).map{|i| {word: "word_#{i}", word_translation: "translation_#{i}"}}
@vocabulary_1 = Vocabulary.create(user_id: User.first.id, title: "Vocabulary #1")
@vocabulary_2 = Vocabulary.create(user_id: User.first.id, title: "Vocabulary #2")
@vocabulary_3 = Vocabulary.create(user_id: User.first.id, title: "Vocabulary #3")
@renegare
renegare / gulp-karma.js
Last active March 28, 2018 05:37
Gulp Karma Integration
/**
* testing tasks (using karma to test in the browser). Requires a karma.conf.js for full config
* single-run testing
* continuous testing
*/
/** base deps, but you may need more specifically for your application */
var gulp = require('gulp');
var gutil = require('gulp-util');
var path = require('path');
@willurd
willurd / web-servers.md
Last active February 28, 2025 17:17
Big list of http static server one-liners

Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.

Discussion on reddit.

Python 2.x

$ python -m SimpleHTTPServer 8000
@runemadsen
runemadsen / description.markdown
Created September 26, 2011 15:23
Reverse polymorphic associations in Rails

Polymorphic Associations reversed

It's pretty easy to do polymorphic associations in Rails: A Picture can belong to either a BlogPost or an Article. But what if you need the relationship the other way around? A Picture, a Text and a Video can belong to an Article, and that article can find all media by calling @article.media

This example shows how to create an ArticleElement join model that handles the polymorphic relationship. To add fields that are common to all polymorphic models, add fields to the join model.

@bobthecow
bobthecow / tab.bash
Last active November 10, 2023 08:47
Open new Terminal tabs from the command line
#!/bin/bash
#
# Open new Terminal tabs from the command line
#
# Author: Justin Hileman (http://justinhileman.com)
#
# Installation:
# Add the following function to your `.bashrc` or `.bash_profile`,
# or save it somewhere (e.g. `~/.tab.bash`) and source it in `.bashrc`
#