Skip to content

Instantly share code, notes, and snippets.

View bocato's full-sized avatar

Eduardo Bocato bocato

View GitHub Profile
@bocato
bocato / Duplicates.java
Last active February 11, 2016 12:04
Find Duplicate Objects Generic Java Collection
public <T> List<T> getDuplicate(Collection<T> list) {
final List<T> duplicatedObjects = new ArrayList<T>();
Set<T> set = new HashSet<T>() {
@Override
public boolean add(T e) {
if (contains(e)) {
duplicatedObjects.add(e);
}
return super.add(e);
}
@bocato
bocato / Lazy.java
Last active November 7, 2016 13:15
Fugindo do Erro de Lazy no Hibernate
@Override
public List<Task> findAllByProcess(Long processId) throws SGPIException {
/**
* Como ProcessDefinition é um relacionamento com fetchType=LAZY, se eu passar uma lista e
* depois tentar pedir algum parametro desta lista ele será obrigado
* a instanciar o objeto, portanto passa a ser acessível e não vai
* mais dar erro de LAZY.
* */
List<Task> tasks = taskRepository.findAllByProcess(processId);
for (Task task : tasks) {
@bocato
bocato / icloud-reminders-as-text.js
Created March 7, 2016 14:09 — forked from duncansmart/icloud-reminders-as-text.js
Get iCloud Reminders as text
[].map.call(document.querySelectorAll('iframe[name=reminders]')[0].contentDocument.querySelectorAll('.reminder-not-completed-view .reminder-row .reminder-title'), function(el) {
return el.textContent;
}).join('\r\n');
@bocato
bocato / iCloudRemindersAsText.js
Created March 7, 2016 14:11
iCloudRemindersAsText.js
[].map.call(document.querySelectorAll('iframe[name=reminders]')[0].contentDocument.querySelectorAll('.reminder-not-completed-view .reminder-row .reminder-title'), function(el) {
return el.textContent;
}).join('\r\n');
@bocato
bocato / ResultSetConverter.java
Created March 31, 2016 20:52
Converts ResultSet object to JSONArray
import org.json.JSONArray;
import org.json.JSONObject;
import org.json.JSONException;
import java.sql.SQLException;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
public class ResultSetConverter {
public static JSONArray convert( ResultSet rs )
@bocato
bocato / RotationHack.m
Created June 30, 2016 13:20
Hack to control screen orientation on iPad/iPhone for a specific inner ViewController
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
if ([self.currentViewController isEqual:self.viewControllerYouDontWantToRotate])
{
return UIInterfaceOrientationMaskPortrait;
}
else
{
return UIInterfaceOrientationMaskAll;
}
@bocato
bocato / ScrollDirection.m
Last active March 3, 2017 13:53
Get scroll direction from ScrollViiew.
typedef enum ScrollDirection {
ScrollDirectionNone,
ScrollDirectionRight,
ScrollDirectionLeft,
ScrollDirectionUp,
ScrollDirectionDown
} ScrollDirection;
@property ScrollDirection lastScrollDirection;
@property (nonatomic, assign) CGFloat lastContentOffset;
@bocato
bocato / CustomPageControl.m
Created March 4, 2017 06:55
Customizing UIPageControl dotImages.
#import "CustomPageControl.h"
@interface CustomPageControl ()
#pragma mark - View Properties
@property (nonatomic,strong) UIImage *selectedImage;
@property (nonatomic,strong) UIImage *normalImage;
@end
@bocato
bocato / HideShowKeyboard.m
Created March 8, 2017 18:39
Hide show keyboard on TableView/CollectionView
#pragma mark - Hide/Show Keyboard on TableView
// Configure this when loading the view (can be inside viewDidLoad)
self.tableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeInteractive;
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(keyboardWillShowWithNotification:) name:UIKeyboardWillShowNotification object:nil];
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(keyboardWillHideWithNotification:) name:UIKeyboardWillHideNotification object:nil];
// Then implement this
- (void)keyboardWillShowWithNotification:(NSNotification *)notification {
CGRect keyboardFrame = [((NSValue *) notification.userInfo[UIKeyboardFrameEndUserInfoKey]) CGRectValue];
CGFloat bottomInset = keyboardFrame.size.height != 0 ? keyboardFrame.size.height : 0;
TAGS="TODO:|FIXME:"
find "${SRCROOT}" \( -name "*.h" -or -name "*.m" -or -name "*.swift" \) -print0 | xargs -0 egrep --with-filename --line-number --only-matching "($TAGS).*\$" | perl -p -e "s/($TAGS)/ warning: \$1/"