Skip to content

Instantly share code, notes, and snippets.

View rantav's full-sized avatar
🎯
Focusing

Ran Tavory rantav

🎯
Focusing
View GitHub Profile
@rantav
rantav / README.md
Created August 23, 2012 06:13
Find slow queries in mongo DB

A few show tricks to find slow queries in mongodb

Enable profiling

First, you have to enable profiling

> db.setProfilingLevel(1)

Now let it run for a while. It collects the slow queries ( > 100ms) into a capped collections, so queries go in and if it's full, old queries go out, so don't be surprised that it's a moving target...

@rantav
rantav / README.md
Created June 28, 2016 20:39
Encrypt in mysql, decrypt in javascript

What is this?

A way to encrypt data on mysql and then decrypt in javascript.

Why is this useful?

Sometimes you have data in your mysql database and you want to pass this data to a JS app.
For example, say you want to run an email campaign and you want to send emails to users from your mysql database. In this campaign you want ppl to click a link and when clicked you want the target site (your site) to be able to identify the user. You could pass the user-id as plaintext. Or the email as plain text. But that would be insulting the user's intelligence plus you might leak information "in the face" of a user. If you want to pass information from mysql to javascript and be able to obfuscate this info such that it isn't in the face of a user, this method is simple and effective.

This is not "secure"

@rantav
rantav / docker-ssh.zsh
Created May 8, 2018 08:32
Docker SSH - a simple shell (zsh) function to connect to a running docker container
##############################################
# Add this to your .zshrc
#
# And then:
# $ docker ps
# => find your container ID or name and
# $ docker-ssh <containerID or containerName>
#
##############################################
@rantav
rantav / README.md
Created June 27, 2012 05:18
MongoDB increment or insert

In mongodb it's easy to make at upsert, meaning update-or-insert by calling

db.collection.update({criteria}, {updated fields}, true)

The third parameter means - insert a new document if the document doesn't exist yet. So, for example, the following will insert a new document for the user if there's no document for that user yet, and will update it if it already exists:

 db.users.update({user_id: '1234'}, {user_id: '1234', name: 'Ran'}, true)
@rantav
rantav / README.md
Created July 22, 2021 09:31
Submit to Kaggle from within a kaggle notebook

Create a ~/.kaggle/kaggle.json file

This is a one-time operation you need to run per kernel

Go and download your kaggle.json file from your kaggle account page and replace YOUR_USERNAME and YOUR_KEY below.

Then run this code in a kaggle python cell

text_file = open("/root/.kaggle/kaggle.json", "w")
n = text_file.write('{"username":"YOUR_USERNAME","key":"YOUR_KEY"}')
text_file.close()
@rantav
rantav / cloudwatch-event-to-slack-lambda.md
Last active January 14, 2021 03:18
CloudWatch Events to Slack

Sends Cloudwatch Event notifications to Slack

What is this?

AWS have released a new featue called CloudWatch Events, which lets you configure events fired by cloudwatch and direct them to SNS, Lambda functions, etc. Here's the blog post

Motivational image:

Here's the motivational image:

Slack image

@rantav
rantav / mailmerge.gs
Last active August 12, 2020 09:09
Mail Merge
var EMAIL_SENT = 'EMAIL_SENT';
/**
* Sends emails from spreadsheet rows.
*/
function mailmerge() {
Logger.log('Starting mail merge...');
var ss = SpreadsheetApp.getActiveSpreadsheet();
var dataSheet = ss.getSheets()[0];
var startRow = 2; // First row of data to process
@rantav
rantav / spinnaker-rbac.yaml
Last active December 10, 2019 06:51
Kubernetes RBAC for Spinnaker
# Authorize read-write in the default namespace. Add this Role and the below RoleBinding to every namespace spinnaker deploys artifacts to
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: spinnaker-role
namespace: default
rules:
- apiGroups: [""]
resources: ["namespaces", "events", "replicationcontrollers", "serviceaccounts", "pods/logs"]
environment.servlets().addFilter("HttpErrorLoggerFilter", new HttpErrorLoggerFilter())
.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, "/*");
@rantav
rantav / AwsClientMetricsCollector.java
Created November 9, 2014 13:08
Collecting AWS client metrics into codahale metrics, in java
package ...;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.amazonaws.Request;