Skip to content

Instantly share code, notes, and snippets.

// 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)
});
@salmanx
salmanx / callback.js
Created October 18, 2018 05:20
an example how javascript callback works
console.log('Before');
getUser(1, displayUser);
console.log("After");
function getUser(id, callback){
setTimeout(() => {
console.log("Reading a user from database!");
callback({ id: id, name: "salmanx" })