Skip to content

Instantly share code, notes, and snippets.

@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
@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 / 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?
// 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 / 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.

@salmanx
salmanx / eslint_prettier_airbnb.md
Created December 20, 2019 16:01 — forked from bradtraversy/eslint_prettier_airbnb.md
ESLint, Prettier & Airbnb Setup

VSCode - ESLint, Prettier & Airbnb Setup

1. Install ESLint & Prettier extensions for VSCode

Optional - Set format on save and any global prettier options

2. Install Packages

npm i -D eslint prettier eslint-plugin-prettier eslint-config-prettier eslint-plugin-node eslint-config-node
@salmanx
salmanx / Tab.js
Last active January 15, 2020 03:20
Reusable tab component
import React, { Component } from 'react';
import styled from 'styled-components';
export default class Tab extends Component {
constructor(props) {
super(props);
console.log(this.props);
this.state = {
activeTabIndex: 1

MongoDB Cheat Sheet

Show All Databases

show dbs

Show Current Database

var arr = [
{'id':1 ,'parentid' : 0},
{'id':2 ,'parentid' : 1},
{'id':3 ,'parentid' : 1},
{'id':4 ,'parentid' : 2},
{'id':5 ,'parentid' : 0},
{'id':6 ,'parentid' : 0},
{'id':7 ,'parentid' : 4}
];
### DigitalOcean Ubuntu 18.04 x64 + Rails 5 + Nginx + Unicorn + PostgreSQL9.6 + Capistrano 3
SSH into Root
$ ssh [email protected]
Change Root Password
$ passwd