Skip to content

Instantly share code, notes, and snippets.

@salmanx
salmanx / running_app_in_production_locally.markdown
Created December 19, 2019 03:45 — forked from rwarbelow/running_app_in_production_locally.markdown
How to Run a Rails App in Production Locally
  1. Add gem 'rails_12factor' to your Gemfile. This will add error logging and the ability for your app to serve static assets.
  2. bundle
  3. Run RAILS_ENV=production rake db:create db:migrate db:seed
  4. Run rake secret and copy the output
  5. From the command line: export SECRET_KEY_BASE=output-of-rake-secret
  6. To precompile your assets, run rake assets:precompile. This will create a folder public/assets that contains all of your assets.
  7. Run RAILS_ENV=production rails s and you should see your app.

Remember to clobber your assets (rake assets:clobber) and re-precompile (rake assets:precompile) if you make changes.

// borrowed from https://getbootstrap.com/docs/4.4/getting-started/browsers-devices/
<script>
$(function () {
var nua = navigator.userAgent
var isAndroid = (nua.indexOf('Mozilla/5.0') > -1 && nua.indexOf('Android ') > -1 && nua.indexOf('AppleWebKit') > -1 && nua.indexOf('Chrome') === -1)
if (isAndroid) {
// do stuff
}
})
</script>
@salmanx
salmanx / browser_helper.rb
Created December 5, 2019 05:39
Helper classes for tracking browser in rails application
module BrowserClassHelper
def browser_class
if ie11?
"is-ie11"
else
"is-" + request.browser.downcase
end
end
def ie11?
@salmanx
salmanx / file_upload.js
Created November 1, 2019 09:23
multiple image upload using javascript, copied from https://jsfiddle.net/Logan_Wayne/xz6dgLz1/#fork
<div class="container">
<h3 class="page-header">Upload Photos Page</h3>
<form class="form-horizontal">
<div class="form-group">
<label for="photo" class="col-sm-2 control-label">Upload</label>
<div class="col-sm-10">
<input type="file" class="form-control" name="photo" id="photo" accept=".png, .jpg, .jpeg" onchange="readFile(this);" multiple>
</div>
</div>
@salmanx
salmanx / .eslintrc.js
Created October 25, 2019 06:01 — forked from adrianhall/.eslintrc.js
A sample .eslintrc file
var OFF = 0, WARN = 1, ERROR = 2;
module.exports = exports = {
"env": {
"es6": true
},
"ecmaFeatures": {
// env=es6 doesn't include modules, which we are using
"modules": true
# Ruby wrapper for UglifyJS JavaScript compressor
gem "uglifier", ">= 1.3.0"
#Search Engine Optimization (SEO)
gem "meta-tags"
# Sucker Punch is a Ruby asynchronous processing library using concurrent-ruby, heavily influenced by Sidekiq and girl_friday.
gem "sucker_punch"
@salmanx
salmanx / docker-help.md
Created March 31, 2019 08:37 — forked from bradtraversy/docker-help.md
Docker Commands, Help & Tips

Docker Commands, Help & Tips

Show commands & management commands

$ docker

Docker version info

import { createStore, combineReducers} from "redux";
import uuid from 'uuid/v1';
// NOTE:
// to create store we need to pass reducer in createStore() method
// reducer is a function with state and action params - testReducer(state = demostate, action)
// reducer will return result based on action.type
// we need to pass demoState in params
// state of the application would look like this demoState
@salmanx
salmanx / callback_to_promise.js
Created October 18, 2018 05:23
an example for callback to promise conversion in javascript
console.log('Before');
// callback approach
// getUser(1, displayUser);
// promised based approach
// getUser(1)
// .then(user => getRepositories(user.name))
// .then(repos => getCommits(repos[0]))
@salmanx
salmanx / promise.js
Created October 18, 2018 05:22
an example how promise work in javascript
const p = new Promise((resolve, reject) => {
setTimeout(() => {
resolve(1);
// reject(new Error('message'));
}, 2000)
});