Skip to content

Instantly share code, notes, and snippets.

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

Дмитрий Hirurg103

🏠
Working from home
View GitHub Profile
@Hirurg103
Hirurg103 / issue_with_joins_in_scopes_in_rails_5_3.rb
Last active July 24, 2019 16:13
Issue with joins in scopes in rails 5.2
begin
require "bundler/inline"
rescue LoadError => e
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler"
raise e
end
gemfile(true) do
source "http://rubygems.org"
gem "activerecord", "5.2.0"
@Hirurg103
Hirurg103 / datepicker-error-example.html
Created October 28, 2018 12:45
Bug with setValue: hours is 1hr less than selected
<!doctype html>
<html>
<head>
<script src="https://rawgit.com/jquery/jquery/1.12.4/dist/jquery.min.js"></script>
<script src="https://rawgit.com/moment/moment/develop/min/moment-with-locales.min.js"></script>
<script src="https://rawgit.com/longbill/jquery-date-range-picker/master/dist/jquery.daterangepicker.min.js"></script>
<link href="https://rawgit.com/longbill/jquery-date-range-picker/master/dist/daterangepicker.min.css" rel="stylesheet"/>
</head>
<body>
@Hirurg103
Hirurg103 / workon.sh
Last active September 3, 2018 14:33
I use this function to navigate between projects
function workon() {
echo "export CURRENT_PROJECT=$1" > ~/.current_project
cd "$HOME/Documents/work/$1"
}
[[ -f ~/.current_project ]] && source ~/.current_project
[[ $CURRENT_PROJECT ]] && cd ~/Documents/work/$CURRENT_PROJECT
# For mysql
SET @id:=1
SELECT id, @num:=@num + 1 AS num
FROM (
SELECT id FROM email_notifications ORDER BY created_at ASC
) AS t
HAVING MOD(num, 101) = 0;
# For postgresql
SELECT id FROM (

Initialize application

gem install rails -v 5.1.2 --no-ri --no-rdoc
rails _5.1.2_ new mysql_lock_wait_timeout_problem
cd mysql_lock_wait_timeout_problem

bundle exec rake db:create
bundle exec rails g model User first_name archived:boolean
bundle exec rails db:migrate
@Hirurg103
Hirurg103 / how_to_optimize.sql
Last active June 11, 2016 09:24
How to optimize this query?
CREATE TABLE clients (
first_name text,
last_name text
);
INSERT INTO clients (first_name, last_name)
(SELECT md5(random()::text) AS first_name, md5(random()::text) AS last_name
FROM (SELECT * FROM generate_series(1,1000000) AS id) AS x);
# trigram index
@Hirurg103
Hirurg103 / install_elasticsearch.sh
Last active June 7, 2016 20:33
Script which installs elasticsearch
sudo apt-get update
sudo apt-get install openjdk-9-jre
wget https://download.elastic.co/elasticsearch/elasticsearch/elasticsearch-2.3.0.deb
sudo dpkg -i elasticsearch-2.3.0.deb
sudo update-rc.d elasticsearch defaults
# remove
function dump() {
time=$(date '+%H_%M_%S');
date=$(date '+%Y_%m_%d');
database=$1;
dumps_dir="$HOME/dumps";
mkdir -p "$dumps_dir/$date";
dumpfile=$dumps_dir/$date/$time"_"$database"_dump".psql.gz
pg_dump $database -W -U ontheway --no-privileges --clean --exclude-table=schema_migrations | gzip > $dumpfile;
class Concord1 < Module
def initialize
define_a
end
def define_a
puts self
define_method :a do | |
puts "a"
end
# install brew
# this will also download and install XCode https://itunes.apple.com/us/app/xcode/id497799835?ls=1&mt=12
# xcode-select --install
sudo -u $USER /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" \ </dev/null
brew update --force
# fix homebrew permissions (see http://stackoverflow.com/questions/16432071/how-to-fix-homebrew-permissions)
# sudo chown -R "$USER":admin /usr/local
# mysql56 (mysql57 )