Skip to content

Instantly share code, notes, and snippets.

View mfurlend's full-sized avatar

Mikhail Furlender mfurlend

  • WeatherBELL Analytics
  • New York, NY
View GitHub Profile
@mfurlend
mfurlend / Mysql.c
Created June 2, 2017 23:05
wgrib2's Mysql.c fix
/******************************************************************************************
Copyright (C) 2008 Niklas Sondell, Storm Weather Center
This file is part of wgrib2 and could be distributed under terms of the GNU General Public License
Example of mysql table structure for use with this script:
create table wgrib2 (rt datetime, vt datetime, lat double, lon double, param varchar(80), level varchar(30), value double);
v1.0 5/2008
10/2009 Jerry Stueve, tmpnam -> mkstemp, "LOAD DATA <<LOCAL>>" added
@mfurlend
mfurlend / conda_cheatsheet.md
Last active November 29, 2017 20:36
conda cheatsheet
Task Conda command Pip command Virtualenv command
Install a package conda install $PACKAGE_NAME pip install $PACKAGE_NAME X
Update a package conda update --name $ENV_NAME $PACKAGE_NAME pip install --upgrade $PACKAGE_NAME X
Update package manager conda update conda Linux/macOS: pip install -U pip Win: python -m pip install -U pip X
Uninstall a package conda remove --name $ENV_NAME $PACKAGE_NAME pip uninstall $PACKAGE_NAME X
Create an environment conda create --name $ENV_NAME python=3.6 X cd $ENV_BASE_DIR; virtualenv $ENV_NAME
Activate an environment source activate $ENV_NAME X source $ENV_BASE_DIR/$ENV_NAME/bin/activate
Deactivate an environment source deactivate X deactivate
Search available packages conda search $SEARCH_TERM pip search $SEARCH_TERM X
@mfurlend
mfurlend / bash-argument-shortcuts.md
Last active October 24, 2019 21:24
Bash CLI re-use last line's arguments
shortcut description
!^ first argument
!$ last argument
!* all arguments
!:2 second argument
!:2-3 second to third arguments
!:2-$ second to last arguments
!:2* second to last arguments
!:2- second to next to last arguments
@mfurlend
mfurlend / datastore-index.js
Created February 6, 2018 02:19
#cloud functions #datastore #google
'use strict';
const Datastore = require('@google-cloud/datastore');
// Instantiates a client
const datastore = Datastore();
/**
* Gets a Datastore key from the kind/key pair in the request.
*
@mfurlend
mfurlend / cloud-storage-index.js
Created February 6, 2018 02:24
#cloud storage #cloud functions #google #word-count-read
const Storage = require('@google-cloud/storage');
const readline = require('readline');
// Instantiates a client
const storage = Storage();
// [END functions_word_count_setup]
function getFileStream (file) {
if (!file.bucket) {
throw new Error('Bucket not provided. Make sure you have a "bucket" property in your request');
@mfurlend
mfurlend / helloGCS-index.js
Created February 6, 2018 02:25
#cloud functions #trigger #cloud storage
exports.helloGCS = (event, callback) => {
const file = event.data;
if (file.resourceState === 'not_exists') {
console.log(`File ${file.name} deleted.`);
} else if (file.metageneration === '1') {
// metageneration attribute is updated on metadata changes.
// on create value is 1
console.log(`File ${file.name} uploaded.`);
} else {
@mfurlend
mfurlend / firebase-gcs-thumbnail-index.js
Created February 6, 2018 02:33
#google #cloud functions #cloud storage #gcs #firebase
'use strict';
const admin = require('firebase-admin');
const functions = require('firebase-functions');
const gcs = require('@google-cloud/storage')({keyFilename:
'adotapet-476b5-firebase-adminsdk-p67hf-60281ac514.json'});
const spawn = require('child-process-promise').spawn;
admin.initializeApp(functions.config().firebase);
exports.generateThumbnail = functions.storage.object()
@mfurlend
mfurlend / firebase-gcs-imagemagik-index.js
Created February 6, 2018 02:36
#firebase #google #cloud storage #cloud functions #imagemagik
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
const gcs = require('@google-cloud/storage')();
const exec = require('child-process-promise').exec;
const LOCAL_TMP_FOLDER = '/tmp/';
/**
* When an image is uploaded in the Storage bucket the information and metadata of the image (the
const query = datastore
.createQuery('Task')
.filter('done', '=', false)
.filter('priority', '=', 4);
@mfurlend
mfurlend / save-to-datastore-index.js
Created February 6, 2018 03:13
#google #datastore #save #cloud functions
exports.transaction = function transaction (req, res) {
// Imports the Google Cloud client library
const Datastore = require('@google-cloud/datastore');
// Your Google Cloud Platform project ID
const projectId = 'moneypenny-dabc6';
// Instantiates a client
const datastore = Datastore({
projectId: projectId