Skip to content

Instantly share code, notes, and snippets.

@jvans1
jvans1 / artists.erb
Created October 29, 2012 16:38
artist page view
<!DOCTYPE html>
<html>
<head>
<title>Playlister</title>
</head>
<body>
<h1>Ruby Playlister</h1>
<h2>Artists</h2>
<h3><%=@artist_count%></h3>
@jvans1
jvans1 / gist:5188109
Created March 18, 2013 15:44
Joins with ordering solution
#Issues
# THIS WORKS: search = Company.search(:users_orders_line_items_price_gte => "2", :order => :ascend_by_orders_total )
#since there is an association in the ordering, the scope returned from the first conditions runs through the stack and hits the join class creating the
#necessary join. When this happens it creates a new set of joins values for the scope
# so I can call joins_values on scope, choose the last one and order based on that.(...order("orders.total ASC"))
#This don't: search = Company.search(:users_orders_line_items_price_gte => "2", :order => :ascend_by_identifier )
#Since there is no association in the ordering method, it never runs through the 'joins' class. So when I call joins_values
#on the current scope i get backk {:users => {:orders => :line_items}} since the last value is line_item, i obviously don't
app.factory( 'AuthService', function($http, $location, $rootScope) {
return {
login: function(email, password) {
currentUser = $http({method: "POST", url: "/login", params: {email: email, password: password}}).
success(function(data, status){
$rootScope.current_user = data.user
return $location.path("/feed");
}).
error(function(data, status){
return $location.path("/login");
class InvoicePresenter < BasePresenter
def shipping_total(period_start, period_end)
company.invoices.for_period(period_start, period_end ).one_off.sum(:total)
end
end
and then in your view
presenter.shipping_total("11-1-13", "12-1-13")
app.factory('PackageService', function(){
return {
tournamentsToHtml: function(tournaments){
var html = "<table class='table table-tooltip'><tr><td>Tournament</td><td>Markup</td></tr><tbody>"
for (var key in tournaments) {
html += "<tr>" + "<td>" + key + ": " + "</td>" + "<td>" + tournaments[key] + "</td>" + "</tr>"
};
html + "</tbody></table>"
return html
#The point of this method is to try executing a change on CustomField Kind, i.e. changing from string to text.
#since not all custom fields are interchangeable like this (boolean to integer for example) this validation
#executes he query that updates it, forces a rollback by raising an exception, do nothing if the exception was triggered
#by us(the query ran successfully) and then rescue every other exception and assume it's because of incompoatible types
def validate_value_kind_change
if should_migrate_values?
begin
begin
self.class.transaction do
@jvans1
jvans1 / ticket.rb
Last active August 29, 2015 13:57 — forked from dhh/ticket.rb
class Ticket < ActiveRecord::Base
class TicketConfirmer
attr_reader :ticket, :confirmation_errors
delegate :user, :grouper :to => :ticket
def initialize(ticket)
@ticket = ticket
@confirmation_errors = []
end
def can_confirm?
def mode(array)
#Hash.new is good here because the 0 is default for blank values
hash = Hash.new(0)
#Just use an array literal
max = []
array.each {|x| hash[x] += 1 }
hash.select do |key, value|
@jvans1
jvans1 / gist:10119587
Last active August 29, 2015 13:58
errors http interceptor
angular.module('myapp').config([ '$httpProvider', function ($httpProvider) {
$httpProvider.interceptors.push('globalErrorInterceptor');
}]);
angular.module('myapp').factory('globalErrorInterceptor', ['$q', '$rootScope', '$cookieStore', '$injector', '$location', 'PathService', 'AlertService',
function ($q, $rootScope, $cookieStore, $injector, $location, Path, Alert) {
$rootScope.showSpinner = false;
$rootScope.http = null;
return {
'response': function (response) {
return response || $q.when(response)
@jvans1
jvans1 / gist:10119641
Last active December 28, 2020 18:38
Angular Auth Service
angular.module('myApp', []).factory( 'AuthService', ["$cookieStore", '$http',
var currentUser;
return {
login: function(email, password, fn) {
currentUser = //Login work with $http
$cookieStore.put("currentUser", currentUser.name)
},
logout: function(){
//Logout work with $http