Skip to content

Instantly share code, notes, and snippets.

View mrhm-dev's full-sized avatar
🏠
Working from home

HM Nayem mrhm-dev

🏠
Working from home
View GitHub Profile
@mrhm-dev
mrhm-dev / enum-access.js
Created January 6, 2018 14:48 — forked from bnoguchi/enum-access.js
How to access enumValues in mongoose from a Model or Document
var mongoose = require('./index')
, TempSchema = new mongoose.Schema({
salutation: {type: String, enum: ['Mr.', 'Mrs.', 'Ms.']}
});
var Temp = mongoose.model('Temp', TempSchema);
console.log(Temp.schema.path('salutation').enumValues);
var temp = new Temp();
console.log(temp.schema.path('salutation').enumValues);
@mrhm-dev
mrhm-dev / restPatch.js
Created January 7, 2018 03:19
Using a different approach to patch method in this code. value should be pass with request as below [ {obj}, {obj} ]
router.put('/:newsId', (req, res, next) => {
const _id = req.params.newsId;
const updateOptions = {};
for(let ops of req.body) {
updateOptions[ops.propName] = ops.value;
}
// Called Update Method from News Model
News.update({_id}, {$set: updateOptions})
.exec()
@mrhm-dev
mrhm-dev / passport.js
Created January 8, 2018 09:29
Passport JWT strategy configuration
module.exports = function(passport){
let opts = {};
opts.jwtFromRequest = ExtractJwt.fromAuthHeaderWithScheme("jwt");
opts.secretOrKey = config.secret;
passport.use(new JwtStrategy(opts, (jwt_payload, done) => {
User.getUserById(jwt_payload.data._id, (err, user) => {
if(err){
return done(err, false);
}
@mrhm-dev
mrhm-dev / cloudSettings
Last active October 31, 2022 17:07
Visual Studio Code Settings Sync Gist
{"lastUpload":"2018-04-22T20:01:49.065Z","extensionVersion":"v2.9.0"}
@mrhm-dev
mrhm-dev / README-Template.md
Created March 21, 2018 05:36 — forked from PurpleBooth/README-Template.md
A template to make good README.md

Project Title

One Paragraph of project description goes here

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

@mrhm-dev
mrhm-dev / cloudSettings
Created March 21, 2018 06:52
Visual Studio Code Settings Sync Gist
{"lastUpload":"2018-03-21T06:52:08.801Z","extensionVersion":"v2.9.0"}
xcode-select --install
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew update
brew cask install iterm2
# update iterm2 settings -> colors, keep directory open new shell, keyboard shortcuts
brew install bash # latest version of bash
# set brew bash as default shell
brew install fortune
brew install cowsay
brew install git
@mrhm-dev
mrhm-dev / uuid.js
Created December 25, 2018 04:55
A very simple implementation of UUID in Javascript
function create_UUID(){
var dt = new Date().getTime();
var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = (dt + Math.random()*16)%16 | 0;
dt = Math.floor(dt/16);
return (c=='x' ? r :(r&0x3|0x8)).toString(16);
});
return uuid;
}
@mrhm-dev
mrhm-dev / tinymce.js
Created July 21, 2019 13:23
TinyMCE minimal setup
tinymce.init({
selector: '#body',
height: 500,
menubar: 'file edit format help',
plugins: 'advlist lists link autolink autosave code preview searchreplace wordcount media table emoticons image imagetools',
toolbar: 'bold italic underline | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image media | forecolor backcolor emoticons | code preview searchreplace',
images_upload_url: '/',
images_upload_handler: function (blobinfo, success, failure) {
},
@mrhm-dev
mrhm-dev / getMP4Length.js
Created July 31, 2019 09:01 — forked from Elements-/getMP4Length.js
Read the duration of a mp4 file nodejs
var buff = new Buffer(100);
fs.open(file, 'r', function(err, fd) {
fs.read(fd, buff, 0, 100, 0, function(err, bytesRead, buffer) {
var start = buffer.indexOf(new Buffer('mvhd')) + 17;
var timeScale = buffer.readUInt32BE(start, 4);
var duration = buffer.readUInt32BE(start + 4, 4);
var movieLength = Math.floor(duration/timeScale);
console.log('time scale: ' + timeScale);
console.log('duration: ' + duration);