Skip to content

Instantly share code, notes, and snippets.

from datetime import datetime, timedelta
import cryptography
from cryptography.fernet import Fernet
class ExpiringTokenGenerator:
FERNET_KEY = 'H-gvBa31So7ZWRlIleY7q5xYPIytGnRHRcBpRbASyao='
fernet = Fernet(FERNET_KEY)
DATE_FORMAT = '%Y-%m-%d %H-%M-%S'
def square(func):
def inner(x):
r = func(x)
r = r * r
return r
return inner
def plus5(x):
return x + 5
//
// main.m
// Objective
//
// Created by Petko Minkov on 8/20/15.
// Copyright (c) 2015 Petko. All rights reserved.
//
#import <Foundation/Foundation.h>
@pminkov
pminkov / sigmoid.m
Created July 30, 2012 05:31
Sigmoid function
function g = sigmoid(z)
%SIGMOID Compute sigmoid functoon
% J = SIGMOID(z) computes the sigmoid of z.
g = arrayfun( @(x) 1 / (1 + e^(-x)), z);
% =============================================================
end
@pminkov
pminkov / nn_and.m
Created July 30, 2012 05:21
Plot f(x1, x2)
n = 50
m = 0
x1 = linspace(0 - m, 1 + m, n);
x2 = linspace(0 - m, 1 + m, n);
a = zeros(n, n);
for i1 = 1:n
@pminkov
pminkov / f.scala
Created April 28, 2012 06:18
Scala scope
/** Return the square of all positive numbers in x
* which are also present in y.
*/
def f(x: List[Int], y: List[Int]): List[Int] = {
val filtered = {
val iny = x.filter(v => y.contains(v))
val pos = iny.filter(_ > 0)
pos
}
@pminkov
pminkov / dedupe.cc
Created March 7, 2012 07:44
Dedupe - C++ solution
#include <iostream>
#include <set>
#include <vector>
using namespace std;
#define SIZE(arr) (sizeof(arr) / sizeof(arr[0]))
int main() {
int aa[3] = {1, 2, 5};
int bb[5] = {6, 5, 1, 7, 5};
@pminkov
pminkov / dedupe.scala
Created March 7, 2012 07:24
Scala deduping
val a = List(1, 2, 5)
val b = List(6, 5, 1, 7, 5)
val c = List(2, 8, 16, 8)
val all = List(a, b, c)
val initial = (List.empty[List[Int]], Set.empty[Int])
val (nodups, used) = all.foldLeft(initial)((state, list) => {
val (lists, used) = state
@pminkov
pminkov / http_simulate_view.py
Created November 12, 2011 03:17
View for http simulate.
from django.shortcuts import render_to_response
from django.http import HttpResponse
import middleware
def main(request):
response = HttpResponse()
middleware.IN_ERROR_MODE = not middleware.IN_ERROR_MODE
response.write('Error mode = ' + str(middleware.IN_ERROR_MODE))
@pminkov
pminkov / middleware.py
Created November 12, 2011 03:14
Middleware class to simulate http errors.
from django.http import HttpResponse
IN_ERROR_MODE = False
class SimulatorMiddleware:
"""Modifies the HTTP response.
"""
def process_request(self, request):
if request.path.startswith('/http_simulate'):
return None