Skip to content

Instantly share code, notes, and snippets.

View tdegrunt's full-sized avatar

Tom de Grunt tdegrunt

View GitHub Profile
@njakobsen
njakobsen / live_database_dump.rb
Last active November 5, 2021 02:28
Live stream a database dump (or any other STDOUT) using Rails 4. Why would you want this? If you have a large database dump and want to avoid storing it in memory as Rails streams it. This allows pipe the dump directly into the http response instead of storing it as a file, sending it, and then deleting it. Let me know what you think! I've teste…
class DatabaseController < ApplicationController
def database_dump
database = Rails.configuration.database_configuration[Rails.env]["database"]
send_file_headers!(:type => 'application/octet-stream', :filename => "#{database}_#{Time.now.to_s(:human)}.backup")
pipe = IO.popen("pg_dump '#{database}' -F c")
stream = response.stream
while (line = pipe.gets)
stream.write line
sleep 0.0001 # HACK: Prevent server instance from sleeping forever if client disconnects during download
@Tinghui
Tinghui / HD.txt
Created June 19, 2013 00:46 — forked from lexrus/HD.txt
http://devstreaming.apple.com/videos/wwdc/2013/710xfx3xn8197k4i9s2rvyb/710/710-HD.mov?dl=1
http://devstreaming.apple.com/videos/wwdc/2013/202xdx2x47ezp1wein/202/202-HD.mov?dl=1
http://devstreaming.apple.com/videos/wwdc/2013/200xdx2x35e1pxiinm/200/200-HD.mov?dl=1
http://devstreaming.apple.com/videos/wwdc/2013/413xdx5x97itb5ek4yex3r7/413/413-HD.mov?dl=1
http://devstreaming.apple.com/videos/wwdc/2013/612xax4xx65z1ervy5np1qb/612/612-HD.mov?dl=1
http://devstreaming.apple.com/videos/wwdc/2013/221xex4xxohbllf4hblyngt/221/221-HD.mov?dl=1
http://devstreaming.apple.com/videos/wwdc/2013/220xbx4xipaxfd1tggxuoib/220/220-HD.mov?dl=1
http://devstreaming.apple.com/videos/wwdc/2013/711xcx4x8yuutk8sady6t9f/711/711-HD.mov?dl=1
http://devstreaming.apple.com/videos/wwdc/2013/404xbx2xvp1eaaqonr8zokm/404/404-HD.mov?dl=1
http://devstreaming.apple.com/videos/wwdc/2013/505xbx4xrgmhwby4oiwkrpp/505/505-HD.mov?dl=1
@alex-zige
alex-zige / gist:5795358
Last active June 8, 2023 07:49
Rails Rspec API Testing Notes

Rails Rspec APIs Testing Notes

Folders Structure

  spec
  |--- apis #do not put into controllers folder. 
        |--- your_api_test_spec.rb  
  |--- controllers
  |--- models
  |--- factories
 |--- views
@machty
machty / router-facelift-guide.md
Last active November 11, 2023 06:44
Guide to the Router Facelift

Ember Router Async Facelift

The Ember router is getting number of enhancements that will greatly enhance its power, reliability, predictability, and ability to handle asynchronous loading logic (so many abilities), particularly when used in conjunction with promises, though the API is friendly enough that a deep understanding of promises is not required for the simpler use cases.

@willurd
willurd / web-servers.md
Last active April 28, 2024 21:38
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
@machty
machty / new-router-examples.md
Last active April 16, 2020 22:03
How to do cool stuff with the new Router API
@rgm
rgm / stamp-icon.rb
Last active September 11, 2023 12:40
Add the current version and build number on your iOS app icon
#!/usr/bin/env ruby
# Requires ImageMagick: `brew install imagemagick`
# Requires version.sh from https://gist.github.com/osteslag/1089407
#
# Set RGM_STAMP_VERSION_ON_ICONS=1 in your build settings to enable/disable
# stamping on Debug/Relase configurations.
#
# Make base unstamped versions Icon.base.png, &c. in the source tree. The
# script will make stamped versions Icon.png, &c. It relies on Xcode to copy
static LINES: [ &'static str, ..20 ] = [
"..............3.85..1.2.......5.7.....4...1...9.......5......73..2.1........4...9 near worst case for brute-force solver (wiki)",
".......12........3..23..4....18....5.6..7.8.......9.....85.....9...4.5..47...6... gsf's sudoku q1 (Platinum Blonde)",
".2..5.7..4..1....68....3...2....8..3.4..2.5.....6...1...2.9.....9......57.4...9.. (Cheese)",
"........3..1..56...9..4..7......9.5.7.......8.5.4.2....8..2..9...35..1..6........ (Fata Morgana)",
"12.3....435....1....4........54..2..6...7.........8.9...31..5.......9.7.....6...8 (Red Dwarf)",
"1.......2.9.4...5...6...7...5.9.3.......7.......85..4.7.....6...3...9.8...2.....1 (Easter Monster)",
".......39.....1..5..3.5.8....8.9...6.7...2...1..4.......9.8..5..2....6..4..7..... Nicolas Juillerat's Sudoku explainer 1.2.1 (top 5)",
"12.3.....4.....3....3.5......42..5......8...9.6...5.7...15..2......9..6......7..8",
"..3..6.8....1..2......7...4..9..8.6..3..4...1.7.2.....3....5.....5...6..98.....5."
@pehrlich
pehrlich / full_error_messages.rb
Created February 4, 2013 23:51
Print out full error messages for nested models
module FullErrorMessages
extend ActiveSupport::Concern
# includes errors on this model as well as any nested models
def all_error_messages
messages = self.errors.messages.dup
messages.each do |column, errors|
if self.respond_to?(:"#{column}_attributes=") && (resource = self.send(column))
messages[column] = resource.errors.messages
end
@juliandunn
juliandunn / pgdg.rb
Created January 24, 2013 03:57
Example of PostgreSQL global development group Chef recipe
#
# Cookbook Name:: smpostgresql
# Recipe:: pgdg
#
# Copyright 2012-2013 SecondMarket Labs, LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#