Skip to content

Instantly share code, notes, and snippets.

View alexander-elgin's full-sized avatar

Alexander Elgin alexander-elgin

View GitHub Profile
@alexander-elgin
alexander-elgin / index.js
Created February 3, 2020 04:35
Upload File to Google Cloud Storage
const {Storage} = require('@google-cloud/storage');
const storage = new Storage({
projectId: 'akbarserver',
keyFilename: './service-account.json'
});
function uploadFile(filename, bucketName) {
return storage.bucket(bucketName).upload(filename, {
gzip: true,
@alexander-elgin
alexander-elgin / index.js
Created January 30, 2020 15:34
Video Thumbnail
var ffmpeg = require('fluent-ffmpeg');
var path = require('path');
new ffmpeg(path.join(__dirname, 'input.mp4'))
.takeScreenshots({
filename: 'thumbnail.png',
size: '640x480',
timemarks: [ '50%' ],
}, __dirname, function(err) {
if (err) {
@alexander-elgin
alexander-elgin / index.js
Created January 30, 2020 15:31
YouTube Thumbnails
const getThumbnails = (videoUrl) => {
const videoId = videoUrl.replace('https://www.youtube.com/watch?v=', '');
return ['hqdefault', 'mqdefault', 'maxresdefault'].map(size => `https://img.youtube.com/vi/${videoId}/${size}.jpg`);
}
@alexander-elgin
alexander-elgin / link.js
Created January 30, 2020 15:26
Google Drive File Public Link
@alexander-elgin
alexander-elgin / formik-mobx.js
Created December 20, 2019 11:44 — forked from danielkcz/formik-mobx.js
Formik with MobX
function useFormik(props) {
// useState to keep the same observable around without recreating it on each render
const [formik] = React.useState(() =>
mobx.observable({
values: props.initialValues || {},
touched: {}
})
)
// just mutate state, this function itself can be considered an action+reducer
@alexander-elgin
alexander-elgin / eth-balance.js
Created October 17, 2018 11:52
Get ETH Balance
const Web3 = require('web3');
const testnet = 'https://rinkeby.infura.io/';
const walletAddress = '0xcde7bd7943944dc558a427ef061400a4da9ee822';
void async function() {
try {
const web3 = new Web3(new Web3.providers.HttpProvider(testnet));
const balance = await web3.eth.getBalance(walletAddress);
console.log('the balance is', web3.utils.fromWei(balance, 'ether'))
} catch (error) {
@alexander-elgin
alexander-elgin / dash-funds-transfer-InstantSend.js
Created October 5, 2018 08:11
Transfer Dash funds using InstantSend
const axios = require('axios');
const dashcore = require('dashcore-lib');
const API_BASE_URL = 'https://testnet-insight.dashevo.org/insight-api-dash';
const sender = {
address: 'yRtqi4khyBHknDGarrsgrJLdvDipmbcbXx',
privateKey: '6e38851a2df2866b95e87aa7cb1c37356a5f6a2546ba7249b86a656288ed18dd'
};
@alexander-elgin
alexander-elgin / dash-funds-transfer.js
Created September 29, 2018 16:09
Transfer DASH Funds
const axios = require('axios');
const dashcore = require('dashcore-lib');
const API_BASE_URL = 'https://testnet-insight.dashevo.org/insight-api-dash';
const sender = {
address: 'yRtqi4khyBHknDGarrsgrJLdvDipmbcbXx',
privateKey: '6e38851a2df2866b95e87aa7cb1c37356a5f6a2546ba7249b86a656288ed18dd'
};
@alexander-elgin
alexander-elgin / Home.jsx
Created June 22, 2018 09:30
React-Intl with Enzyme & Jest
import React from 'react';
import messages from './messages.js';
import { Link } from 'react-router';
import { FormattedMessage } from 'react-intl';
const Home = () => (
<div>
<header>
<FormattedMessage {...messages.home_link}>
{(homeLink) => <FormattedMessage {...messages.header} values={{ link: <Link to="/">{ homeLink }</Link> }} />}