Skip to content

Instantly share code, notes, and snippets.

View Maslor's full-sized avatar

Gabriel Freire Maslor

View GitHub Profile
@Maslor
Maslor / ExpandableListView.java
Last active August 26, 2015 09:36 — forked from uphy/ExpandableListView.java
JavaFX Expandable ListView
/**
* Copyright (C) 2015 uphy.jp
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@Maslor
Maslor / Python.py
Created August 12, 2015 15:51
Simple example class in python. When object Python is created with a name argument, it prints said name.
class Python:
def __init__(self, name):
self.name = name
print name
@Maslor
Maslor / TicketLine.java
Created August 10, 2015 15:11
Receives an array of customer bills and returns YES or NO depending on whether you can or can't give them all change, assuming you start with 0$. Ticket value is 25 and customers only carry 3 kinds of bills: 25$, 50$ and 100$
public class TicketLine {
public static String Tickets(int[] peopleInLine) {
int money=0;
for(int i = 0;i<peopleInLine.length;i++){
if(peopleInLine[i] == 50){
if (money < 25) return "NO";
else money+=25;
}
@Maslor
Maslor / capitals.py
Created August 9, 2015 21:16
Lists a String's capital letters' index
def capitals(word):
lst = []
for i,ch in enumerate(word):
if ch.isupper():
lst.append(i)
return lst
@Maslor
Maslor / BatmanQuotes.java
Last active August 29, 2015 14:26
Receives an array of quotes and the name of the hero. Said hero will have one of its letters replaced by a number, which indicates which quote he says.
import java.util.regex.Pattern;
import java.util.regex.Matcher;
public class BatmanQuotes{
public static int indexOf(Pattern pattern, String s) {
Matcher matcher = pattern.matcher(s);
return matcher.find() ? matcher.start() : -1;
}
@Maslor
Maslor / Bio.java
Created August 6, 2015 22:54
Method that replaces a specified String by another one in all of the first String's extension. In this case, all instances of the letter "T" in the input string are replaced by "U"
import java.lang.StringBuilder;
public class Bio {
public static String dnaToRna(String dna){
StringBuilder strb = new StringBuilder(dna);
while(strb.indexOf("T") != -1) {
strb.replace(strb.indexOf("T"),strb.indexOf("T")+1,"U");
}
@Maslor
Maslor / Negative.java
Created August 6, 2015 22:24
return the symmetric of a positive number. Negative numbers aren't altered
public class Negative {
public static int makeNegative(final int x) {
if(x >= 0) return -x;
else return x;
}
}
@Maslor
Maslor / Number.java
Created August 6, 2015 22:21
returns true if inserted number is even, false otherwise
public class Number {
public boolean isEven(double n) {
if (n % 2 == 0) return true;
else return false;
}
}
@Maslor
Maslor / ReverseLongerStr.java
Created August 6, 2015 22:10
class that reverses a long string efficiently with StringBuilder
import java.lang.StringBuilder;
public class ReverseLonger {
public static String shorterReverseLonger(String a, String b) {
if (a.length() < b.length()) {
return a + reverse(b) + a;
} else {
return b + reverse(a) + b;
}
@Maslor
Maslor / SquareDigit.java
Created August 6, 2015 20:58
class which method receives an Integer and returns an Integer that results of the square of each of the input Integer's digits. i.e. Input: 9119 Output: 811181
import java.util.LinkedList;
import java.lang.Math;
public class SquareDigit {
LinkedList<Integer> stack = new LinkedList<Integer>(); //stack where I'll push each digit for easy ordered extraction
String str = "";
/**
* this method receives a number and returns a number which digits are the input number's digits square.