Skip to content

Instantly share code, notes, and snippets.

@anithri
anithri / nameMaker.js
Last active September 29, 2019 20:33
nameMaker.js utililty
// nameMaker.js
const cc = require('change-case')
const inflection = require('inflection')
const suffixer = {
get: function(target, prop, _receiver) {
if (target.hasOwnProperty(prop)) return target[prop]
if (prop[0] === prop[0].toLowerCase()) {
return `${target.name}${cc.pascal(prop)}`
# 2018-01-16 by Scott P
# Created by https://www.gitignore.io/api/node,ruby,rails,jekyll,rubymine,serverless
### Jekyll ###
_site/
.sass-cache/
.jekyll-metadata
### Node ###
# Logs
@anithri
anithri / rspec failure error
Created March 12, 2013 21:43
Having an issue with rspec should_recieve().with.ordered
1) Ruzo::Crm#get_records should get more than 1 slice for counts over @max_records
Failure/Error: crm.should_receive(:get_record_slice).with("Contacts",{from:1, to: 4}).ordered
#<Ruzo::Crm:0x00000002e2f980> received :get_record_slice with unexpected arguments
expected: ("Contacts", {:from=>1, :to=>4})
got: ("Contacts", {:from=>1, :to=>8}), ("Contacts", {:from=>5, :to=>12})
# ./spec/crm_spec.rb:88:in `block (4 levels) in <top (required)>'
@anithri
anithri / results.md
Last active December 12, 2015 02:58
trying to figure out normdist

expected result in from excel function where =(NORMDIST(test,0,1,FALSE)) * 2.506628274631

actual result from (Normdist.normdist(test, 0 , 1, false) * 2.50663).round(4)

test value expected Actual
0 1.0 1.0
0.05 0.9988 0.9753
0.1 0.995 0.9512
0.15 0.9888 0.9277
@anithri
anithri / model.rb
Created February 1, 2013 22:53
active_record model generator template Inserted comments to help keep models organized
<% module_namespacing do -%>
class <%= class_name %> < <%= parent_class_name.classify %>
#extends
#includes
#security
<% if !accessible_attributes.empty? -%>
attr_accessible <%= accessible_attributes.map {|a| ":#{a.name}" }.sort.join(', ') %>
<% else -%>
@anithri
anithri / controller_spec.rb
Last active December 12, 2015 01:58
rspec scaffold/controller_spec template based o n Everyday Rails Testing with Rspec
require 'spec_helper'
describe <%= controller_class_name %>Controller do
# This should return the minimal set of attributes required to create a valid
# <%= class_name %>. As you add validations to <%= class_name %>, be sure to
# update the return value of this method accordingly.
def valid_attributes
attributes_for(:<%= file_name %>)
end
@anithri
anithri / gist:3881265
Created October 12, 2012 20:15
Match only projects that have all of the given project_types
class Project < ActiveRecord::Base
has_and_belongs_to_many :project_types
scope :has_any_project_types, ->(*project_types) do
joins(:project_types).
where("project_types.id IN (?)", project_types)
end
scope :has_all_project_types, ->(*project_types) do
joins(:project_types).
@anithri
anithri / addendum_grid.yml
Created April 25, 2012 21:03
Configuration piece for jqgrid_rails
#app/grids/addendum_grid.yml
---
:grid:
:dom_id: "addendums_grid"
:caption: "Addendums"
:pager_options:
:core:
:edit: true
:search: false
:add: true
@anithri
anithri / clause.rb
Created March 7, 2012 23:33
operations dispatch?
def clause(op, field, data)
out = []
out << ops_table[op][:field_proc].call(field)
out << ops_table[op][:data_proc].call(data)
out
end
#later
model.where(*clause(op, field, data))
@anithri
anithri / exception.rb
Created February 16, 2012 05:04
Toying with an idea for exception handling.
module MyModule
class MyModuleError < StandardError
@@ignore = :warn
def ok_to_ignore?
@@ignore
end
def self.ok_to_ignore
@@ignore