Skip to content

Instantly share code, notes, and snippets.

View petrbela's full-sized avatar

Petr Bela petrbela

View GitHub Profile
@a-chernykh
a-chernykh / application_controller.rb
Created June 22, 2011 19:43
devise force https for sign in and sign up routes
class ApplicationController < ActionController::Base
before_filter :ensure_proper_protocol
protected
def ssl_allowed_action?
(params[:controller] == 'users/sessions' && ['new', 'create'].include?(params[:action])) ||
(params[:controller] == 'users/registrations' && ['new', 'create', 'edit', 'update'].include?(params[:action])) ||
(params[:controller] == 'users/omniauth_callbacks')
end
@jwo
jwo / registrations_controller.rb
Created September 30, 2011 23:11
API JSON authentication with Devise
class Api::RegistrationsController < Api::BaseController
respond_to :json
def create
user = User.new(params[:user])
if user.save
render :json=> user.as_json(:auth_token=>user.authentication_token, :email=>user.email), :status=>201
return
else
@alexeygolev
alexeygolev / controllersSpec.js
Created August 14, 2012 01:47
angular.js jasmine test spec for controller defined inside a module
'use strict';
/* jasmine specs for controllers go here */
describe('PhoneCat controllers', function() {
describe('PhoneListCtrl', function() {
beforeEach(module('phonesCat.controllers'));
@lukas-vlcek
lukas-vlcek / gist:5143799
Last active February 7, 2023 21:50
Adding a new analyzer into existing index in Elasticsearch (requires close/open the index). Tested with Elasticsearch 0.19.12.
// create an index with an analyzer "myindex"
curl -X PUT localhost:9200/myindex -d '
{
"settings" : {`
"index":{
"number_of_replicas":0,
"number_of_shards":1,
"analysis":{
"analyzer":{
"first":{
@wsargent
wsargent / docker_cheat.md
Last active August 31, 2023 12:10
Docker cheat sheet
@staltz
staltz / introrx.md
Last active May 24, 2024 07:56
The introduction to Reactive Programming you've been missing

Usage

  1. npm install babel-loader imports-loader webpack --save
  2. Create webpack.config.js
  3. Move index.ios.js to src/index.ios.jsx
  4. webpack --watch

Example

src/index.ios.jsx

@hejld
hejld / reactive-2015.md
Last active December 10, 2021 10:24
Advanced React.js Performance - Reactive 2015 Lightning Talk Proposal

Note: This is a submission for a Reactive2015 lightning talk. If you'd like to see a lightning talk about this (or read a detailed blog post if you are not going for the conference), vote for it by starring this gist! Thanks a lot!

Advanced React.js Performance

Performance is one of the reasons why React.js is so popular for building complex, highly interactive web applications. It became the go-to library for developers who don’t like to make compromises for technical reasons when building awesome user experiences. However even with React.js it still can be easy to hit it’s performance limits.

In this lightning talk Daniel will go beyond the basics of shouldComponentUpdate and immutable data structures and will discuss how to correctly instrument, measure and optimize performance in complex React apps. He will help you understand the overhead of different parts of the React component lifecycle, how some of it’

@fson
fson / rapid-prototyping-with-relay.md
Created October 18, 2015 20:08
Rapid prototyping with Relay (Reactive 2015 lightning talk proposal)

This is a proposal for a lightning talk at the Reactive 2015 conference.

NOTE: If you like this, star ⭐ the Gist - the amount of stars decides whether it makes the cut!

Rapid prototyping with Relay

Relay makes data fetching in React apps simpler, by letting you declare the data needs of your components instead of writing complex imperative code. React, Relay, GraphQL and the other complementary tools are changing how apps are built.

import {parse, Source} from 'graphql/language'
import {GraphQLSchema, GraphQLObjectType, GraphQLString} from 'graphql/type'
import {graphql} from 'graphql'
const whisperType = new GraphQLObjectType({
name: 'Whisper',
fields: () => ({
whyAreYouWhispering: {
type: GraphQLString
}