Skip to content

Instantly share code, notes, and snippets.

@davidcaste
davidcaste / inflate_body.lua
Last active November 26, 2024 14:32
Nginx config: receive a request with a gzipped body, inflate it, and pass it to a proxied server
-- Debian packages nginx-extras, lua-zlib required
ngx.ctx.max_chunk_size = tonumber(ngx.var.max_chunk_size)
ngx.ctx.max_body_size = tonumber(ngx.var.max_body_size)
function create_error_response (code, description)
local message = string.format('{"status":400,"statusReason":"Bad Request","code":%d,"exception":"","description":"%s","message":"HTTP 400 Bad Request"}', code, description)
ngx.status = ngx.HTTP_BAD_REQUEST
ngx.header.content_type = "application/json"
ngx.say(message)
@fxn
fxn / gist:427dca61ec44adf8253b
Last active July 2, 2019 18:14
gzip assets with Capistrano
# Compresses all .js and .css files under the assets path.
namespace :deploy do
# It is important that we execute this after :normalize_assets because
# ngx_http_gzip_static_module recommends that compressed and uncompressed
# variants have the same mtime. Note that gzip(1) sets the mtime of the
# compressed file after the original one automatically.
after :normalize_assets, :gzip_assets do
on release_roles(fetch(:assets_roles)) do
assets_path = release_path.join('public', fetch(:assets_prefix))
within assets_path do
@kentcdodds
kentcdodds / package-exact.js
Last active December 7, 2024 14:09
make your package.json dependencies be the exact version that's in your node_modules currently
/* jshint node:true */
/* eslint-env node */
/*
* This will look at the current version of all of your dependencies and update your package.json
* with the specific version that you currently have in node_modules. This will save you from the
* sadness that is: DEPENDENCY MANAGEMENT
*
* Place this file in a folder that's a a sibling to your package.json and node_modules
* Then simply run: node scripts/package-strict
@timothee-alby
timothee-alby / programming_task_short.md
Created October 20, 2015 13:59
Programming Challenge - Overleaf - 2015-10-20

Programming challenge

A natural language time parser

You are a developer on a task manager app. Your users can create tasks and those tasks, in particular, have a time and date.

To provide a enhanced experience to your users upon task creation, you want the task date to be a free text field. A user would input strings such as in 2 days, 3 hours ago, tomorrow, on december 5th at noon, and you would save that information as a date object in the system.

Challenge

@sedm0784
sedm0784 / _vim_auto_list.markdown
Last active March 28, 2025 20:04
Vim Automatic List Continuation

Vim Auto List Completion

This snippet makes Vim automatically continue/end lists in insert mode, similar to the way word processors do:

  • It automatically adds the bullet/number for the next list item when you press Return at the end of an existing item,
  • When you press Return on an empty list item, it removes the bullet/number, ending the list.

It supports ordered lists with markers like 1. and unordered lists with - markers (because those are the markers I use.)

(It's particularly useful when using an iOS keyboard where punctuation and numerals are slow to access.)

" cs'' => will switch surrounding simple/double quotes
" cs'[x] => will delegate to vim-surround
nmap <expr>cs' CSurroundQuotes()
fu! CSurroundQuotes()
let qch = s:findQuote()
let char = s:getChar('Question', 'Exchange quotes with?')
if char == "'"
let char = (qch ==# "\"" ? "'" : "\"") | end
@aroben
aroben / git-commit-editor.vim
Last active November 10, 2024 13:23
Vim script to show git commit diff in vertical split while writing commit messages
" Put this in your .vimrc and whenever you `git commit` you'll see the diff of your commit next to your commit message.
" For the most accurate diffs, use `git config --global commit.verbose true`
" BufRead seems more appropriate here but for some reason the final `wincmd p` doesn't work if we do that.
autocmd VimEnter COMMIT_EDITMSG call OpenCommitMessageDiff()
function OpenCommitMessageDiff()
" Save the contents of the z register
let old_z = getreg("z")
let old_z_type = getregtype("z")
abandoned
able
absolute
adorable
adventurous
academic
acceptable
acclaimed
accomplished
accurate
# Bash best practices and style-guide
Just simple methods to keep the code clean.
Inspired by [progrium/bashstyle](https://github.com/progrium/bashstyle) and [Kfir Lavi post](http://www.kfirlavi.com/blog/2012/11/14/defensive-bash-programming/).
## Quick big rules
* All code goes in a function
* Always double quote variables