Skip to content

Instantly share code, notes, and snippets.

@xionon
xionon / copy_image_files.rb
Last active August 24, 2020 13:54
Simple program to watch a floppy drive (A:) for new disks, and copy the images or files from them
require 'fileutils'
require 'win32-sound'
FILE_UTILS_NOOP = false
IMAGE_TYPES_REGEX = /.(jpg|gif|jpeg|png|mpg)$/i
DOC_TYPES_REGEX = /(?<!mavica).(doc|txt|docx|xls|xlsx|html|htm|zip)$/i
IMAGES_DIRECTORY = "C:/Users/Alec/Documents/floppys/images"
OTHER_DIRECTORY = "C:/Users/Alec/Documents/floppys/docs"
ALWAYS_IGNORE_REGEX = /(System Volume Information|.411|MAVICA.htm)$/i
FAILURE_WAV = "C:/Windows/Media/Windows Hardware Fail.wav"
class PostsController < ApplicationController
def show
@post = Post.find(params[:id])
respond_to do |format|
format.html # GET /posts/1
format.json { render :json => @post } # GET /posts/1.json
end
end
web: bundle exec puma -C config/puma.rb
#! /usr/bin/env sh
# Generate a new, simple sinatra app
# Usage: sinatra-new name_of_app
set -e
dir=$1
mkdir -p $dir/{views,public}
cd $dir
@xionon
xionon / rails_form.js.jsx
Created February 20, 2015 17:01
rails jsx helper
var RailsForm = React.createClass({
propTypes: {
csrf: React.PropTypes.shape({
param: React.PropTypes.string,
token: React.PropTypes.string
}).isRequired
},
getDefaultProps: function() {
return {
@xionon
xionon / gist:f946b27f27c1fbb6eaba
Created June 28, 2014 14:29
Difference between an app generated with active record and an app without active record
diff -r app-with-ar/Gemfile app-without-ar/Gemfile
6,7d5
< # Use sqlite3 as the database for Active Record
< gem 'sqlite3'
diff -r app-with-ar/Gemfile.lock app-without-ar/Gemfile.lock
97d96
< sqlite3 (1.3.9)
123d121
< sqlite3
diff -r app-with-ar/config/application.rb app-without-ar/config/application.rb
# Ensures that we can save a news item and queue up the right jobs around it
class NewsSaveService
def self.save!(news)
new(news).save!
end
def initialize(news)
@news = news
end
@xionon
xionon / routes.rb
Created June 9, 2014 18:51
Namespaced url, un-prefixed method
namespace 'manage', as: '' do
resources :programs
end
#----
$ rake routes
Prefix Verb URI Pattern Controller#Action
programs GET /manage/programs(.:format) manage/programs#index
POST /manage/programs(.:format) manage/programs#create
class ApplicationController < ActionController::Base
# see: http://guides.rubyonrails.org/action_controller_overview.html#rescue-from
rescue_from ApiKey::NotAuthorized, with: :api_key_not_authorized
rescue_from ActiveRecord::RecordNotFound, with: :record_not_found
private
# see: http://guides.rubyonrails.org/layouts_and_rendering.html#options-for-render
def record_not_found
render file: '404.html', status: :not_found
module Foo
def run
puts 'Does the thing'
end
end
class Bar
include Foo
end