Skip to content

Instantly share code, notes, and snippets.

@viksit
viksit / checkin.py
Created May 24, 2016 21:49
grpc and gevent thread pool executor
class ThreadPoolExecutor(concurrent.futures.ThreadPoolExecutor):
"""
A version of :class:`concurrent.futures.ThreadPoolExecutor` that
always uses native threads, even when threading is monkey-patched.
.. versionadded:: 1.2a1
"""
def __init__(self, max_workers):
super(ThreadPoolExecutor, self).__init__(max_workers)
@viksit
viksit / async_flask.py
Created March 28, 2016 20:01 — forked from sergray/async_flask.py
Asynchronous requests in Flask with gevent
"""Asynchronous requests in Flask with gevent"""
from time import time
from flask import Flask, Response
from gevent.pywsgi import WSGIServer
from gevent import monkey
import requests
@viksit
viksit / seq2seqRNN.py
Last active March 21, 2022 15:10
Simple Keras recurrent neural network skeleton for sequence-to-sequence mapping
__author__ = 'Conan'
import numpy as np
import random
from keras.models import Sequential
from keras.layers.recurrent import SimpleRNN
# Toy dictionary of 1000 indices to random length 10 vectors
@viksit
viksit / bootstrap.html
Created November 4, 2018 17:50 — forked from kolorobot/bootstrap.html
Complete Bootstrap Starter Template with pre-defined CDN paths
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<meta name="description" content=""/>
<meta name="author" content=""/>
@viksit
viksit / java_mysql_password.java
Created September 20, 2013 21:38
Java equivalent of the MySQL PASSWORD() function
/**
* http://stackoverflow.com/questions/868482/simulating-mysqls-password-encryption-using-net-or-ms-sql
* http://dev.mysql.com/doc/refman/5.0/en/encryption-functions.html#function_password
**/
public static String MySQLPassword(String plainText) throws UnsupportedEncodingException {
byte[] utf8 = plainText.getBytes("UTF-8");
return "*" + DigestUtils.shaHex(DigestUtils.sha(utf8)).toUpperCase();
}
@viksit
viksit / startx.sh
Created April 20, 2018 21:15
Start screen session with custom script
viksit@gpu3-4-k80:~$ cat startx.sh
screen -AdmS viksit -t tab0 bash
screen -S viksit -X screen -t jup0 bash /home/viksit/j.sh
screen -S viksit -X screen -t tsb0 bash /home/viksit/t.sh
@viksit
viksit / integrate.html
Last active November 17, 2017 22:05
Myra Labs Widget Integration Snippet
<script>
(function() {
var w = window;
var mcs = w.MyraConciergeSettings;
var d = document;
function l() {
var s = d.createElement('script');
s.type = 'text/javascript';
s.async = true;
s.src = '//cdn-prod.myralabs.com/widget/v3/widget.CUSTOMER_ID.js';
@viksit
viksit / kullback_leibler.py
Created August 31, 2017 18:38 — forked from ognis1205/kullback_leibler.py
Calculate Kullback-Leibler Divergence of Given Corpus
#!/usr/bin/env python
# -*- coding: utf-8 -*-
""" Caluculates symmetric Kullback-Leibler divergence.
@author Shingo OKAWA
"""
import numpy
import sys
import scipy.stats as stats
import matplotlib.pyplot as plotter
from gensim import corpora, models, similarities, matutils
@viksit
viksit / rank_metrics.py
Created August 20, 2017 23:57 — forked from shashankg7/rank_metrics.py
Ranking Metrics
"""Information Retrieval metrics
Useful Resources:
http://www.cs.utexas.edu/~mooney/ir-course/slides/Evaluation.ppt
http://www.nii.ac.jp/TechReports/05-014E.pdf
http://www.stanford.edu/class/cs276/handouts/EvaluationNew-handout-6-per.pdf
http://hal.archives-ouvertes.fr/docs/00/72/67/60/PDF/07-busa-fekete.pdf
Learning to Rank for Information Retrieval (Tie-Yan Liu)
"""
import numpy as np
import tensorflow as tf
import numpy as np
class ConvolutionalAttentionNLI(object):
def __init__(self, embeddings_shape, target_classes=2, conv_filter_size=3, conv_projection_size=300, attention_output_size=200, comparison_output_size=100, learning_rate=0.05):
self._embeddings_shape = embeddings_shape
self._target_classes = target_classes
self._conv_filter_size = conv_filter_size
self._conv_projection_size = conv_projection_size