Skip to content

Instantly share code, notes, and snippets.

@sudeepraja
sudeepraja / bandits.py
Last active June 18, 2023 23:04
Code to test different exploration strategies for Multi armed bandits
import numpy as np
import matplotlib.pyplot as plt
import math
number_of_bandits=10
number_of_arms=10
number_of_pulls=30000
epsilon=0.3
temperature=10.0
min_temp = 0.1
decay_rate=0.999
@robyoung
robyoung / isolation_level.py
Last active January 31, 2022 06:35
Flask-SQLAlchemy set per request isolation level
def isolation_level(level):
"""Return a Flask view decorator to set SQLAlchemy isolation level
Usage::
@main.route("/thingy/<id>", methods=["POST"])
@isolation_level("SERIALIZABLE")
def update_a_thing(id):
...
"""
def decorator(view):
@fitnr
fitnr / git-archive-file.sh
Last active December 4, 2015 23:42
Great a nicely-named archive file from your git repository
#!/bin/bash
# Save this somewhere in your path as "git-archive-file"
# and do 'chmod u+x git-archive-file'
# If run at tag "v10.0", archvie file will be named "repo-v10.0.zip"
# If run after one commit after a tag, file will be named "repo.v10.0-1-gdc03bc1.branchname.zip"
# adapted from
# http://blog.thehippo.de/2012/03/tools-and-software/how-to-create-a-custom-git-command-extension/
@stephenash
stephenash / README.md
Created October 22, 2014 21:00
Django on ElasticBeanstalk - HTTP to HTTPS redirects

I needed a way to have my Django ElasticBeanstalk application automatically redirect HTTP requrests to HTTPS. Rick Christianson wrote a post [1] about how to do this by overwriting the wsgi.conf file with one that was slightly modified to support the HTTP to HTTPS redirect.

Building off the shoulders of giants, I wanted to do the same, but not have to keep a copy of the config file in my local source directory. Christianson even points out in his post that if ElasticBeanstalk ever changes it's template for the wsgi.conf file, those updates would not be overwritten and you wouldn't get their benefits. To get around that problem, I used sed to insert the new lines into the wsgi.conf file.

References

  1. http://rickchristianson.wordpress.com/2013/11/02/updating-wsgi-automatically-in-amazon-aws/
  2. http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers-ec2.html#customize-containers-format-container_commands
package main
import (
"fmt"
"log"
"net/http"
"html/template"
"github.com/gorilla/sessions"
@staltz
staltz / introrx.md
Last active October 14, 2025 19:39
The introduction to Reactive Programming you've been missing
@ichaos
ichaos / chinamap.c
Last active August 29, 2015 14:00
Print China map
/*
* Magic code to print china map.
* The original idea is from International Obfuscated C Code test, check more here.
* http://stackoverflow.com/questions/3533348/how-does-this-code-generate-the-map-of-india
*/
#include <stdio.h>
int main(){int a,b,c; for (b = c = 10; (a =
"-FIGURE?,China *CJ Hello Folks,\
b&M\"D(G*>/#\";,B1:0=12<924;554D\
*76`<W#!?UEZ>YCWEWFTJOP$%CXAX@Z?\
@ketaro
ketaro / mainsite_tests.py
Last active December 4, 2015 05:08
Writing Tests with Flask
if __name__ == '__main__':
import os, sys
basedir = os.path.abspath(os.path.dirname(__file__) + '/../')
sys.path.insert(0, basedir)
from app import app, db
from hakaru_test import MyAppTest
from pyquery import PyQuery as pq
from app.model import *
@wbroek
wbroek / genymotionwithplay.txt
Last active February 13, 2025 09:37
Genymotion with Google Play Services for ARM
NOTE: Easier way is the X86 way, described on https://www.genymotion.com/help/desktop/faq/#google-play-services
Download the following ZIPs:
ARM Translation Installer v1.1 (http://www.mirrorcreator.com/files/0ZIO8PME/Genymotion-ARM-Translation_v1.1.zip_links)
Download the correct GApps for your Android version:
Google Apps for Android 6.0 (https://www.androidfilehost.com/?fid=24052804347835438 - benzo-gapps-M-20151011-signed-chroma-r3.zip)
Google Apps for Android 5.1 (https://www.androidfilehost.com/?fid=96042739161891406 - gapps-L-4-21-15.zip)
Google Apps for Android 5.0 (https://www.androidfilehost.com/?fid=95784891001614559 - gapps-lp-20141109-signed.zip)
#!/usr/bin/ruby
# Create display override file to force Mac OS X to use RGB mode for Display
# see http://embdev.net/topic/284710
require 'base64'
data=`ioreg -l -d0 -w 0 -r -c AppleDisplay`
edids=data.scan(/IODisplayEDID.*?<([a-z0-9]+)>/i).flatten
vendorids=data.scan(/DisplayVendorID.*?([0-9]+)/i).flatten