This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Thing.find_by!(id: 123, state: "pending").state #=> "approved" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SloppyHash | |
def [](k) | |
memory[k] ||= SloppyHash.new | |
end | |
def []=(k,v) | |
memory[k] = v | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module RecursiveKeyCheck | |
def recursive_key?(key) | |
return true if key?(key) | |
self.each do |_, v| | |
if v.is_a?(Hash) | |
return true if v.recursive_key?(key) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('#btnbtnbtn').on('click', function(e) { | |
var res = $('#res').val(); | |
var sum= $('#sumThis').val(); | |
var ress=res+sum; | |
$('#res').val(ress); | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Routedraw | |
def self.define_api_routes(routes: Rails.application.routes, | |
version: :v1, | |
&block) | |
routes.draw do | |
namespace :api, defaults: { format: :json } do | |
namespace version do | |
# yield self to pass the current context to the block | |
yield self | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(1..5).each do |i| | |
f = File.open("somefile#{i}.txt") | |
begin | |
do_stuff_with(f) | |
rescue | |
next | |
ensure | |
f.close | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Person { | |
private String mName; | |
public Person() {} | |
public void setName(String mName) { this.mName = mName; } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper' | |
shared_examples "extended_definition" do | |
it "must contain original definition" do | |
expect(sense.extended_definition).to include(sense.definition) | |
end | |
it "must contain both sample texts" do | |
expect( | |
sense.samples.pluck(:sample).collect { |t| sense.extended_definition.include? t }.inject(:&) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
... | |
:user_hash => Proc.new { |current_user| | |
OpenSSL::HMAC.hexdigest( | |
"sha256", | |
"ENV['intercom_secret']", | |
current_user.id.to_s | |
) | |
}, | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rails_helper' | |
class ApplicationController < ActionController::Base | |
rescue_from ActiveRecord::RecordNotFound, with: :not_found | |
rescue_from Pundit::NotAuthorizedError, with: :permission_denied | |
rescue_from ActionController::UnknownFormat, with: :unknown_format | |
private | |
def permission_denied |