Skip to content

Instantly share code, notes, and snippets.

View Maslor's full-sized avatar

Gabriel Freire Maslor

View GitHub Profile
@Maslor
Maslor / findUser.java
Last active August 29, 2015 14:25
Getting a subclass element from the abstract superclass type list
private List<Manager> _managers = new ArrayList<Manager>();
private List<Employee> _employees = new ArrayList<Employee>();
private List<User> _usrs = new ArrayList<User>();
public User findUser(String userID){
refreshUserList(); //updates _usrs so it has all the current users
Iterator<User> i;
User u = null; //abstract class User
i = this._usrs.iterator();
@Maslor
Maslor / interpol.bat
Created July 31, 2015 16:18
Just a funny script to run on a windows terminal. It basically opens some terminal windows and infinitely prints the message in each of them.
mklink "C:\Users\Gabriel\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\ip.lnk" "interpol.bat"
set var1=You have been tracked by Interpol. Turn your terminal off and await the local authorities calmly.
set var2=You are being arrested for posession of illegal digital content.
set cont=500
:loop
echo ALERT!
if %cont% equ 0 goto end
set /a cont=cont-1
@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.
@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 / 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 / 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 / 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 / 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 / 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 / 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;
}