Skip to content

Instantly share code, notes, and snippets.

@indrekots
indrekots / mass_aspect_ratio_fix.md
Created September 21, 2016 15:48
How to mass update image files and fix their aspect ratio
  • Find all image files
find . -type f -name "*.jpg" > images
  • Determine if image file is portrait or landscape
find . -type f -name "*.jpg" -exec sh -c "identify -ping -format '%W/%H>1' {} | bc -l" \; > aspect
public class BookFilterRunner {
public static void main(String[] args) {
//create a list of books
List<Book> books = new ArrayList<>();
books.add(new Book("Moby Dick", 250, "Herman Melville"));
books.add(new Book("Alice's Adventures in Wonderland", 190, "Lewis Carrol"));
books.add(new Book("Sylvie and Bruno", 400, "Lewis Carrol"));
//filter a list of books
filterBooks(books, "Lewis Carrol");
//
// SmoothScroll for websites v1.2.1
// Licensed under the terms of the MIT license.
//
// You may use it in your theme if you credit me.
// It is also free to use on any individual website.
//
// Exception:
// The only restriction would be not to publish any
// extension for browsers or native application
@indrekots
indrekots / argumentCaptor.java
Last active January 4, 2016 09:29
How to capture values with ArgumentCaptor
UserDao userDao = Mockito.mock(UserDao.class);
ArgumentCaptor<User> captor = ArgumentCaptor.forClass(User.class);
Mockito.verify(userDao).save(captor.capture());
//do some testing logic, eg. call save on a userService object,
//which internally uses userDao to save the user object
//get the user as it was passed to the save method in userDao
User user = captor.getValue()
@indrekots
indrekots / verityTimes.java
Created January 18, 2014 11:14
Verifying the number of times a method is called with Mockito
Mockito.verify(userDao, Mockito.times(2)).save(Mockito.any(User.class));
@indrekots
indrekots / verify.java
Created January 11, 2014 21:47
verifying behavior with Mockito
UserService userService = new UserService();
UserDao userDao = Mockito.mock(UserDao.class);
userService.setUserDao(userDao);
User user = new User("Luigi");
userService.registerNewUser(user);
Mockito.verify(userDao).save(Mockito.any(User.class));
@indrekots
indrekots / mockitoWhenThenThrow.java
Created January 4, 2014 09:04
Subbing a behavior which throws an exception in Mockito
Mockito.when(userDao.getUserById(111)).thenThrow(new NoResultException());
@indrekots
indrekots / whenThenReturn.java
Created December 30, 2013 21:54
Example on how to stub methods with Mockito
Mockito.when(userDao.getUserById(1L)).thenReturn(new User("Mario"));
@indrekots
indrekots / mock.java
Created December 24, 2013 17:12
Creating a mock class with Mockito
UserDao userDao = Mockito.mock(UserDao.class);
@indrekots
indrekots / default-filters.php
Last active December 27, 2015 02:19
A section from the default-filters.php file in Wordpress
<?php
// Display filters
add_filter( 'the_title', 'wptexturize' );
add_filter( 'the_title', 'convert_chars' );
add_filter( 'the_title', 'trim' );
add_filter( 'the_content', 'wptexturize' );
add_filter( 'the_content', 'convert_smilies' );
add_filter( 'the_content', 'convert_chars' );