Skip to content

Instantly share code, notes, and snippets.

View goelinsights's full-sized avatar

Vijay Goel goelinsights

View GitHub Profile
@pauljamesrussell
pauljamesrussell / spec_helper.rb
Created November 9, 2011 23:15
RSpec matcher for ensuring a model is accepting nested attributes for an association, and accepting/rejecting the right values.
# Use: it { should accept_nested_attributes_for(:association_name).and_accept({valid_values => true}).but_reject({ :reject_if_nil => nil })}
RSpec::Matchers.define :accept_nested_attributes_for do |association|
match do |model|
@model = model
@nested_att_present = model.respond_to?("#{association}_attributes=".to_sym)
if @nested_att_present && @reject
model.send("#{association}_attributes=".to_sym,[@reject])
@reject_success = model.send("#{association}").empty?
end
model.send("#{association}").clear
@marcomd
marcomd / gist:3129118
Created July 17, 2012 12:18
Authenticate your API with devise, token by header
#Session controller provides a token
#/controllers/api/sessions_controller.rb
class Api::SessionsController < Devise::SessionsController
before_filter :authenticate_user!, :except => [:create]
before_filter :ensure_params_exist, :except => [:destroy]
respond_to :json
def create
resource = User.find_for_database_authentication(:email => params[:user_login][:email])
return invalid_login_attempt unless resource
@SabretWoW
SabretWoW / rspec_model_testing_template.rb
Last active March 7, 2024 03:56
Rails Rspec model testing skeleton & cheat sheet using rspec-rails, shoulda-matchers, shoulda-callbacks, and factory_girl_rails. Pretty much a brain dump of examples of what you can (should?) test in a model. Pick & choose what you like, and please let me know if there are any errors or new/changed features out there. Reddit comment thread: http…
# This is a skeleton for testing models including examples of validations, callbacks,
# scopes, instance & class methods, associations, and more.
# Pick and choose what you want, as all models don't NEED to be tested at this depth.
#
# I'm always eager to hear new tips & suggestions as I'm still new to testing,
# so if you have any, please share!
#
# @kyletcarlson
#
# This skeleton also assumes you're using the following gems:
@Stanback
Stanback / nginx.conf
Last active February 4, 2022 18:05
Example Nginx configuration for serving pre-rendered HTML from Javascript pages/apps using the Prerender Service (https://github.com/collectiveip/prerender).Instead of using try_files (which can cause unnecessary overhead on busy servers), you could check $uri for specific file extensions and set $prerender appropriately.
# Note (November 2016):
# This config is rather outdated and left here for historical reasons, please refer to prerender.io for the latest setup information
# Serving static html to Googlebot is now considered bad practice as you should be using the escaped fragment crawling protocol
server {
listen 80;
listen [::]:80;
server_name yourserver.com;
root /path/to/your/htdocs;
@dsaronin
dsaronin / gist:8155622
Last active March 22, 2017 07:09
token_authentication handling using milia & devise
## token_authentication
# at the head of of controllers which will need token authentication instead of password/session authentication:
skip_before_action :authenticate_tenant!
before_action :authenticate_by_token!
# then in application_controller.rb:
def authenticate_by_token!
require 'rails_helper'
RSpec.describe TodosController, :type => :controller do
describe "GET #index" do
#describe "POST #create" do
#describe "GET #show" do
#describe "PATCH #update" do (or PUT #update)
#describe "DELETE #destroy" do
#describe "GET #new" do
import {Directive, forwardRef, Provider} from "angular2/core";
import {NG_VALUE_ACCESSOR, ControlValueAccessor} from "angular2/common";
import {CONST_EXPR} from "angular2/src/facade/lang";
const FILE_VALUE_ACCESSOR = CONST_EXPR(
new Provider(NG_VALUE_ACCESSOR, {useExisting: forwardRef(() => FileControlValueAccessor), multi: true})
);
/**
* The accessor for listening to changes that is used by the
@btroncone
btroncone / ngrxintro.md
Last active February 9, 2024 15:37
A Comprehensive Introduction to @ngrx/store - Companion to Egghead.io Series

Comprehensive Introduction to @ngrx/store

By: @BTroncone

Also check out my lesson @ngrx/store in 10 minutes on egghead.io!

Update: Non-middleware examples have been updated to ngrx/store v2. More coming soon!

Table of Contents

@keathmilligan
keathmilligan / auth0-angular-cli-notes.md
Last active March 20, 2018 20:56
auth0 + angular-cli notes

Auth0 Example with Angular CLI

A complete example is available at https://github.com/keathmilligan/angular2-cli-auth0-example

The provided auth0 tutorial uses SystemJS, these notes outline how to integrate into an angular-cli or straight webpack project.

Create project as usual with "ng create".

Install auth0 packages & bootstrap:

@bennadel
bennadel / app.component.ts
Created November 6, 2017 00:13
Lazy Loading Images With The IntersectionObserver API In Angular 5.0.0
// Import the core angular services.
import { Component } from "@angular/core";
// ----------------------------------------------------------------------------------- //
// ----------------------------------------------------------------------------------- //
interface Contact {
id: number;
name: string;
avatarUrl: string;