Skip to content

Instantly share code, notes, and snippets.

View vitalyp's full-sized avatar
💭
HaPpY

Vitaly Pestov ua vitalyp

💭
HaPpY
View GitHub Profile

If you want to revert changes made to your working copy, do this:

git checkout .

If you want to revert changes made to the index (i.e., that you have added), do this. Warning this will reset all of your unpushed commits to master!:

git reset

If you want to revert a change that you have committed, do this:

@vitalyp
vitalyp / koding_mstsc.sh
Last active November 6, 2015 08:49
KodingDesktopServerInstallScript
wget -O Koding_Desktop_Server_Install.sh "https://docs.google.com/feeds/download/documents/export/Export?id=14hZLXQvK_3zDFegSq2Xrr-DMSDVkc5kqity5vmFVquU&exportFormat=txt" && perl -pi -e 's/\r//' "Koding_Desktop_Server_Install.sh" && bash "Koding_Desktop_Server_Install.sh" && echo -e " \033[1;5;36m FINE! Now sudo reboot, and then connect me with mstsc.exe! \033[0m "
@vitalyp
vitalyp / pyramid_matrix.rb
Created October 19, 2015 12:10
pyramid_matrix
def pyramid_matrix n
nums = (0..(n/2.0).ceil-1).map{|m| [[m+1]*([4*n-8*m-4,1].max)] }.flatten
mx, ci, cd = ([!:&]*n*n).each_slice(n).to_a, n, 0
nums.each do |i|
ci = ci - 1
mx[cd][ci] ||= i
if ci == 0 || mx[cd][ci-1]
ci, cd = n - cd - 1, ci
mx = mx.transpose.map(&:reverse)
end
@vitalyp
vitalyp / doPendulum.js
Created March 14, 2015 08:50
Single line Pendulum stroke algorythm
var inc = 1,
slideCount = 30,
slideIndex = 1;
// PENDULUM ANIMATION
// -------------------------------
function doPendulum() {
slideIndex += (inc *= (((slideIndex >= slideCount-1 || slideIndex <= 0 ) && -1) || 1));
}
// where:
@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,
@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 / 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 / test
Created October 1, 2014 23:55
test remote alias
echo "HELLO FROM GITHUB!"
@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:

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]