Skip to content

Instantly share code, notes, and snippets.

View mallyvai's full-sized avatar
🐕
Reading this? Tweet me a dog photo

Vaibhav Mallya mallyvai

🐕
Reading this? Tweet me a dog photo
View GitHub Profile
require 'parallel'
Benchmark.measure do
query = ->(table) do
result = ActiveRecord::Base.connection.execute("CHECK TABLE #{table} EXTENDED;").to_a
puts result
result
end
result = Parallel.map(ActiveRecord::Base.connection.tables, in_processes: 10) { |table| query.call(table)}
end
@mallyvai
mallyvai / django_admin_thoughts.txt
Last active May 19, 2016 06:43
Thoughts on Django's admin UI
Django’s admin UI is wonderful, and a big part of the reason why we chose it for OfferLetter.io. Unfortunately the admin panel itself is extremely insecure, with simple password authentication and no modern security infrastructure.
Given how widely-used and critical this admin UI is, I think that adding better, modern security practices would go a long way to keeping Django safe. Some rough ideas are below, in rough order of ease of implementation.
> Logging CSRF exceptions as special SuspiciousOperation security exceptions. CSRF tokens/cookies exist to provide security, and if there is some rogue actor, I’d like to know about as soon as possible. This is easy now to do now using the 403 handler. But in my view, the sensible default here is to treat it as a security violation and SuspiciousOperation.
> Logging failed admin account login attempts as SuspiciousOperation (including the IP). This will be highly-leveraged - easy to implement and straightforward.
http://www.offerletter.io/wp-login.php
http://www.offerletter.io/xmlrpc.php
http://www.offerletter.io/administrator/index.php
http://www.offerletter.io/wp-signup.php
http://www.offerletter.io/wp-content/uploads/samplc.php
http://www.offerletter.io/wp-includes/routing.php
http://www.offerletter.io/wp-admin/admin-ajax.php
http://www.offerletter.io/index.php
http://www.offerletter.io/admin/include/ktt.php
http://www.offerletter.io/store/index.php/admin
LOGGING = {
'version': 1,
'disable_existing_loggers': True,
'root': {
'level': 'WARNING',
'handlers': ['sentry'],
},
'formatters': {
import json, requests
from django.http import HttpResponse
from django.shortcuts import render_to_response, render
from django.http import JsonResponse, HttpResponse
def test_loop(request):
print "in my glorious infinite loop"
while True:
@mallyvai
mallyvai / wsgi.py
Last active October 27, 2015 18:45
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings")
from django.core.wsgi import get_wsgi_application
from whitenoise.django import DjangoWhiteNoise
from raven.contrib.django.raven_compat.middleware.wsgi import Sentry
from django.core.wsgi import get_wsgi_application
Thanks for your interest in OfferLetter.io! Here's the fine print you are consenting to as you use this service:
The Advisers are just that - advisers. They are usually not employees of Smart Beehive. If they are, this will be made clear in the conversation.
If you use this service, you agree that neither Adviser(s), nor Smart Beehive Co., are liable for any negative consequences of any advice or action taken or given.
Smart Beehive Co. uses modern security practices, including two-factor authentication, and encryption, to protect your data, work history, and negotiation plan. In the event a leak does occur, your agree to hold Smart Beehive Co. free of any and all liability.
Although it has never happened, it is possible you may lose a job or job opportunity as a result of provided advice by Smart Beehive Co. or an Adviser. If this happens, you agree to hold both Smart Beehive Co. and your Advisers free of any liability.
@mallyvai
mallyvai / windows.h__.js
Created November 18, 2012 08:09
windows.h.js INFINITY
var ffi = require('ffi'),
ref = require('ref'),
Struct = require('ref-struct'),
Library = require('./Library'),
Type = ref.Type,
NULL = ref.NULL,
isNull = ref.isNull;
var groups = ['libs', 'types', 'structs', 'callbacks', 'enums'];
"""
Basic Python program for doing some stuff with the conversation format
you wanted.
--Vaibhav Mallya
"""
import sys
import nltk
sent_tokenize = nltk.tokenize.sent_tokenize
word_tokenize = nltk.tokenize.word_tokenize
@mallyvai
mallyvai / sum-of-squares.py
Created January 12, 2011 03:01
Facebook Hacker Cup Qual Round Problem #1
from math import sqrt, floor, ceil
def compute(num):
upper_bound = int(ceil(sqrt(num)))
counter = 0
lower_bound = int(sqrt(floor(num/2)))
for i in range(lower_bound, upper_bound+1):
diff = num - i**2
if diff < 0:
continue
s = sqrt(diff)