Posts

Validate Google access token?

  For user check, just post get the access token as accessToken and post it and get the response https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=accessToken you can try in address bar in browsers too, use httppost and response in java also response will be like { "issued_to": "xxxxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com", "audience": "xxxxxxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com", "user_id": "xxxxxxxxxxxxxxxxxxxxxxx", "scope": "https://www.googleapis.com/auth/userinfo.profile https://gdata.youtube.com", "expires_in": 3340, "access_type": "offline" } The scope is the given permission of the accessToken. you can check the scope ids in  this link Update:  New API post as below https://oauth2.googleapis.com/tokeninfo?id_token=XYZ123 Response will be as { // These six fields are

Javascript key codes

Key Code Key 0 That key has no keycode 3 break 8 backspace / delete 9 tab 12 clear 13 enter 16 shift 17 ctrl 18 alt 19 pause/break 20 caps lock 21 hangul 25 hanja 27 escape 28 conversion 29 non-conversion 32 spacebar 33 page up 34 page down 35 end 36 home 37 left arrow 38 up arrow 39 right arrow 40 down arrow 41 select 42 print 43 execute 44 Print Screen 45 insert 46 delete 47 help 48 0 49 1 50 2 51 3 52 4 53 5 54 6 55 7 56 8 57 9 58 : 59 semicolon (firefox), equals 60 < 61 equals (firefox) 63 ß 64 @ (firefox) 65 a 66 b 67 c 68 d 69 e 70 f 71 g 72 h 73 i 74 j 75 k 76 l 77 m 78 n 79 o 80 p 81 q 82 r 83 s 84 t 85 u 86 v 87 w 88 x 89 y 90 z 91 Windows Key / Left ⌘ / Chromebook Search key 92 right window key 93 Windows Menu / Right ⌘ 95 sleep 96 numpad 0 97 numpad 1 98 numpad 2 99 numpad 3 100 numpad 4 101 numpad 5 102 numpad 6 103 numpad 7 104 numpad 8

Run react-native with emulator

List Emulator Devices:   emulator -list-avds Example:  Pixel_2_API_28 Run app with emulator: emulator @{device_name} & react-native run-android Example:  emulator @{Pixel_2_API_28} & react-native run-android

Deploy Reatjs app on Heroku

1. React JS app npm install -g create-react-app create-react-app my-app cd my-app git init heroku create -b https://github.com/mars/create-react-app-buildpack.git git add . git commit -m "react-create-app on Heroku" git push heroku master heroku open OR if you already have app created then add  mars/create-react-app then set heroku buildpacks:set mars/create-react-app 2. If following error coming then set bundle path:  ls: cannot access '/app/build/static/js/*.js': No such file or directory 2019-12-23T07:49:22.901124+00:00 app[web.1]: Error injecting runtime env: bundle not found '/app/build/static/js/*.js'. See: https://github.com/mars/create-react-app-buildpack/blob/master/README.md#user-content-custom-bundle-location heroku config:set JS_RUNTIME_TARGET_BUNDLE='/app/dist/*.js' Make sure your bundle into directory /app/dist OR if you have your bundle into other directory then set other directory pa

Add Android devices in n file trasfer mode and set USB

For android connect the cellphone in file trasfer mode and set USB debugging mode under developer options add the device to your linux machine  lsusb  list the usb devices connected and shows something like Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub Bus 001 Device 005: ID 04ca:3010 Lite-On Technology Corp. Bus 001 Device 003: ID 04f2:b483 Chicony Electronics Co., Ltd Bus 001 Device 002: ID 04f3:0235 Elan Microelectronics Corp. Bus 001 Device 008: ID *12d1:107e* Huawei Technologies Co., Ltd. Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub after this run  echo 'SUBSYSTEM=="usb", ATTR{idVendor}=="12d1", MODE="0666", GROUP="plugdev"' | sudo tee /etc/udev/rules.d/51-android-usb.rules  Finally start the app on your device  ract-native run-android

Add CORS to Nginx on AWS Elastic Beanstalk

Image
Apache Add the following block to your  .htaccess  file: <FilesMatch ".(eot|otf|ttf|woff|woff2)"> Header always set Access-Control-Allow-Origin "*" </FilesMatch> Nginx Add the following location block to your virtual host file (usually within the server directive) and reload Nginx: location ~* \.(eot|otf|ttf|woff|woff2)$ { add_header Access-Control-Allow-Origin *; } Invalidate CloudFront Distribution Once the changes have been made you will need to  invalidate the CloudFront cache  with a path of “/*”. Integrating to CloudFront service It’s simple to config and use CloudFront (a CDN service) for Rails app.  Just one thing from my experience, regarding to CORS issue on EB when your CSS want get loading font files or font-awesome. Because EB run your app with Nginx server serve public static files, then work around would be overwriting web server config in Nginx with  add_header Access-Control-Allow-Origin ‘*’  by crea

Add auto increment column in Postgres in Rails

class AddAutoIncrements < ActiveRecord::Migration def self.up add_column :designs, :custom_id, :integer execute <<-SQL CREATE SEQUENCE custom_id_seq START 1; ALTER SEQUENCE custom_id_seq OWNED BY designs.custom_id; ALTER TABLE designs ALTER COLUMN custom_id SET DEFAULT nextval('custom_id_seq'); SQL end def self.down remove_column :designs, :custom_id execute <<-SQL DROP SEQUENCE custom_id_seq; SQL end end OR Added by Active record: class AddAutoIncrements < ActiveRecord::Migration def self.up add_column :users, :custom_id, :integer ActiveRecord::Base.connection.execute("CREATE SEQUENCE users_id_seq") ActiveRecord::Base.connection.execute("ALTER SEQUENCE users_id_seq OWNED BY users.id") ActiveRecord::Base.connection.execute("ALTER TABLE users ALTER COLUMN id SET DEFAULT nextval('users_id_seq')") end end def self.down remove_column

ERROR: null value in column "id" violates not-null constraint

This is easier: ActiveRecord :: Base . connection . tables . each do | t | ActiveRecord :: Base . connection . reset_pk_sequence !( t ) end If sequence missing then create new sequence to all database table:           ActiveRecord::Base.connection.tables.each do |t|      ActiveRecord::Base.connection.execute("CREATE SEQUENCE #{t}_id_seq")   end