Skip to content

Instantly share code, notes, and snippets.

@sorokadima
sorokadima / test_controller.rb
Created June 12, 2020 08:36
Rails test controller
class TestController < ApplicationController
require 'colorize'
def index
result = Rails.env
puts result.class.to_s.colorize(:color => :black, :background => :green)
puts result.to_s.colorize(:color => :black, :background => :yellow)
render text: result
end
end
@sorokadima
sorokadima / Ruby Rails Faraday Request Log.rb
Last active August 11, 2020 14:25
Ruby Rails Faraday Request Log
con = Faraday.new(url: url, params: {}, headers: headers) do |faraday|
faraday.response :logger, nil, { headers: true, bodies: true }
faraday.adapter Faraday.default_adapter
end
if method_type == 'post'
con.post do |req|
req.body = request_body
end
else
@sorokadima
sorokadima / Media Queries.md
Last active June 1, 2020 06:16
Media Queries

Small only

@media screen and (max-width: 39.9375em) {}

Medium and up

@media screen and (min-width: 40em) {}

Medium only

@media screen and (min-width: 40em) and (max-width: 63.9375em) {}

Large and up

@sorokadima
sorokadima / Ruby rest client log.rb
Created May 27, 2020 09:05
Ruby rest client log (rest-client, restclient)
require 'rest-client'
RestClient.log =
Object.new.tap do |proxy|
def proxy.<<(message)
puts message
end
end
@sorokadima
sorokadima / yii2 recompile assets.md
Created May 26, 2020 12:29
yii2 recompile assets

Remove all content from web/assets/

BASH

sudo rm -rf web/assets && mkdir web/assets && sudo chmod -R 777 web/assets
@sorokadima
sorokadima / REST response format: success error.md
Created May 26, 2020 12:27
REST response format: success / error
@sorokadima
sorokadima / JSON MySql.md
Last active May 20, 2020 09:12
JSON mysql - find in mysql by json field (sql, json, JSON_EXTRACT, order, select, yii2, yii)

select

select * from cars WHERE JSON_EXTRACT(data, "$.color") = 'red';

order

select * from cars ORDER BY JSON_EXTRACT(data, "$.color") DESC;

@sorokadima
sorokadima / PHPStorm hotkeys.md
Last active May 18, 2020 08:30
PHPStorm hotkeys (rubymine hotkeys, idea hotkeys)

Collapsing all methods/functions

CTRL + SHIFT + numpad -

The Structure popup

Ctrl+F12

@sorokadima
sorokadima / codeception funcitonal.md
Last active May 15, 2020 14:05
codeception (php-unit, php unit, testing, test, тестування, тест, тестирование, codecept debug)

codecept debug

codecept_debug($I->grabTextFrom('body'));

before run testing

public function _before(\FunctionalTester $I)
{
	$I->amOnPage(['en/account/register']);
}
@sorokadima
sorokadima / Yii2 tests.md
Created May 11, 2020 15:48
Yii2 tests (run test Yii2, codecept, codeception, phpunit, php unit, php-unit)

codecept

vendor/bin/codecept run unit

php-unit

run single test vendor/bin/phpunit --filter testActionIndexMyFormSubmit tests/unit/MyControllerTest.php

vendor/bin/phpunit tests/unit/