Skip to content

Instantly share code, notes, and snippets.

@scttymn
scttymn / vim-cucumber.vim
Created August 17, 2011 03:39
Run a cuke in vim without ansi colors
"
" Vim Cucumber
"
" To install, put this in your .vim directory and source it.
" If you use Janus, place in your .vim/plugins directory and restart vim
function! Cuke()
let cmd = "cucumber --no-color %"
execute ":! " . cmd
endfunction
@scttymn
scttymn / gist:1283177
Created October 13, 2011 02:18
Hack the counter_cache
# activerecord/lib/active_record/associations/builder/belongs_to.rb automagically creates
# the private methods for you if you include counter_cache in your belongs_to association.
# We simply override the basic behavior of these with our own conditions.
#
# For more information, check out:
# https://github.com/rails/rails/blob/733bfa63f5d8d3b963202b6d3e9f00b4db070b91/activerecord/lib/active_record/associations/builder/belongs_to.rb
# Lines 23 - 44
class Inventory < ActiveRecord::Base
belongs_to :user, counter_cache:true
module PgSearchable
def self.included(base)
base.extend(ClassMethods)
end
module ClassMethods
def searchable_on(*args)
@@search_columns = args
end
@scttymn
scttymn / gist:4059912
Created November 12, 2012 15:16
Angularize
#application.html.haml
%html(ng-app)
#event.js
function EventCtrl($scope){
$scope.current_user = {
name: "Scotty Moon",
email: "scotty@ovenbits.com"
}
<!DOCTYPE html>
<html lang="en" ng-app>
<head>
<meta charset="utf-8">
<title>Sinatra JSON API Example</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.js"></script>
<script src="/controllers.js"></script>
</head>
<body ng-controller='ThingController'>
function ThingController($scope, $http) {
var baseUrl = 'http://sinatra-api-example.scottymoon.c9.io';
$http.get(baseUrl + '/things').success(function(data) {
$scope.things = data;
});
$scope.create = function(thing) {
$http.post(baseUrl + '/things', thing).success(function(thing){
$scope.things.unshift(thing);
public class MainActivity extends Activity implements View.OnClickListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
Button clickMe = (Button) findViewById(R.id.button_name);
clickMe.setOnClickListener(this);
}
@Override
public void onClick(View view) {
@scttymn
scttymn / 0_reuse_code.js
Created January 20, 2014 19:17
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@scttymn
scttymn / sample page output
Last active August 29, 2015 13:57
Page CMS output
{
"total_pages": 5,
"page": {
"number": 1,
"content": [
{
"type": "text",
"value": "Aliquam ut dui eu purus ultrices mollis. Nullam mattis, leo vitae accumsan rhoncus, nisl urna tincidunt lacus, ac fermentum ante neque at metus. Sed at eros hendrerit, lacinia augue et, facilisis velit. Praesent est metus, faucibus id mi quis, aliquet tempus urna. Suspendisse pellentesque <b>leo ut ligula luctus</b> ultrices. Sed at ultrices velit. In et leo turpis. Duis accumsan ante non nunc elementum, vitae dapibus metus pellentesque. Cras id tempor eros. Vivamus et scelerisque eros, sit amet laoreet lorem. <br/> Curabitur nisi nulla, congue et enim et, iaculis dictum lacus. Mauris id libero neque. Nulla condimentum dignissim nunc rhoncus mattis. Sed pellentesque nec ante at aliquam. Aliquam et dignissim ante. Sed sed tellus non turpis lacinia rutrum sit amet sit amet ligula. Integer enim mauris, ornare ut dapibus in, tempor ac justo. Donec condimentum sit amet metus eget euismod. Donec hen
@scttymn
scttymn / nerdy-coffee.rb
Created July 29, 2014 16:19
Nerdy Coffee Recipe
#/usr/bin/ruby
WATER = 22.2593
WATER_MEASUREMENT = "ml"
COFFEE = 0.04493
COFFEE_MEASUREMENT = "g"
def get_water_weight(coffee)
(coffee.to_f * WATER).ceil.to_s + WATER_MEASUREMENT
end