Skip to content

Instantly share code, notes, and snippets.

View TranBaVinhSon's full-sized avatar
🎯
Focusing

Tran B. V. Son TranBaVinhSon

🎯
Focusing
View GitHub Profile
@TranBaVinhSon
TranBaVinhSon / rails_jquery_ajax.md
Created October 5, 2017 17:51 — forked from SamSamskies/rails_jquery_ajax.md
Rails: jQuery & AJAX Tutorial

jQuery and jQuery-ujs

When using Rails 3.0 and later we already get jquery-rails for free. Look in the gemfile and you'll see:

gem "jquery-rails"

You can view the full documentation here: source: https://github.com/indirect/jquery-rails

If you take a look in APP_DIR/app/assets/javascripts/application.js, you'll notice the following lines of code:

@TranBaVinhSon
TranBaVinhSon / application.html.erb
Created October 13, 2017 02:25 — forked from the-bass/application.html.erb
Using Google Analytics with Rails 5 and Turbolinks 5. This code is taken from the conversation between @preetpalS and @packagethief on https://github.com/turbolinks/turbolinks/issues/73.
<%# Put this code snippet between the <head></head>-tags in your application layout and %>
<%# replace 'UA-XXXXXXXX-X' with your own unique Google Analytics Tracking ID %>
<%# ... %>
<head>
<%# ... %>
<% if Rails.env.production? %>
<script type="text/javascript">
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
@TranBaVinhSon
TranBaVinhSon / gist:0d3719d0c8e3f9d93eb0265ffbf2a3b6
Created December 10, 2017 08:35
Text inside Doughnut Chart.js
Chart.pluginService.register({
beforeDraw: function (chart) {
if (chart.config.options.elements.center) {
//Get ctx from string
var ctx = chart.chart.ctx;
//Get options from the center object in options
var centerConfig = chart.config.options.elements.center;
var fontStyle = centerConfig.fontStyle || 'Arial';
var txt = centerConfig.text;
class Api::V1::RegistrationsController < Devise::RegistrationsController
before_action :ensure_params_exist, only: :create
# sign up
def create
user = User.new user_params
if user.save
render json: {
messages: "Sign Up Successfully",
is_success: true,
data: {user: user}
@TranBaVinhSon
TranBaVinhSon / send_data-send_file-remote-images-download
Created March 5, 2018 17:43 — forked from maxivak/send_data-send_file-remote-images-download
Rails. Download remote image as attachment in browser
# in controller
# for local files
send_file '/path/to/file', :type => 'image/jpeg', :disposition => 'attachment'
# for remote files
require 'open-uri'
url = 'http://someserver.com/path/../filename.jpg'
data = open(url).read
send_data data, :disposition => 'attachment', :filename=>"photo.jpg"
package com.example.sontbv.retrofittutorial.model;
import com.google.gson.annotations.SerializedName;
/**
* Created by sontbv on 3/7/18.
*/
public class Movie {
@SerializedName("id")
package com.example.sontbv.retrofittutorial.webservice;
import com.example.sontbv.retrofittutorial.model.Movie;
import java.util.List;
import retrofit2.Call;
import retrofit2.http.GET;
/**
package com.example.sontbv.retrofittutorial.webservice;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
package com.example.sontbv.retrofittutorial;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import com.example.sontbv.retrofittutorial.adapter.MoviesAdapter;
import com.example.sontbv.retrofittutorial.model.Movie;
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="12dp">
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"