Skip to content

Instantly share code, notes, and snippets.

View inneroot's full-sized avatar

Gleb F inneroot

View GitHub Profile
@inneroot
inneroot / divcolheight.js
Created May 12, 2018 00:03
2 colons same height jQuery
var max_height = 0;
$("div.col").each(function(){
if ($(this).height() > max_height) { max_height = $(this).height(); }
});
$("div.col").height(max_height);
@inneroot
inneroot / select_topitem_id.erb
Last active May 19, 2018 15:38
Select form for collection of objects with _form Action View Helper
<div class="field">
<%= form.label :topmenuitem_id %>
<%= form.collection_select(:topmenuitem_id, @menuitems.all, :id, :title) %>
</div>
@inneroot
inneroot / uploadname.js
Last active November 18, 2018 21:20
changing label on bootstrap custom upload file input field
//bootstrap 4 custom upload
//<input type="file" name="fileToUpload" id="fileToUpload" accept=".pdf" class="custom-file-input" onchange="getname(event)">
//<label class="custom-file-label file-upload-info" for="fileToUpload" id="upload_label">Upload PDF</label>
//uploaded filename > label, default label is back on clear;
let deflabel = "Upload File";
if (document.getElementById("upload_label")) deflabel = document.getElementById("upload_label").innerHTML;
function getname(evt){
//console.log(evt);
@inneroot
inneroot / registrations_controller.rb
Created December 4, 2018 13:42
Device gem with one user allowed
# app/controllers/registrations_controller.rb
class RegistrationsController < Devise::RegistrationsController
before_action :one_user_registered?, only: [:new, :create]
protected
def one_user_registered?
if User.count == 1
if user_signed_in?
require('dotenv/config')
const mongoose = require('mongoose')
const Mymodel = require('./models/Mymodel')
mongoose.connect(
process.env.MONGOCONNECT,
{useNewUrlParser: true,
useUnifiedTopology: true},
() => console.log('connected to mongo')
)
@inneroot
inneroot / returnPromiseFromPromise.js
Last active June 16, 2020 13:23
return Promise From Promise
const returnPromiseFromPromise = async (decree) => {
return new Promise((resolve, reject) => {
getPromise()
.then(result => resolve(result))
.catch(Error => reject(Error))
})
}
@inneroot
inneroot / returnConcurrentResult.js
Last active June 16, 2020 13:27
return Result of concurrent tasks
const returnPromeseAll = async () => {
try{
const a = getPromise1()
const b = getPromise2()
const concurrentResult = await Promise.all([a, b])
}
catch(err) {
throw err
}
return concurrentResult
@inneroot
inneroot / forAwaitPromiseArr.js
Created June 16, 2020 13:37
Concurrent loop through array of Promises
callApi = [url1, url2, url3]
const pormiseArr = callApi.map(v => getFromApi(v))
const ConcurrentLoop = async() => {
for await (const resolvedPromise in pormiseArr) {
console.log(resolvedPromise)
}
}
@inneroot
inneroot / forAwait.js
Created November 23, 2021 16:13
for await loop javascript
async function start() {
for await (let asyncFunction of asyncFunctions ) {
console.log(await asyncFunction())
}
}
start();
@inneroot
inneroot / arrayToBatchGenerator.js
Created March 10, 2022 06:47
split array to batches with generator
function* batchGenerator(array, batchSize) {
const arrCopy = [...array];
while(arrCopy.length>0){
yield arrCopy.splice(0, batchSize);
}
}