Skip to content

Instantly share code, notes, and snippets.

View etewiah's full-sized avatar

Ed Tee etewiah

View GitHub Profile
@fallwith
fallwith / http_headers_dump.rb
Created January 28, 2011 20:41
Rails controller code to dump raw HTTP headers from a request
logger.warn "*** BEGIN RAW REQUEST HEADERS ***"
self.request.env.each do |header|
logger.warn "HEADER KEY: #{header[0]}"
logger.warn "HEADER VAL: #{header[1]}"
end
logger.warn "*** END RAW REQUEST HEADERS ***"
@JangoSteve
JangoSteve / cache.rake
Created November 17, 2011 03:32
Automatically cache pages in Rails, put this in /lib/tasks/cache.rake
# See rails source:
# https://github.com/rails/rails/blob/master/actionpack/lib/action_controller/caching/pages.rb
#
# Turn on caching in development, by changing this line to true in config/environments/development.rb:
#
# config.action_controller.perform_caching = true
#
# Then run:
#
# bundle exec rake pages:cache
class Marksman < RTanque::Bot::Brain
NAME = 'Marksman'
include RTanque::Bot::BrainHelper
def tick!
command.speed = RTanque::Bot::MAX_SPEED
nearest = nearest_target()
if (!defined?(@direction))
@direction = 0
@cam8001
cam8001 / d8_reset.sh
Last active July 21, 2017 17:09
A reset & reinstall script for Drupal 8 core development.
#!/bin/sh
# Removes an existing Drupal 8 install, then install again.
# Requires Drush 7 - https://github.com/drush-ops/drush
#
# Run this script from the docroot of a Drupal 8 checkout.
# Installs to mysql://localhost/drupal, user 1 user/pass is admin/admin.
if [ ! -e ./core/core.services.yml ]
then
require 'nokogiri'
require 'open-uri'
# Get a Nokogiri::HTML:Document for the page we're interested in...
doc = Nokogiri::HTML(open('http://www.google.com/search?q=tenderlove'))
# Do funky things with it using Nokogiri::XML::Node methods...
####
@goyalankit
goyalankit / bash_to_zsh_history.rb
Last active October 28, 2023 05:07
Import bash history to zsh history.
#################################################################
# = This script transfers bash history to zsh history
# = Change bash and zsh history files, if you don't use defaults
#
# = Usage: ruby bash_to_zsh_history.rb
#
# = Author: Ankit Goyal
#################################################################
# change if you don't use default values
@olivierlacan
olivierlacan / migrate_postgresql_database.md
Last active March 24, 2022 20:30
How to migrate a Homebrew-installed PostgreSQL database to a new major version (9.3 to 9.4) on OS X. See upgraded version of this guide: http://olivierlacan.com/posts/migrating-homebrew-postgres-to-a-new-version/

This guide assumes that you recently run brew upgrade postgresql and discovered to your dismay that you accidentally bumped from one major version to another: say 9.3.x to 9.4.x. Yes, that is a major version bump in PG land.

First let's check something.

brew info postgresql

The top of what gets printed as a result is the most important:

@thijsc
thijsc / screenshots.rake
Last active February 3, 2021 22:38
Example of creating screenshots of your site using Capybara and Selenium, for details: http://blog.appsignal.com/blog/2015/07/21/automated-screenshots-using-capybara.html
BROWSER_WIDTH = 1600
BROWSER_HEIGHT = 1200
Capybara.default_driver = :selenium
include Capybara::DSL
def take_screenshot(path, name, convert_options={})
# Wait for JS to load data and so on
sleep 2
retinafy_screen
@hijonathan
hijonathan / readme.md
Last active September 16, 2019 11:43
Fun in-browser web scraper.

What is this?

This little script lets you easily define a few things you want from a web page (using CSS selectors), the crawl the site until you get them all.

It's based on the way Kimono works, but it's much simpler and has no limit to the number of results you can get. It also uses your auth tokens from the browser, so it's just as secure as your browser (which you should still be suspect of).

How do I use it?

Put that script into your browser terminal and run it. If you use Chrome, I highly recommend saving it as a snippet for easy reuse. To start scraping a site, create a Scraper instance with your desired options:

@henrik
henrik / dokku_on_digital_ocean.md
Last active May 12, 2022 14:38
Notes from running Dokku on Digital Ocean.

My notes for Dokku on Digital Ocean.

These may be a bit outdated: Since I originally wrote them, I've reinstalled on a newer Dokku and may not have updated every section below.

Commands

Install dokku-cli (gem install dokku-cli) for a more Heroku-like CLI experience (dokku config:set FOO=bar).

# List/run commands when not on Dokku server (assuming a "henroku" ~/.ssh/config alias)

ssh henroku dokku