Skip to content

Instantly share code, notes, and snippets.

View mikhailov's full-sized avatar

Anatoly Mikhaylov mikhailov

View GitHub Profile
SET @db_name = '***';
SELECT
TBname,
CONCAT(LPAD(REPLACE(FORMAT(B.DSize/POWER(102,pw),3),',',''),17,' '),' ', SUBSTR(' KMGTP',pw,1),'B') "Data Size",
CONCAT(LPAD(REPLACE(FORMAT(B.ISize/POWER(102,pw),3),',',''),17,' '),' ', SUBSTR(' KMGTP',pw,1),'B') "Index Size",
CONCAT(ROUND(B.ISize * 100 / B.DSize), ' %') "Percentage",
CONCAT(LPAD(REPLACE(FORMAT(B.TSize/POWER(102,pw),3),',',''),17,' '),' ', SUBSTR(' KMGTP',pw,1),'B') "Table Size"
FROM
(SELECT table_name TBname, data_length DSize, index_length ISize, data_length+index_length TSize
@mikhailov
mikhailov / flattenizer.rb
Last active August 29, 2015 14:26
flatten an array of arbitrarily nested arrays of integers into a flat array of integers (can't use Array#flatten built-in method)
class Flattenizer
def initialize(params)
if params.empty?
raise ArgumentError, 'Data set is empty'
end
if !params.is_a?(Array)
raise TypeError, 'Data set is not an array'
end
@input_array = params
@mikhailov
mikhailov / gist:115918
Created May 22, 2009 03:55
jQuery beatiful code examples by RailsGeek.com
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<style>
div {
position:relative;
}
#images div {
float:left;
@mikhailov
mikhailov / db_indexes.rb
Created November 16, 2009 04:46
DbIndexes - activerecord index handlier
require(File.dirname(__FILE__) + '/../config/environment') unless defined?(Rails)
class DbIndexes
def initialize(app, message = "Database Indexes")
@app = app
@message = message
end
def call env
@mikhailov
mikhailov / gist:238578
Created November 19, 2009 05:59
automate backup and dvd burn
#!/bin/sh
folder=/media/storage/Backup/
file=$folder/backup_$(date +"%Y_%m_%d_%H-%M")
echo 'Change directory and remove files older than 7days'
cd $folder
find *.tgz -mtime +7 |xargs rm
echo 'Backup process...'
if [ -d $folder ]; then
@mikhailov
mikhailov / delayed_job
Created December 3, 2009 11:49
delayed_job handle script
#!/usr/bin/env ruby
require 'rubygems'
require 'daemons'
require 'optparse'
require 'ostruct'
# Daemons sets pwd to /, so we have to explicitly set RAILS_ROOT
RAILS_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
@mikhailov
mikhailov / gist:256747
Created December 15, 2009 06:51
I'm working with 12 desktop workspaces (every app started on his own workspace). Startup script of mine
#!/bin/sh
# Waiting for desktop loaded
sleep 10
wmctrl -o 1500,0 && /opt/google/chrome/google-chrome 2>&1 &
sleep 2
wmctrl -o 3000,0 && opera 2>&1 &
sleep 2
#!/usr/bin/env ruby
require 'rubygems'
require 'daemons'
require 'optparse'
require 'ostruct'
# Daemons sets pwd to /, so we have to explicitly set RAILS_ROOT
RAILS_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
#!/usr/local/bin/ruby
d1=[83,51]
d2=[85,31]
d3=[18,137]
A = d2[0] - d1[0];
B = d2[1] - d1[1];
C = d3[0] - d1[0];
D = d3[1] - d1[1];
Checking the memcached & sphinx running
if $0 == 'script/server'
# Check for memcached
begin
# check if memcached is running; if it is, use that instead of the default memory cache
Timeout.timeout(0.5) { TCPSocket.open("localhost", 11211) { } }
config.cache_store = :mem_cache_store, %w(localhost:11211), { :namespace => 'zimaletto', :timeout => 60 }
$stderr.puts "\033[0;32mUsing memcached on localhost:11211\033[0;34m"
rescue StandardError