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
@IlkhamGaysin
IlkhamGaysin / postgres_in_another_pid.md
Last active March 2, 2017 06:32
postgres check running in another pid

OSX Mavericks has been crashing randomly recent to me. Just very random. Not quite good because it doesn't give it the chance for processes like Postgres, etc... to shut down properly, leaving process ids (PIDs) behind.

Now got this issue where my postgres won't boot up.

Running postgres manually doesn't work

> pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
> pg_ctl: another server might be running; trying to start server anyway
So here's a quick fix.
require 'rails_helper'
RSpec.describe TodosController, :type => :controller do
context "GET index" do
#context "POST create" do
#context "GET show" do
#context "PATCH update" do (or PUT update)
#context "DELETE destroy" do
#context "GET new" do
@IlkhamGaysin
IlkhamGaysin / remove_all_gems_from_gemfile.md
Created June 3, 2016 20:51
allow remove all gems one by one

for i in `gem list --no-versions`; do gem uninstall -aIx $i; done

@IlkhamGaysin
IlkhamGaysin / gist:85b179e09fba41f7b40954376daa99f1
Created June 4, 2016 13:31 — forked from lttlrck/gist:9628955
rename git branch locally and remotely
git branch -m old_branch new_branch # Rename branch locally
git push origin :old_branch # Delete the old branch
git push --set-upstream origin new_branch # Push the new branch, set local branch to track the new remote
@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).

@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

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

class FlatArray
  attr_reader :nested_array, :result

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

 def call
@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

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