Skip to content

Instantly share code, notes, and snippets.

View jeremiahlukus's full-sized avatar

Jeremiah Parrack jeremiahlukus

View GitHub Profile
FacilityInfo = Struct.new(:facility, :pallet_quantity, :case_quantity, :item_quantity)
def index
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
@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)
in view
FacilityStock.where(product_id: @products).select('MAX(id), facilty_stocks.*').group(:product_id).to_sql
=> "SELECT MAX(id), facilty_stocks.* FROM \"facility_stocks\" WHERE \"facility_stocks\".\"product_id\" IN (SELECT DISTINCT \"products\".\"id\" FROM \"products\" WHERE \"products\".\"company_id\" = 10) GROUP BY \"facility_stocks\".\"product_id\""
FacilityStock.where(product_id: @products).select('MAX(id), facilty_stocks.*').group(:product_id).size
{34=>2, 36=>4, 40=>2}
2.4.1 :054 > sql = "SELECT DISTINCT ON (product_id) * FROM facility_stocks WHERE product_id IN (#{@products.pluck(:id).join(', ')}) ORDER BY product_id, created_at DESC"
2 @company.projects.each do |project|
1 @facility_projects = project.facility_projects.where(inactive: false)
21 @facility_projects.each do |fp|
1 @facilities << fp.facility
2 end
3 @inactive_facility_projects = project.facility_projects.where(inactive: true)
4
5 @inactive_facility_projects.each do |fp|
6 @inactive_facilities << fp.facility
7 end
10 jQuery(function() {
9 return $('form').on('click', '.add_fields', function(event) {
8 var regexp, time;
7 time = new Date().getTime();
6 regexp = new RegExp($(this).data('id'), 'g');
5 $(this).before($(this).data('fields').replace(regexp, time));
4 return event.preventDefault();
3 });
2 });
Edit the incomplete C source code to create a linked list to store the birthday information of 6 random students. For each person, the birthday information should include month, day, year, and name.When the module is loaded, traverse through the linked list and output its contentto the kernel log buffer. In addition, write code to identifythe youngeststudentby year (you can define 6 students born in 6 different years.)and remove that student from the list. After removing the youngest student,
output the updated linked list content to the kernel log buffer. In the module exit point, delete the elements from the updated linked list and returnthe free memory back to the kernel.Makesure to output a message to the kernel log buffer every time an element is deleted.
MakeFile
```
obj-m += simple.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
5 describe "POST #create" do
4 describe "with valid params" do
3 it "creates a new inbound order" do
0 inbound_params = FactoryGirl.attributes_for(:inbound_order, documents: [Document.create(name: Faker::App.name, doc: File.new("#{Rails.root}/spec/fixtures/test_file.pdf"))])
1 expect { post :create, :inbound_order => inbound_params }.to change(InboundOrder, :count).by(1)
2 end
3
5 describe "POST #create" do
4 describe "with valid params" do
3 it "creates a new inbound order" do
2 inbound_params = FactoryGirl.attributes_for(:inbound_order)
>> 1 document = Document.create(name: Faker::App.name, doc: File.new("#{Rails.root}/spec/fixtures/test_file.pdf"))
27 inbound_params.documents << document # this is stupid but I need to do the for the inbound order not the params
1 expect { post :create, :inbound_order => inbound_params }.to change(InboundOrder, :count).by(1)
2 end
3
#!/usr/bin/env bash
SCM_THEME_PROMPT_DIRTY=" ${red}✗"
SCM_THEME_PROMPT_CLEAN=" ${bold_green}✓"
SCM_THEME_PROMPT_PREFIX=" ${green}|"
SCM_THEME_PROMPT_SUFFIX="${green}|"
GIT_THEME_PROMPT_DIRTY=" ${red}✗"
GIT_THEME_PROMPT_CLEAN=" ${bold_green}✓"
GIT_THEME_PROMPT_PREFIX=" ${green}|"