Skip to content

Instantly share code, notes, and snippets.

View vitalyp's full-sized avatar
💭
HaPpY

Vitaly Pestov ua vitalyp

💭
HaPpY
View GitHub Profile
@vitalyp
vitalyp / main.rb
Created July 30, 2012 12:42
spreadsheet_alignments
require 'spreadsheet'
class DailyOrdersXlsFactory
#formats:
@@simple_format = Spreadsheet::Format.new :color => :black, :weight => :normal, :size => 10
@@title_format = Spreadsheet::Format.new :color => :black, :weight => :bold, :size => 14, :vertical_align => :center, :horizontal_align => :center
@@total_format = Spreadsheet::Format.new :color => :black, :weight => :bold, :vertical_align => :center, :horizontal_align => :right
@@price_format = Spreadsheet::Format.new :color => :black, :vertical_align => :center, :horizontal_align => :center
@@price_title_format = Spreadsheet::Format.new :color => :black, :vertical_align => :center, :horizontal_align => :right, :weight => :bold
@vitalyp
vitalyp / test.rb
Last active December 17, 2015 10:58
# My Simple Test Suite. For '4Eki'.
class Test
require_relative 'test_suite'
include TestSuite
def test_true
assert_true([].size == 0)
end
def test_eq
assert_equal([].size, 0)
class CreatePrices < ActiveRecord::Migration
def change
create_table :prices do |t|
t.integer :price
t.integer :old_price
t.string :name
end
end
end
-----------------------------------------------
function pop_console() {
document.getElementsByTagName("body")[0].innerHTML='<div id="popconsole" style="width: 100%; height: 130px; z-index: 10000; text-size: 10px; font-family: monospace; color: white; overflow: scroll; opacity: 0.5; position: fixed; bottom: 0px; left: 0px; background: rgb(3, 10, 41);"></div>'+document.getElementsByTagName("body")[0].innerHTML;
}
var console = {};
var console_counter = 100;
console.log = function(text){
console_counter = console_counter + 1;
document.getElementById('popconsole').innerHTML = document.getElementById('popconsole').innerHTML + "<br/><font style='color: green'>"+console_counter+"> </font>" + text;
}
console.info = function(text){

ONCE UPON A TIME, AT STACKOVERFLOW

BACKGROUND: I'm on edge Rails (4.1.0.rc1). Users has many Communities through CommunityUser model. The following users belong to various communities:

USERS TABLE
ID | COMMUNITY_IDS
---|--------------
1  | [2, 7, 8]
2  | [3, 4, 8]

3 | [4, 5, 7]

@vitalyp
vitalyp / gist:35d87b123c5efbd05918
Last active August 29, 2015 14:07
shell backup alias
# EXPORT VARIABLES
export PROJECTS_PATH=~/dev/current
export MASTER_PROJECT_NAME=ultimate-proto
export MASTER_PROJECT_PATH=$PROJECTS_PATH/$MASTER_PROJECT_NAME
# STARTUP ALIASES
cd $MASTER_PROJECT_PATH
##################
# PROJECT BACKUPER:
@vitalyp
vitalyp / test
Created October 1, 2014 23:55
test remote alias
echo "HELLO FROM GITHUB!"
@vitalyp
vitalyp / crc32.rb
Created October 16, 2014 23:17
How to calculate 32 bit CRC in Ruby on rails
[vitalyp]:~/dev/current/ultimate-proto on develop_prototype_listing*
$ irb
2.1.2 :001 > require 'zlib'
=> true
2.1.2 :002 > crc32 = Zlib::crc32('input field value')
=> 1873826587
2.1.2 :003 > crc32 = Zlib::crc32('input field ')
=> 1511246425
2.1.2 :004 > crc32 = Zlib::crc32('a')
=> 3904355907
@vitalyp
vitalyp / .append_to_.bashrc_file.bash
Last active August 29, 2015 14:16
Koding Rails automize script
##################################################################
# Koding awesome Rails-script (c). Append it to your .bashrc file, in home directory.
# To start rails server manually you need to enable rvm initially:
# /bin/bash --login
# Then, navigate you Rails project directory, and start app server:
# cd ~/Applications/projectPath;
# rvm gemset use projectRvm;
# rails server -b 0.0.0.0
# Lets automize this process!
##################################################################
@vitalyp
vitalyp / scraper.py
Created March 14, 2015 02:29
Scraping LinkedIn Public Profiles for Fun and Profit
#!/usr/bin/python
#
# Copyright (C) 2012 Itzik Kotler
#
# scraper.py is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# scraper.py is distributed in the hope that it will be useful,