This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def square(func): | |
def inner(x): | |
r = func(x) | |
r = r * r | |
return r | |
return inner | |
def plus5(x): | |
return x + 5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// main.m | |
// Objective | |
// | |
// Created by Petko Minkov on 8/20/15. | |
// Copyright (c) 2015 Petko. All rights reserved. | |
// | |
#import <Foundation/Foundation.h> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** 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 | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |