Skip to content

Instantly share code, notes, and snippets.

View smapira's full-sized avatar

smapira smapira

View GitHub Profile
@azinazadi
azinazadi / formtastic.rb
Created November 17, 2011 11:19
formtastic cheatsheet
more: https://github.com/justinfrench/formtastic
-> make form for all db columns
<%= semantic_form_for @user do |f| %>
<%= f.inputs %>
<%= f.buttons %>
<% end %>
-> select cols
<%= semantic_form_for @user do |f| %>
@bartlomiejdanek
bartlomiejdanek / .irbrc
Created December 20, 2011 19:23
IRB configuration
# Make gems available
require 'rubygems' if RUBY_VERSION <= '1.9.0'
# http://drnicutilities.rubyforge.org/map_by_method/
require 'map_by_method'
# Dr Nic's gem inspired by
# http://redhanded.hobix.com/inspect/stickItInYourIrbrcMethodfinder.html
require 'what_methods'
@chetan
chetan / yardoc_cheatsheet.md
Last active May 10, 2024 02:53
YARD cheatsheet
@kijtra
kijtra / pref.sql
Created July 9, 2012 07:10
[MySQL] 都道府県をコード⇔文字に相互変換
DELIMITER //
DROP FUNCTION IF EXISTS `PREF`//
CREATE FUNCTION PREF( _STR_ VARCHAR(20)) RETURNS VARCHAR(6)
LANGUAGE SQL NOT DETERMINISTIC READS SQL DATA
BEGIN
DECLARE res VARCHAR(6);
SET res=CASE
WHEN _STR_='1' THEN '北海道'
WHEN _STR_='2' THEN '青森県'
@shunchu
shunchu / convert-seconds-into-hh-mm-ss-in-ruby.rb
Created July 25, 2012 07:58
Convert seconds into HH:MM:SS in Ruby
t = 236 # seconds
Time.at(t).utc.strftime("%H:%M:%S")
=> "00:03:56"
# Reference
# http://stackoverflow.com/questions/3963930/ruby-rails-how-to-convert-seconds-to-time
@tscolari
tscolari / thinking_sphinx.rake
Last active August 22, 2023 20:54
Thinking-Sphinx Run in Foreground Task
namespace :ts do
desc "Run Thinking Sphinx in the foreground (for something like foreman)"
task :run_in_foreground => ['ts:stop', 'ts:index'] do
config = ThinkingSphinx::Configuration.instance
controller = config.controller
unless pid = fork
exec "#{controller.bin_path}#{controller.searchd_binary_name} --pidfile --config #{config.configuration_file} --nodetach"
end
@dchapkine
dchapkine / Docker Snippets
Last active June 7, 2022 12:57
Docker Snippets
# Build
IMAGEID=$(cat /dev/urandom | tr -dc 'a-z0-9' | fold -w 32 | head -n 1) && sudo docker build -t $IMAGEID .
# Run new container
CONTAINER_ID=$(sudo docker run -t -d -p 0.0.0.0:81:80 $IMAGEID)
# Login into running containe. REQUIRES DOCKER >= 1.3
sudo docker exec -it $CONTAINER_ID bash
# !!! DEPRECATED !!! Login into running container. REQUIRES DOCKER < 0.9
  • Dynamic Dispatch
  • Dynamic Method
  • Ghost Methods
  • Dynamic Proxies
  • Blank Slate
  • Kernel Method
  • Flattening the Scope (aka Nested Lexical Scopes)
  • Context Probe
  • Class Eval (not really a 'spell' more just a demonstration of its usage)
  • Class Macros
@mlr
mlr / rspec_rails_cheetsheet.rb
Last active October 26, 2023 14:32 — forked from them0nk/rspec_rails_cheetsheet.rb
Rspec Rails cheatsheet with expect syntax (including capybara matchers)
# Model
expect(@user).to have(1).error_on(:username) # checks whether there is an error in username
expect(@user.errors[:username]).to include("can't be blank") # check for the error message
# Rendering
expect(response).to render_template(:index)
# Redirecting
@coryalder
coryalder / AmazonProduct.swift
Last active October 23, 2019 08:47
Amazon Product Advertising API + Alamofire
//
// AmazonProduct.swift
// Requires SHXMLParser for parsing Amazon's XML responses (https://github.com/simhanature/SHXMLParser)
//
// Created by Cory Alder on 2015-01-11.
// Copyright (c) 2015 Davander Mobile Corporation. All rights reserved.
//
// partly inspired by RWMAmazonProductAdvertisingManager
import Alamofire