Skip to content

Instantly share code, notes, and snippets.

View drvarya's full-sized avatar
🎯
Focusing

Dhruv Arya drvarya

🎯
Focusing
View GitHub Profile
@mrflip
mrflip / gist:766608
Created January 5, 2011 17:15
Elasticsearch shell config
We couldn’t find that file to show.
@jdp
jdp / searchindex.py
Created November 25, 2012 00:06
Autocomplete search with Redis and Python
from functools import partial
from itertools import imap, izip, product
from redis import Redis
class SearchIndex(object):
"""Autocomplete search index.
>>> index = SearchIndex(Redis())
@veselosky
veselosky / s3gzip.py
Last active August 29, 2024 11:32
How to store and retrieve gzip-compressed objects in AWS S3
# vim: set fileencoding=utf-8 :
#
# How to store and retrieve gzip-compressed objects in AWS S3
###########################################################################
#
# Copyright 2015 Vince Veselosky and contributors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
function proxyMethods(proxyObj, originalObj, props) {
props.forEach(function(method) {
proxyObj[method] = function() {
return originalObj[method](...arguments);
};
});
}
function proxyProps(proxyObj, originalObj, props) {
props.forEach(function(prop) {
@spro
spro / pytorch-simple-rnn.py
Last active April 24, 2026 12:34
PyTorch RNN training example
import torch
import torch.nn as nn
from torch.nn import functional as F
from torch.autograd import Variable
from torch import optim
import numpy as np
import math, random
# Generating a noisy multi-sin wave
import torch
from torch import nn
from torch.autograd import Variable
import torch.nn.functional as F
class RNN(nn.Module):
def __init__(self, input_size, hidden_size, output_size, n_layers=1):
super(RNN, self).__init__()
self.input_size = input_size
self.hidden_size = hidden_size
@kkweon
kkweon / DQN_PyTorch.py
Created June 8, 2017 22:18
PyTorch DQN implementation
"""
DQN in PyTorch
"""
import argparse
import torch
import torch.nn
import numpy as np
import random
import gym
import json
import os
import urllib.request
def format_message(data):
severity_level = get_severity_level(data['detail']['severity'])
payload = {
'username': 'GuardDuty Finding',
'icon_emoji': ':guardduty:',
'text': '{} GuardDuty Finding in {}'.format(severity_level['mention'], data['detail']['region']),
@Cediddi
Cediddi / pg10_partition_compiler_sqla.py
Last active September 12, 2019 16:44
Simple helper that enables Postgresql 10's declarative partitioning features.
import textwrap
from sqlalchemy.ext.compiler import compiles
from sqlalchemy.sql.ddl import CreateTable
@compiles(CreateTable, "postgresql")
def pg10_partition_compiler(element, compiler, **kw):
"""
Simple helper that enables Postgresql 10's declarative partitioning features.
partition_by : str = Plain sql string that defines partition rules for the parent table.