Skip to content

Instantly share code, notes, and snippets.

def create
@club = Club.new(club_params)
respond_to do |format|
if @club.save
format.html { redirect_to @club, notice: 'Club was successfully created.' }
format.json { render :show, status: :created, location: @club }
else
format.html { render :new }
format.json { render json: @club.errors, status: :unprocessable_entity }
<!-- how to use G_mapper -->
<!-- 1) add an input field with this structure -->
<input type="text" id="any_id_u_like" data-gmapper-input>
<!-- 2) add a div with “data-gmapper-render-for” with the id of input you've added as data attribute value -->
<div data-gmapper-render-for="any_id_u_like">
<!-- 3) add a child div with id “distance” -->
<!-- and “data-gmapper-endpoint” with the address you want the itinerary from as value -->
{
"services": [
{
"id": 8,
"name": "Interval training",
"default_picture": "http://localhost:3000/system/avatars/photos/000/000/036/medium/interval_train.jpg?1504207529"
},
{
"id": 9,
"name": "Yoga",
@shcyiza
shcyiza / variable_scanner.rb
Last active September 9, 2018 12:11
variable scanner for hapi_mailer
str = "<container>\n<row>\n <columns large=\"6\">\n <h1>%{toto}%</h1>\n </columns>\n %{kilo}%\n <columns large=\"6\">\n <i class=\"classx\">%{socco}%</i>\n </columns>\n %{kilo}%\n</row>\n</container>"
# /%{+\w+}%/ is the regex of the chosen string interpolation synthax e.g. %{variable}%
# we try to extract all of those and put them in an array
# first lets get the all the interpolation out of the text
interpolition_arr = str.scan(/%{+\w+}%/)
# => ["%{toto}%", "%{kilo}%", "%{socco}%", "%{kilo}%"]
# make each variable have only one occurence in the variable array
// create state with constructor
constructor(props) {
super(props);
this.state = {comment: "yo!"};
}
// proper way to change the state
this.setState({comment: 'Hello'});
RandomService.formatPayload = function (id, fn) {
/* Should deduce that RandomService is an object, has a property named 'formatPayload'
a funtion with two arguments is being expressed on the property, so it's a method */
return {
// this method returns an object
client_id: id,
/* returned object has a property 'client_id', which has the id argument as value or a reference
we cannot deduce the type of the 'id' argument
var arr1 = [1, 2, 3]
var obj1 = {prop1: "lol", prop2: "lmao"}
var arr2 = [...arr1, 4, 5, 6]
var obj2 = {...Obj1, prop1: "Trololo", foo: "bar"}
console.log(arr2)
//expects: [1,2,3,4,5,6]
console.log(obj2)
import { SET_BOOKNAME, ADD_BOOKMARK, DELETE_BOOKMARK } from '../actions/types';
export default function bookmarksReducer(state = {book_name: "", list: []}, action) {
switch (action.type) {
case SET_BOOKNAME:
return {...state, book_name: action.payload}
// copy the current state
// and change the value of book_name property
// with payload property given by the action
case ADD_BOOKMARK:
@shcyiza
shcyiza / inheritance.js
Last active May 28, 2019 07:19
shallow and deep clone objects with inheritance
// shallow copy
function cloneWithProto (source, target = {}) {
// if you just want to copy the source the target is optional
let clone = {...source, ...target}
// make shallow copy out of source, and overwrite with target
Object.setPrototypeOf(clone, Object.getPrototypeOf(source))
// set the proto of result to the proto of source object
return clone
{
"status": 200,
"data":{
"title": {
"en": "How many hot-dogs can you eat?",
"nl": "Hoevel hot-dogs kunt gij eten?",
"fr": "Combien de hot-dogs peux-tu manger?",
},
"abstract": {
"en": "Deep dive into the dark world of hot-dog eaters contest...",