Skip to content

Instantly share code, notes, and snippets.

View ankit8898's full-sized avatar

Ankit gupta ankit8898

View GitHub Profile
@ankit8898
ankit8898 / nginx.conf
Created May 24, 2017 07:07
passenger-5.0.22 default nginx conf
##########################################################################
# Passenger Standalone is built on the same technology that powers
# Passenger for Nginx, so any configuration option supported by Passenger
# for Nginx can be applied to Passenger Standalone as well. You can do
# this by direct editing the Nginx configuration template that is used by
# Passenger Standalone.
#
# This file is the original template. DO NOT EDIT THIS FILE DIRECTLY.
# Instead, make a copy of this file and pass the `--nginx-config-template`
# parameter to Passenger Standalone.
@ankit8898
ankit8898 / Demo.java
Created March 11, 2015 18:02
Hazelcast client connect
package com.ankit.hazelcast;
import com.hazelcast.client.config.ClientConfig;
import com.hazelcast.client.HazelcastClient;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.core.IMap;
public class Demo {
public static void main( String[] args ) {
ClientConfig clientConfig = new ClientConfig();
@ankit8898
ankit8898 / b.svg
Created November 3, 2014 17:24
Prawn svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
=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('Button Value')
class ApplicationController < ActionController::Base
helper_method :permitted_params
private
def permitted_params
PermittedParams.new(params)
end
@ankit8898
ankit8898 / controller
Created July 26, 2013 10:59
Strong parameters with array
def create
p "++++++++#{permitted_params.user.inspect}"
p "++++++++#{permitted_params.user['role_ids'].inspect}"
@user = User.new(permitted_params.user)
if @user.save
flash[:notice] = 'User was successfully created.'
redirect_to edit_admin_user_url(@user)
else
render :action => 'new'
end
@ankit8898
ankit8898 / nested_model.rb
Created June 28, 2013 10:16
Alternative for awesome_nested_set self_and_descendants and descendants. Basically with the idea of hitting the sql that are fired by the nested_set helper
class Group < ActiveRecord::Base
acts_as_nested_set
def self_and_descendants_hashed
ActiveRecord::Base.connection.select_all("SELECT * FROM groups WHERE lft >= #{self.lft} AND rgt <= #{self.rgt} order by lft")
end
def descendants_hashed
ActiveRecord::Base.connection.select_all("SELECT * FROM groups WHERE lft >= #{self.lft} AND lft < #{self.rgt} AND id != 1 ORDER BY lft")
end
@ankit8898
ankit8898 / gist:5212677
Last active December 15, 2015 05:59
Error
Controller Update
def update
@channel = Channel.find(params[:id])
@channel.attributes = params[:channel]
if @channel.save! #@channel.update_attributes(params[:channel])
redirect_to @channel, notice: 'Channel was successfully updated.'
else
render action: 'edit'
end
end
@ankit8898
ankit8898 / BugSegmentation Fault + Ruby 1.9.3 + Asset Precompile
Created February 27, 2013 20:43
This error backtrace in coming while deploying a rails Application on a Open SUSE Server
servers: ["application_server.com"]
[application_server.com] executing command
*** [err :: application_server.com] ** Invoke assets:precompile (first_time)
*** [err :: application_server.com] ** Execute assets:precompile
*** [err :: application_server.com] /usr/local/rvm/rubies/ruby-1.9.3-p392/bin/ruby /opt/apps/myapplication.com/shared/bundle/ruby/1.9.1/bin/rake assets:precompile:all RAILS_ENV=devutility RAILS_GROUPS=assets --trace
*** [err :: application_server.com]
*** [err :: application_server.com] /opt/apps/myapplication.com/shared/bundle/ruby/1.9.1/gems/therubyracer-0.11.4/lib/v8/init.so:
*** [err :: application_server.com] [BUG]
*** [err :: application_server.com] Segmentation fault
*** [err :: application_server.com] ruby 1.9.3p392 (2013-02-22 revision 39386) [x86_64-linux]