Skip to content

Instantly share code, notes, and snippets.

@itsmikeq
itsmikeq / gist:3943515
Created October 24, 2012 03:31
Sinatra quick download script
require 'sinatra'
require 'rubygems'
require "dm-migrations"
require 'sinatra-authentication'
require 'sinatra/authorization'
download_base = './Downloads'
set :authorization_realm, "download"
configure do
set :template_engine, :erb # for example
end
@itsmikeq
itsmikeq / IssueResource.rb
Created January 6, 2013 17:36
Class for connecting to remote Redmine Instance
class IssueResource < ActiveResource::Base
self.element_name = "issue"
self.user="admin"
self.password="admin"
self.site = "http://localhost:3000"
end
@itsmikeq
itsmikeq / gist:5752955
Last active December 18, 2015 08:19
Accessing an Atom feed behind Site Minder
#!perl
#
# Example script to connect to an ATOM feed behind SiteMinder
# Usage: feed_parser.pl <username> <password> <url>
# URL Can also be copied and pasted from the Atom feed link at the bottom
# of any project
#
#
use strict;
@itsmikeq
itsmikeq / API.swift
Last active August 29, 2015 14:12 — forked from higepon/API.swift
//
// API.swift
//
// Created by Taro Minowa on 6/10/14.
// Copyright (c) 2014 Higepon Taro Minowa. All rights reserved.
//
import Foundation
typealias JSONDictionary = Dictionary<String, AnyObject>
package main
import (
"fmt"
"math"
)
type ErrNegativeSqrt float64
func (e ErrNegativeSqrt) Error() string {
package main
import (
"golang.org/x/tour/reader"
)
type MyReader struct{}
type MyError string
// TODO: Add a Read([]byte) (int, error) method to MyReader.
package main
import (
"io"
"os"
"strings"
)
type rot13Reader struct {
rot io.Reader
@itsmikeq
itsmikeq / collapsed-bootstrap-nav.scss
Created June 11, 2015 14:27
bootstrap css for collapsed navbar
body {
padding-top:70px;
}
.navbar-header {
float: none;
}
.navbar-toggle {
display: block;
}
@itsmikeq
itsmikeq / LocalStorage.js
Created August 30, 2015 01:39
JavaScript local storage
Storage.prototype.setObject = function (_key, _value) {
return this.setItem(_key, JSON.stringify({timestamp: new Date().getTime(), data: _value }));
};
// Clears stuff older than 2 hours
Storage.prototype.clearOld = function () {
_t_date = new Date().getTime();
for (var i = 0; i < Storage.prototype.length; i++) {
if ((_t_date - this.key(i).timestamp) > 7200) {
this.removeItem(this.key(i));
@itsmikeq
itsmikeq / live_database_dump.rb
Last active September 11, 2015 20:01 — forked from njakobsen/live_database_dump.rb
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