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 / 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 / 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 / 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 / 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 / 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 / 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 / $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: {