Skip to content

Instantly share code, notes, and snippets.

View bekatom's full-sized avatar
🎯
Focusing

Beka Tomashvili bekatom

🎯
Focusing
View GitHub Profile
@bekatom
bekatom / $iteratorUpdate.js
Created September 3, 2018 20:33
mongoUpdate $iterator deep nested arrays with Mongoose Raw query
function justSample() {
try {
mongoose.connect(config.database.connection, mongoConnectOptions)
mongoose.connection.db.collection('tenants').update(
{ '_id': mongoose.Types.ObjectId(userId) },
{
// $set: {
// 'lease.$[l].rooms.$[r].items.$[i].title': 'Flooring'
// }
$push: {
@bekatom
bekatom / Utils.js
Last active August 17, 2018 09:20
save image in local drive & upload to s3 - (With image processing to save thumbnail also )
/**
* save image with thumbnail in local drive if dir is /tmp then it will be deleted
* @param {Request} req request
* @param {Response} res response
* @param {string} what type of files should be upload ex: "images", "excel"
* @returns {Promise<Express.Multer.File>} file
*/
saveImage (req, res, cfg) {
const { UPLOAD_DIR, hasThumbnail, waitThumbnail } = cfg
@bekatom
bekatom / pdf.js
Created April 5, 2018 12:26
PDF_GENERATION_WITH_PHANTOM_CONTROLLER
pdf(req, res) {
const {id} = req.params
var fs = require('fs');
phantom.create().then(function(ph) {
ph.createPage().then(function(page) {
page.open(`${config.HTTP_HOST}/api/v1/html-report-endpoint/${id}`).then(function(status) {
var fileName = `./public/uploads/pdf/${id}.pdf`
page.render(fileName).then(function() {
// HERE RETURNS AS PDF
var file = fs.createReadStream(fileName);
@bekatom
bekatom / SMART_COTRACT.md
Last active February 22, 2018 11:56
SMART-CONTRACT

ბლოკჩეინთან ურთიერთობა web3.js

ganache-cli - ბლოკჩეინის სიმულატორი

კონსოლიდან web3js ის მეშვეობით დაკავშირება ბლოკჩეინზე, წინასწარ უნდა იყოს გაშვებული ბლოკჩიენის სიმულატორი ganache-cli

node
Web3 = require('web3')
web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
@bekatom
bekatom / getCityByIP.js
Created June 1, 2017 13:37
Get location data by IP
var axios = require('axios')
const getAddressByIP = (ip) => {
return axios.get(`http://ip-api.com/json/${ip}?lang=en`).then((data) => data)
}
@bekatom
bekatom / reducer.js
Created May 31, 2017 14:59
Reducer example
/// gets data from service and maps each other creates new array
const getAllFestivals = (arr) => Promise.reduce(arr, (prev, item) =>
tkt.getShowsList({categoryId: item}).then((result) => {
if (result.data.Shows.length > 0) {
result.data.Shows.map((i) => {
prev.push(i)
})
}
return prev
@bekatom
bekatom / cahced_image_sample.js
Created April 13, 2017 07:50
react native cached images
let imgAsync = Asset.fromModule(require('./image.jpg'))
await imgAsync.downloadAsync()
if (imgAsync.downloaded) {
console.log('> imgAsync, ', imgAsync)
const imageURL = imgAsync.localUri
Image.getSize(imageURL, (width, height) => {
var imageSize = {
size: {
@bekatom
bekatom / createAlphabetSorting.js
Created April 9, 2017 11:35
createAlphabetSorting with lodash
import _ from 'lodash'
/**
* Create Alpavet data structure from list of objects like : [ A : {}, B : {}]
* @param {*} list
*/
export const createAlphabetSorting = list =>
_.groupBy(
_.sortBy(list, [i => i.firstName.toLowerCase()]),
item => item.firstName.charAt(0).toUpperCase())
@bekatom
bekatom / oto.js
Last active March 6, 2017 20:33
oto.js
/* eslint jsx-a11y/href-no-hash: 0 */
import React, { Component, PropTypes } from 'react'
import { Link } from 'react-router'
import { connect } from 'react-redux'
import { startupRequest } from '../actions/startup'
import { fetchUserRequest, userLogoutRequest } from '../actions/userAuth'
class App extends Component {
@bekatom
bekatom / promise_all.js
Created March 3, 2017 13:25
Promise.all() sample
var sum = 0
var p1 = new Promise((resolve, reject) => {
console.log('p1')
sum = sum + 1
setTimeout(resolve, 1000, 'one')
})
var p2 = new Promise((resolve, reject) => {
console.log('p2')
sum = sum + 1
setTimeout(reject, 2000, 'two')