Skip to content

Instantly share code, notes, and snippets.

View yavuztas's full-sized avatar
🏠
Working from home

Yavuz Tas yavuztas

🏠
Working from home
View GitHub Profile
@yavuztas
yavuztas / vue-event-bus.js
Last active January 7, 2021 22:17
add handler method this scope capability
/**
* A Simple EventBus Plugin for Vue
*/
export default {
$eventBus: null,
install (Vue) {
this.$eventBus = new Vue()
},
# Assuming you did not commit the file, or add it to the index, then:
git checkout -- filename
# Assuming you added it to the index, but did not commit it, then:
git reset HEAD filename
git checkout -- filename
# Assuming you did commit it, then:
git checkout origin/master filename
@yavuztas
yavuztas / git-pick-specific-commits-from-another-branch.txt
Created October 13, 2019 10:52
git cherry-pick some commits from another branch
# if you want to pick some commits from <some-branch> to master for example,
# switch to master
git checkout master
# pick the commits you want to apply to master
git cherry-pick a52afa1
git cherry-pick 08f39f7
# if there is a conflict, resolve and commit
/.classpath
/.project
/.settings/
/target/
@yavuztas
yavuztas / article-java-utility-collections-snippet.java
Last active August 27, 2019 15:21
Created with Copy to Gist
String[] array = new String[] {
"apple", "banana", "orange", "avocado", "mango"
};
String joined = UtilsForCollections.join(array, ", ", 3);
System.out.println(joined);
@yavuztas
yavuztas / UtilsForCollections.java
Last active August 27, 2019 15:28
Created with Copy to Gist
public static <T> String join(T[] array, String separator) {
return UtilsForCollections.join(array, separator, 0);
}
public static <T> String join(T[] array, String separator, int limit) {
if (limit > 0 && array.length > limit) {
return Arrays.stream(array)
.limit(limit)
.map(String::valueOf)
.collect(Collectors.joining(separator)) + separator + "...";
}
@yavuztas
yavuztas / article-java-utility-collections-snippet.java
Last active August 27, 2019 15:21
Created with Copy to Gist
String[] array = new String[] {
"apple", "banana", "orange", "avocado", "mango"
};
List<String> filtered = UtilsForCollections.filterArray(array, v -> v.startsWith("a"));
filtered.forEach(System.out::println);
@yavuztas
yavuztas / UtilsForCollections.java
Last active August 27, 2019 15:24
Created with Copy to Gist
public static <T> List<T> filterArray(T[] array, Predicate<? super T> predicate) {
return Arrays.stream(array)
.filter(predicate)
.collect(Collectors.toCollection(ArrayList::new));
}
public static <T> List<T> filterCollection(
Collection<T> collection, Predicate<? super T> predicate) {
return collection.stream()
.filter(predicate)
@yavuztas
yavuztas / UtilsForCollections.java
Last active August 27, 2019 15:30
Created with Copy to Gist
public static <T> List<T> toList(Collection<T> collection) {
return collection.stream().collect(Collectors.toList());
}
public static <T> Set<T> toSet(Collection<T> collection) {
return UtilsForCollections.toSet(collection, false);
}
public static <T> Set<T> toSet(Collection<T> collection, boolean preserveOrder) {
if (preserveOrder) {
return collection.stream()
.collect(Collectors.toCollection(LinkedHashSet::new));
@yavuztas
yavuztas / UtilsForCollections.java
Last active August 27, 2019 15:25
Created with Copy to Gist
public static <T> Set<T> toSet(T[] array) {
return UtilsForCollections.toSet(array, false);
}
public static <T> Set<T> toSet(T[] array, boolean preserveOrder) {
if (preserveOrder) {
return Arrays.stream(array)
.collect(Collectors.toCollection(LinkedHashSet::new));
}
return Arrays.stream(array).collect(Collectors.toSet());
}