Skip to content

Instantly share code, notes, and snippets.

View IlkhamGaysin's full-sized avatar
🏠
Working from home

Ilkham Gaysin IlkhamGaysin

🏠
Working from home
View GitHub Profile
class ContentSuggestionEnqueuer
  def self.enqueue
    User.where(subscribed: true).pluck(:id).each do |user_id|
      ContentSuggestionWorker.perform_async(user_id)
    end
  end
end

To count objects in current thread you can use this approach.

class OtherKlass
end

OtherKlass.new
OtherKlass.new

ObjectSpace.each_object(OtherKlass){} # => 2
@IlkhamGaysin
IlkhamGaysin / SCSS.md
Created February 27, 2017 14:58 — forked from jareware/SCSS.md
Advanced SCSS, or, 16 cool things you may not have known your stylesheets could do

⇐ back to the gist-blog at jrw.fi

Advanced SCSS

Or, 16 cool things you may not have known your stylesheets could do. I'd rather have kept it to a nice round number like 10, but they just kept coming. Sorry.

I've been using SCSS/SASS for most of my styling work since 2009, and I'm a huge fan of Compass (by the great @chriseppstein). It really helped many of us through the darkest cross-browser crap. Even though browsers are increasingly playing nice with CSS, another problem has become very topical: managing the complexity in stylesheets as our in-browser apps get larger and larger. SCSS is an indispensable tool for dealing with this.

This isn't an introduction to the language by a long shot; many things probably won't make sense unless you have some SCSS under your belt already. That said, if you're not yet comfy with the basics, check out the aweso

@IlkhamGaysin
IlkhamGaysin / carrierwave-base64.md
Created February 24, 2017 14:56 — forked from shrikanthkr/carrierwave-base64.md
Saving base64 string with Carrierwave

In the controller action

image_file = change_img_params(params[:avatar]) #params[:avatar] - base64 string

def change_img_params(img)
begin
  Base64.decode64(img) #To check if thats a base64 string
  if img
    img = file_decode(img.split(',')[1],"some file name") #getting only the string leaving out the data/<format>

end

apt-cache policy MY_PACKAGE - get list of available version or like this apt-cache madison MY_PACKAGE

@IlkhamGaysin
IlkhamGaysin / gist:de0b4182e025878819ce9b336842943c
Created February 6, 2017 12:43 — forked from atcuno/gist:3425484ac5cce5298932
HowTo: Privacy & Security Conscious Browsing

The purpose of this document is to make recommendations on how to browse in a privacy and security conscious manner. This information is compiled from a number of sources, which are referenced throughout the document, as well as my own experiences with the described technologies.

I welcome contributions and comments on the information contained. Please see the How to Contribute section for information on contributing your own knowledge.

Table of Contents

class FlatArray
  attr_reader :nested_array, :result

  def initialize(nested_array = [])
    @nested_array = nested_array
    @result = []
  end

 def call

Transactions

As your business logic gets complex you may need to implement transactions. The classic example is a bank funds transfer from account A to account B. If the withdrawal from account A fails then the deposit to account B should either never take place or be rolled back.

Basics

All the complexity is handled by ActiveRecord::Transactions. Any model class or instance has a method named .transaction. When called and passed a block, that block will be executed inside a database transaction. If there's an exception raised, the transaction will automatically be rolled back.

Example

@IlkhamGaysin
IlkhamGaysin / cucumber_dynamic_end.md
Created September 15, 2016 14:28
cucumber step with dynamic the end

Cucumber step with dynamic the end:


When(/^I enter (\d+)(?:st|nd|rd|th) record/) do |n|
  # my interations
end
@IlkhamGaysin
IlkhamGaysin / skpe_group_chat.md
Created August 19, 2016 10:09
Skype - Unable to receive group chat messages

I was having the same problem. Ubuntu 14,04 here. I found this answer in a forum that solved the problem for me.

After struggling a bit, I found some useful commands. You can type these in any skype chat window.

/dumpmsnp - show details about your connection

/showplaces - show where you are currently connected

What was happening was that /dumpmsnp command was showing "LoggedOut", but I was online and talking almost normally (except group chats).