Skip to content

Instantly share code, notes, and snippets.

View abhionlyone's full-sized avatar
:octocat:
Focusing

Abhilash Reddy abhionlyone

:octocat:
Focusing
View GitHub Profile
# 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
@abhionlyone
abhionlyone / fp.rb
Created January 10, 2020 10:22
Understanding functional programming in Ruby.
# Understanding FP in Ruby
class Counter
def initialize
@count = 0
end
def call
@count += 1
end
end
@abhionlyone
abhionlyone / includes.rb
Created May 3, 2019 07:06
Rails includes for nested active-record associations
# 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.
@abhionlyone
abhionlyone / hash_deep_diff.rb
Created February 5, 2019 06:06 — forked from henrik/hash_deep_diff.rb
Recursively diff two Ruby hashes.
# 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" => {
@abhionlyone
abhionlyone / Pure CSS3 Gradient Background Animation
Created November 15, 2018 12:41
Pure CSS3 Gradient Background Animation
https://codepen.io/P1N2O/pen/pyBNzX
@abhionlyone
abhionlyone / hash_it.rb
Created October 10, 2018 16:07
Ruby - Convert a Hash into Object
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
@abhionlyone
abhionlyone / active_record_initializers.rb
Created August 31, 2018 11:08
Activerecord name starts with
# 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)
@abhionlyone
abhionlyone / letsencrypt_2018.md
Created August 18, 2018 13:50 — forked from cecilemuller/letsencrypt_2020.md
How to setup Let's Encrypt for Nginx on Ubuntu 18.04 (including IPv6, HTTP/2 and A+ SSL rating)

How to setup Let's Encrypt for Nginx on Ubuntu 18.04 (including IPv6, HTTP/2 and A+ SLL rating)


Virtual hosts

Let's say you want to host domains first.com and second.com.

Create folders for their files:

@abhionlyone
abhionlyone / gist:129ed753031bdb534016cf1be5a5bb10
Created August 14, 2018 08:12 — forked from cpjolicoeur/gist:3590737
Ordering a query result set by an arbitrary list in PostgreSQL

I'm hunting for the best solution on how to handle keeping large sets of DB records "sorted" in a performant manner.

Problem Description

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'