Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env ruby
repo_path = File.expand_path('../../', __FILE__)
cache_file_path = File.join(repo_path, '/tmp/cached_routes')
cache_mtime = File.exists?(cache_file_path) && File.mtime(cache_file_path)
highest_routes_mtime = (Dir[File.join(repo_path,'/config/routes/**')] + [File.join(repo_path,'config/routes.rb')]).map { |f| File.mtime(f) }.max
if !cache_mtime || highest_routes_mtime > cache_mtime
`#{File.join(repo_path,'bin/rake')} routes > #{cache_file_path}`
puts `cat #{cache_file_path}`
else
import { ApiResponse } from "apisauce"
export type GeneralApiProblem =
/**
* Times up.
*/
| { kind: "timeout"; temporary: true }
/**
* Cannot connect to the server for some reason.
*/
@gotmayonase
gotmayonase / parallel_csv.rb
Last active June 16, 2017 03:57
Process a CSV file in parallel using threads
require 'fileutils'
require 'csv'
class ParallelCSV
attr_accessor :threads, :header_line, :opts
def initialize(file_path, opts = {})
@threads = opts.delete(:threads) || 2
headers = opts.delete(:headers)
if headers
@gotmayonase
gotmayonase / about-page?locale=en-CA
Created January 20, 2016 17:13
Localization Example
<h1>What's all this aboot?</h1>
class Segment < ActiveRecord::Base
extend ActsAsTree::TreeView
extend ActsAsTree::TreeWalker
belongs_to :course
belongs_to :section_type
has_and_belongs_to_many :chunks, join_table: 'chunks_segments'
acts_as_tree order: 'rank'
$('.glyphicon-check').map(function(i, e) {
var $e = $(e)
var variant = $e.parents('.variant');
var snippet = $e.parents('.snippet');
var variant_name = $(variant).find('.variant-name').val();
var snippet_name = $(snippet).find('.panel-title').clone().children().remove().end().text();
return snippet_name + '--' + variant_name;
function updateCSS(){
$ss.css({
'border-width' : borderWidthString(),
'border-image' : borderImageString()
})
}
function borderWidthString() {
return //whatever builds that string here
}
function win(delay) {
if($('#box span').length >= 4) {
var clicker = $('span','#box').filter(function(e) { return $(this).data('type') == 'a'; })
clicker.click();
setTimeout(win, delay)
}
}
var list_template = _.template('\
<% if(items != null) { %> \
<% split_items = items.split(",") %> \
<% for (var i = 0; i < split_items.length; i++) { %> \
<li><%= split_items[i] %></li> \
<% } %> \
<% } %> \
');
class CreateCalendarTable < ActiveRecord::Migration
def up
create_table :calendar, id: false do |t|
t.date "_date"
t.string :month_name
t.integer :month_no
t.integer :year
t.integer :day
t.integer :day_of_week
t.integer :day_of_year