Skip to content

Instantly share code, notes, and snippets.

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

Juan Ariel Brusco juanbrusco

🏠
Working from home
View GitHub Profile
@juanbrusco
juanbrusco / truncate.js
Created August 30, 2018 19:02
Truncate a string - Javascript
truncate (str, length, ending) {
if (length == null) {
length = 100;
}
if (ending == null) {
ending = '...';
}
if (str.length > length) {
return str.substring(0, length - ending.length) + ending;
} else {
@juanbrusco
juanbrusco / check-empty.js
Created August 30, 2018 19:06
Check empty - Javascript
isEmpty(myObject) {
for(var key in myObject) {
if (myObject.hasOwnProperty(key)) {
return false;
}
}
return true;
};
@juanbrusco
juanbrusco / parsing-json-object.swift
Last active August 31, 2018 22:06
Parsing json objects - Swift
//JSON example
{
"ObjectList": [
{
"x": "Starbucks",
"y": "asd"
},
{
"x": "Starbucks",
"y": "asd"
@juanbrusco
juanbrusco / merge-two-arr.js
Created August 31, 2018 22:02
Merge 2 arrays - Javascript
merge_array(array1, array2) {
const result_array = [];
const arr = array1.concat(array2);
let len = arr.length;
const assoc = {};
while (len--) {
const item = arr[len];
if (!assoc[item]) {
@juanbrusco
juanbrusco / merge-three-arr.js
Created August 31, 2018 22:03
Merge 2 arrays - Javascript
merge_array(array1, array2, array3) {
const result_array = [];
array1.concat(array2, array3).forEach(item => {
if (result_array.indexOf(item) == -1)
result_array.push(item);
});
return result_array;
}
@juanbrusco
juanbrusco / add-no-existing.js
Created August 31, 2018 22:05
Add item to array (if exists then remove) - Javascript
this.array = [];
selectCarouselItem(itemToAdd) {
if (this.array.indexOf(itemToAdd) != -1) {
this.array.splice(this.array.indexOf(itemToAdd), 1)
} else {
this.array.push(itemToAdd);
}
}
@juanbrusco
juanbrusco / recursive.java
Created September 5, 2018 15:44
Recursive function with ArrayList - Java
public static ArrayList<E> getFunction(Object x, int level, ArrayList<E> list) {
if (level == 1) {
Object x2 = DB.getInstance().getObjectById(x.getID());
list.add(x2);
return list;
} else {
Object x2 = DB.getInstance().getObjectById(x.getID());
level = level - 1;
list.add(x2);
return getFunction(x2, level, list);
@juanbrusco
juanbrusco / detect-duplicate.ftl
Created September 5, 2018 20:54
Detect duplicates into list - Freemarker
<#assign newList = [] />
<#list response.data.items as originalList>
<#if ! newList?seq_contains(originalList.xValue)>
<#assign newList = newList + [originalList.xValue] />
</#if>
</#list>
@juanbrusco
juanbrusco / heart-animation-icon.scss
Created September 5, 2018 20:56
Heart animation - SCSS
//animation like - twitter opt1
.heart {
width: 50px;
height: 50px;
background: url("https://cssanimation.rocks/images/posts/steps/heart.png") no-repeat;
background-size: cover;
background-position: 0 -7px;
cursor: pointer;
transition: background-position 1s steps(28);
transition-duration: 0s;
@juanbrusco
juanbrusco / responsive-values.txt
Created September 5, 2018 20:57
Responsive values (Bootstrap) - Text
xs
0 - 576px
sm
> 576px
md
> 768px
lg
> 992px
xl
> 1200px