Skip to content

Instantly share code, notes, and snippets.

View sonianand11's full-sized avatar
🌞

Anand Soni sonianand11

🌞
View GitHub Profile
@sonianand11
sonianand11 / ruby
Created May 16, 2018 07:27
how to use build method to create new object
class Post < ActiveRecord::Base
has_many :comments
end
class Comment < ActiveRecord::Base
belongs_to :post
end
post = Post.first
@result = []
def flatten_it(array)
array.each do |element|
element.is_a?(Array) ? flatten_it(element) : @result << element
end
end
flatten_it([[1,2,[3]],4])
puts @result
#View Original : https://github.com/plataformatec/devise/blob/master/app/controllers/devise/sessions_controller.rb
class Users::SessionsController < Devise::SessionsController
respond_to :json
# POST /resource/sign_in
def create
self.resource = warden.authenticate!(auth_options)
set_flash_message(:notice, :signed_in) if is_flashing_format?
sign_in(resource_name, resource)
#View original : https://github.com/plataformatec/devise/blob/master/app/controllers/devise/registrations_controller.rb
class Users::RegistrationsController < Devise::RegistrationsController
respond_to :json
# POST /resource
def create
build_resource(sign_up_params)
1) ActiveModel validation in rails server side :
class MyObject < ActiveRecord::Base
  validates :state, :presence => true
  validates :other_state, :presence => true, if: state.persent?
end
2) Lets say we have drop down with following state : 
<select id="stateDropdown" name="state">
#! /bin/sh
### BEGIN INIT INFO
# Provides:          nginx
# Required-Start:    $all
# Required-Stop:     $all
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts the nginx web server
# Description:       starts nginx using start-stop-daemon
worker_processes  1;
events {
    worker_connections  1024;
}
http {
    passenger_root /path/to/.rvm/gems/ruby-2.3.0/gems/passenger-5.0.24;
    passenger_ruby /path/to/.rvm/gems/ruby-2.3.0/wrappers/ruby;
    include       mime.types;
package com.healthseva.widget;
import com.healthseva.R;
import com.healthseva.services.RandomTipService;
import com.healthseva.utility.ServiceUtility;
import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.ComponentName;
@sonianand11
sonianand11 / TestingFile
Last active August 29, 2015 14:02
This is for testing
class Foo
def initialize(thing)
@thing = thing
end
def test_me
if @thing.big?
'Big!'
else
'Small!'
<script>
$(document).ready(function(){
var startRecording = document.getElementById('start-recording');
var stopRecording = document.getElementById('stop-recording');
var uploadRecordingBtn = document.getElementById('upload-recording');
var cameraPreview = document.getElementById('camera-preview');