Skip to content

Instantly share code, notes, and snippets.

View dusanstanojeviccs's full-sized avatar
🔭
Building Traceway

narrow-adventure dusanstanojeviccs

🔭
Building Traceway
View GitHub Profile
@dusanstanojeviccs
dusanstanojeviccs / conv2d_output_size.py
Last active December 29, 2019 08:42
PyTorch - How to calculate the Conv2d output (stride, padding, dilation)
def conv2d_output(conv_layer, input_height = 128, input_width = 128):
"""Calculates the output dimensions of a convolutional layer in PyTorch.
Keyword arguments:
conv_layer -- the nn.Conv2d object
input_height -- the height of the input image to be processed by Conv2d
input_width -- the width of the input image to be processed by Conv2d
"""
# We need to get all of the values from the conv layer
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.jspdf=e()}(this,function(){"use strict";var t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},e=(function(){function t(t){this.value=t}function e(e){function n(i,o){try{var a=e[i](o),s=a.value;s instanceof t?Promise.resolve(s.value).then(function(t){n("next",t)},function(t){n("throw",t)}):r(a.done?"return":"normal",a.value)}catch(t){r("throw",t)}}function r(t,e){switch(t){case"return":i.resolve({value:e,done:!0});break;case"throw":i.reject(e);break;default:i.resolve({value:e,done:!1})}(i=i.next)?n(i.key,i.arg):o=null}var i,o;this._invoke=function(t,e){return new Promise(function(r,a){var s={key:t,arg:e,resolve:r,reject:a,next:null};o?o=o.next=s:(i=o=s,n(t,e))})},"function"!=typeof e.return&&(this.return=void 0)}"function"==
public void update(Book book) throws SQLException {
PreparedStatement preparedStatement = database.getConnection().prepareStatement("update books set title = ?, description = ? where id = ?");
preparedStatement.setString(1, book.getTitle());
preparedStatement.setString(2, book.getDescription());
preparedStatement.setInt(3, book.getId());
preparedStatement.executeUpdate();
}
public void add(Book book) throws SQLException {
// Book has no id because we are adding a new one to the database
PreparedStatement preparedStatement = database.getConnection().prepareStatement("insert into books (id, title, description) values (null, ?, ?)", Statement.RETURN_GENERATED_KEYS);
preparedStatement.setString(1, book.getTitle());
preparedStatement.setString(2, book.getDescription());
preparedStatement.execute();
// after inserting we want to get the generated id
ResultSet rs = preparedStatement.getGeneratedKeys();
public void delete(int id) throws SQLException {
PreparedStatement preparedStatement = database.getConnection().prepareStatement("delete from books where id = ?");
preparedStatement.setInt(1, id);
preparedStatement.execute();
}
public Optional<Book> findById(int id) throws SQLException {
PreparedStatement preparedStatement = database.getConnection().prepareStatement("select * from books where id = ?");
preparedStatement.setInt(1, id);
preparedStatement.execute();
ResultSet rs = preparedStatement.getResultSet();
if (rs.next()) {
public List<Book> findAll() throws SQLException {
PreparedStatement preparedStatement = database.getConnection().prepareStatement("select * from books");
List<Book> books = new ArrayList<>();
preparedStatement.execute();
ResultSet rs = preparedStatement.getResultSet();
while (rs.next()) {
package controllers;
import com.google.inject.Inject;
import play.db.Database;
import play.libs.Json;
import play.mvc.Controller;
import play.mvc.Result;
public class BookController extends Controller {
package books;
import com.google.inject.Inject;
import play.db.Database;
import play.libs.Json;
import play.mvc.Controller;
import play.mvc.Result;
public class BookController extends Controller {
package repositories;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import java.sql.*;
import java.util.*;
import play.db.*;