This file contains hidden or 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
set runtimepath^=~/.vim runtimepath+=~/.vim/after | |
let &packpath = &runtimepath | |
source ~/.vimrc | |
let g:python2_host_prog = '/usr/local/bin/python' | |
let g:python3_host_prog = '/usr/local/bin/python3' |
This file contains hidden or 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 dontGetIt { | |
constructor() { | |
this.foo = 'hello'; | |
} | |
hello() { | |
this.foo; | |
} | |
} |
This file contains hidden or 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 framework7.bundle.js | |
var f7_app = new Framework7({ | |
// App root element | |
root: '#app', | |
// App Name | |
name: 'My App', | |
// App id | |
id: 'com.myapp.test', | |
// Enable swipe panel |
This file contains hidden or 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 AddTriggerForInvoiceAmount < ActiveRecord::Migration[5.1] | |
def change | |
reversible do |dir| | |
dir.up do | |
execute <<-SQL | |
CREATE OR REPLACE FUNCTION calculate_invoice_current_balance() | |
RETURNS trigger AS $calc_invoice_balance$ | |
BEGIN | |
IF (TG_OP = 'DELETE') THEN |
This file contains hidden or 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
products = Product.by_company(current_user.company.slug).includes(:facilities, :total_stocks).distinct(:sku) | |
sql = "SELECT DISTINCT ON (product_id) * FROM facility_stocks WHERE product_id IN (#{@products.pluck(:id).join(', ')}) ORDER BY product_id, created_at DESC" | |
facility_stocks = ActiveRecord::Base.connection.execute(sql) | |
facilities = Facility.all # or whatever conditions you are putting on that | |
# then construct a collection of stuff you want to show in the view. | |
# Basic principle: don't calculate anything in a view unless absolutely necessary | |
# "separation of concerns" helps you know where to look for your logic |
This file contains hidden or 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
# assuming a column called encrypted password, and you need to | |
# get access to the plaintext to do work, put these getters | |
# and setters in your class to magically get what you need | |
def password | |
Base64.decode64(self.encrypted_password) | |
end | |
def password=(string) |
This file contains hidden or 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' | |
RSpec.describe King, type: :class do | |
describe '.valid_move?' do | |
it "should check for valid move for a King" do | |
user = FactoryGirl.create(:user) | |
piece = FactoryGirl.create(:king, user_id: user.id) | |
piece.x = 4; piece.y = 4; piece.color = "white" | |
expect(piece.valid_move?(piece.x+1, piece.y+0)).to eq(true) |
This file contains hidden or 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 King < ChessPiece | |
# King specific methods ... | |
def valid_move?(x_target, y_target) | |
return false if same_location?(x_target, y_target) | |
return false if !in_board?(x_target, y_target) | |
return true if move_single_step?(x_target, y_target) | |
return false | |
end |
This file contains hidden or 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 'pry' | |
class Image | |
def initialize(image) | |
@image = Marshal.load(Marshal.dump(image)) | |
end | |
def output_image | |
@image.each do |x| | |
puts x.join |
This file contains hidden or 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 CycleDetector | |
def initialize(list) | |
@tortoise = list | |
@hare = list.next_node if list | |
end | |
def self.detect(list) | |
self.new(list).detect | |
end |