Skip to content

Instantly share code, notes, and snippets.

@mitio
mitio / ip-of
Created July 13, 2014 14:09
Resolves a hostname and copies the A DNS record to the clipboard. OS X only.
#!/bin/bash
HOST="$1"
echo "Looking up $HOST..."
IP=`dig $HOST +short`
echo -n $IP | pbcopy
echo "Copied $IP to the clipboard."
@mitio
mitio / convert_trac_wiki_to_markdown.rb
Last active February 14, 2020 09:38 — forked from somebox/convert_trac.rb
Convert Trac Wiki to Markdown
#!/usr/bin/env ruby
# Convert Trac DB Wiki pages to Markdown source files
#
# Usage
#
# 1. Save the file somewhere and make it executable:
# chmod a+rx convert_track_wiki_to_markdown.rb
# 2. Run it like this:
# ./convert_track_wiki_to_markdown.rb /path/to/your/project/db/trac.db
@mitio
mitio / indexes_to_add.sql
Last active December 21, 2020 01:53
OpenCart SQL profiler and indexes for improved speed and page load time. Requires vqMod to be installed. Place it in <project-root>/vqmod/xml/ and that's it. Copy and paste the indexes once in PhpMyAdmin, in the database for your store.
-- Add these to speed up OpenCart
ALTER TABLE `oc_product` ADD INDEX(`date_available`, `status`);
ALTER TABLE `oc_product` ADD INDEX(`status`);
ALTER TABLE `oc_url_alias` ADD UNIQUE(`query`);
ALTER TABLE `oc_product_to_store` ADD INDEX(`store_id`);
ALTER TABLE `oc_category_path` ADD INDEX(`path_id`, `category_id`);
ALTER TABLE `oc_category_path` ADD INDEX(`category_id`, `path_id`);
ALTER TABLE `oc_product_description` ADD INDEX(`language_id`);
ALTER TABLE `oc_category` ADD INDEX (`parent_id`, `status`, `sort_order`);
ALTER TABLE `oc_category` ADD INDEX(`sort_order`);
MRuby::Build.new do |conf|
# load specific toolchain settings
toolchain :gcc
# Use mrbgems
# conf.gem 'examples/mrbgems/ruby_extension_example'
# conf.gem 'examples/mrbgems/c_extension_example' do |g|
# g.cc.flags << '-g' # append cflags in this gem
# end
# conf.gem 'examples/mrbgems/c_and_ruby_extension_example'
@mitio
mitio / rock_paper_scissors_web.rb
Created May 27, 2014 22:04
Rock-paper-scissors implemented in Sinatra
require 'sinatra'
before do
content_type :txt
@moves = {rock: :scissors, paper: :rock, scissors: :paper}
end
get '/play/:move' do
# Be wary when calling #to_sym on random strings!
player_move = params[:move].to_sym
@mitio
mitio / README.md
Last active August 29, 2015 14:01
A custom Capistrano 3.x strategy that allows deployment from a Git subfolder

You can use this strategy to deploy your Rails app properly when it's located in a subfolder in the main repo.

Supports Capistrano 3.x (tested on 3.2.1).

Usage

  1. Place this file in lib/capistrano/git_subfolder_strategy.rb
  2. Add this line to your Capfile: require_relative 'lib/capistrano/git_subfolder_strategy'
  3. In your deploy.rb, set the following:
@mitio
mitio / README.md
Last active August 9, 2018 14:01
A simple init.d script for the psdash tool

Installation (on a Debian machine):

  1. Install psdash
  2. Save the contents of the init.d script in /etc/init.d/psdash and edit it to fit your OS and paths
  3. Make it exectutable: chmod a+rx /etc/init.d/psdash
  4. Run update-rc.d psdash defaults
  5. Start the daemon with /etc/init.d/psdash start

Optionally, setup a proxy pass to psdash's port (TCP 5000) and add some form of authentication there.

@mitio
mitio / memory_cache.js
Last active February 5, 2023 16:23
Simple in-memory JavaScript object cache with a maxAge per key (in seconds) and maxEntries limit (per cache instance).
var MemoryCache = function (options) {
options = $.extend(true, {
maxEntries: null
}, options || {});
var self = this;
var cache = {};
var entries = 0;
var ageOf = function (entry) {
@mitio
mitio / .gitignore
Last active August 29, 2015 13:57
"Quick" script to generate an example schedule for the Rails Girls study groups
.DS_Store
*.csv
@mitio
mitio / test-direct-http-request-to-passenger
Created March 10, 2014 21:33
A quick script to call a Phusion Passenger process directly to assist in debugging server issues.
#!/usr/bin/env ruby
status = `passenger-status -v --show=xml`
pid_to_show = ARGV.first
processes = {}
def extract(tag_name, xml)
if xml =~ /<#{tag_name}>(.*?)<\/#{tag_name}>/s
$1.to_s.strip