Skip to content

Instantly share code, notes, and snippets.

View dibayendu's full-sized avatar

Dibayendu Dey dibayendu

View GitHub Profile
@dibayendu
dibayendu / move-vm-to-server.md
Created July 12, 2017 16:24
Moving VirtualBox VM to server

Moving VirtualBox VM to server

Modifying guest VM before moving to server

  1. Install ssh server on guest machine - sudo apt-get install openssh-server
  2. Add ssh port VBoxManage modifyvm <myserver> --natpf1 "ssh,tcp,,8022,,22" ssh -p 38022 [email protected]
  3. Remove usb drive settings (except mouse) from VM.
  4. Export Appliance.
@dibayendu
dibayendu / cpp_standard.cpp
Created April 5, 2017 10:21
Determines the version or standard of C++ compiler
#include <iostream>
int main(){
#if __cplusplus==201402L
std::cout << "C++14" << std::endl;
#elif __cplusplus==201103L
std::cout << "C++11" << std::endl;
#elif __cplusplus==199711L
std::cout << "C++07" << std::endl;
#else

Installing googletest in OSX.

Make sure brew is installed.

$ mkdir /usr/local/Cellar/googletest
$ mkdir /usr/local/Cellar/googletest/1.8.0
$ cd /usr/local/Cellar/googletest/1.8.0
cd /usr/local/Cellar/googletest/1.8.0 $ wget https://github.com/google/googletest/archive/release-1.8.0.zip
cd /usr/local/Cellar/googletest/1.8.0 $ cd googletest-release-1.8.0
@dibayendu
dibayendu / README.md
Last active August 29, 2015 14:26 — forked from hofmannsven/README.md
My simply Git Cheatsheet
<%= simple_form_for @product do |f| %>
<%= f.simple_fields_for :attributes do |d| %>
<% f.object.attributes.try(:each) do |key, value| %>
<%= d.input key, :input_html => {:value => value } %>
<% end %>
<% end %>
<% end %>
#Model
@user.should have(1).error_on(:username) # Checks whether there is an error in username
@user.errors[:username].should include("can't be blank") # check for the error message
#Rendering
response.should render_template(:index)
#Redirecting
response.should redirect_to(movies_path)
@dibayendu
dibayendu / conversion.rb
Created January 12, 2015 00:24
Hash to OpenStruct and vice-versa
module Conversion
module Boolean; end
class TrueClass; include Boolean; end
class FalseClass; include Boolean; end
def to_openstruct(hashed_object)
case hashed_object
when Hash
boolean_methods = []
hashed_object.each do |k, v|
@dibayendu
dibayendu / README.txt
Last active August 29, 2015 14:11 — forked from rdetert/README.txt
The purpose of all this is to see if sphinx, thinking sphinx and thinking sphinx delayed delta are all working properly.
I created a test controller on a separate monit subdomain that simply generates and posts a test value and then uses curl to retrieve it. If the two values match, then sphinx is working properly with delayed delta.
This example assumes a Linux installation.
The file 'delayed_delta.sh' spawns the `rake ts:dd` process in the background, saving its PID to tmp/pids in your Rails project. You can start and stop it by running '/etc/init.d/delayed_delta.sh start' and '/etc/init.d/delayed_delta.sh stop'. You will use these in your monitoring to, see the monitrc snippet.
In a crontab, every X seconds or minutes, run 'ar_sphinx_mon.sh' to see if records are properly being inserted and indexed. If they aren't, then kill all Thinking Sphinx processes and monit should restart them.
#=Navigating=
visit('/projects')
visit(post_comments_path(post))
#=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click_on('Button Value')
@dibayendu
dibayendu / gist:fae77729092753e39941
Created September 26, 2014 07:48
Postgres remove connection of active users
SELECT pg_terminate_backend(pg_stat_activity.pid)
FROM pg_stat_activity
WHERE pg_stat_activity.datname = 'TARGET_DB'
AND pid <> pg_backend_pid();