Let's say you want to host domains first.com
and second.com
.
Create folders for their files:
# Upgrade all packages including Kernel | |
sudo dnf upgrade | |
# Install Nvidia drivers | |
dnf install dnf-plugins-core -y | |
sudo dnf install dnf-plugins-core -y | |
dnf copr enable t0xic0der/nvidia-auto-installer-for-fedora -y | |
sudo dnf copr enable t0xic0der/nvidia-auto-installer-for-fedora -y | |
sudo dnf install nvautoinstall -y |
# Understanding FP in Ruby | |
class Counter | |
def initialize | |
@count = 0 | |
end | |
def call | |
@count += 1 | |
end | |
end |
# https://stackoverflow.com/questions/24397640/rails-nested-includes-on-active-records | |
# I believe the following should work for you. | |
Event.includes(users: :profile) | |
# If you want to include an association (we'll call it C) of an already included association (we'll call it B), you'd use the syntax above. However, if you'd like to include D as well, which is also an association of B, that's when you'd use the array as given in the example in the Rails Guide. | |
A.includes(bees: [:cees, :dees]) | |
# You could continue to nest includes like that (if you actually need to). Say that A is also associated with Z, and that C is associated to E and F. |
# Recursively diff two hashes, showing only the differing values. | |
# By Henrik Nyh <http://henrik.nyh.se> 2009-07-14 under the MIT license. | |
# | |
# Example: | |
# | |
# a = { | |
# "same" => "same", | |
# "diff" => "a", | |
# "only a" => "a", | |
# "nest" => { |
https://codepen.io/P1N2O/pen/pyBNzX |
class Hashit | |
def initialize(hash) | |
hash.each do |k,v| | |
self.instance_variable_set("@#{k}", v.is_a?(Hash) ? Hashit.new(v) : v) | |
self.class.send(:define_method, k, proc{self.instance_variable_get("@#{k}")}) | |
self.class.send(:define_method, "#{k}=", proc{|v| self.instance_variable_set("@#{k}", v)}) | |
end | |
end | |
end |
# initializers/active_record_initializers.rb | |
class ActiveRecord::Base | |
# do not accept a column_name from the outside without sanitizing it | |
# as this can be prone to sql injection | |
def self.starts_with(column_name, prefix) | |
where("lower(#{column_name}) like ?", "#{prefix.downcase}%") | |
end | |
end | |
# User.starts_with('name', 'ab').limit(1) |
I'm hunting for the best solution on how to handle keeping large sets of DB records "sorted" in a performant manner.
Most of us have work on projects at some point where we have needed to have ordered lists of objects. Whether it be a to-do list sorted by priority, or a list of documents that a user can sort in whatever order they want.
A traditional approach for this on a Rails project is to use something like the acts_as_list
gem, or something similar. These systems typically add some sort of "postion" or "sort order" column to each record, which is then used when querying out the records in a traditional order by position
SQL query.
This approach seems to work fine for smaller datasets, but can be hard to manage on large data sets with hundreds (or thousands) of records needing to be sorted. Changing the sort position of even a single object will require updating every single record in the database that is in the same sort group. This requires potentially thousands of wri
require 'httparty' | |
require 'jwt' | |
require 'digest' | |
require 'securerandom' | |
require 'json' | |
class Skype | |
def initialize | |
@key = 'b97dfb72-1504-fadd-1b04-05efc186aaeb' |