Skip to content

Instantly share code, notes, and snippets.

View yanil3500's full-sized avatar

Elyanil Liranzo-Castro yanil3500

View GitHub Profile
@yanil3500
yanil3500 / reverseAnInteger.java
Last active December 1, 2017 18:34
Reverse an Integer
class ReverseInteger {
public static int reverseInteger(int num){
long reversedNum = 0L;
while(num != 0){
//Calculate the remainder
reversedNum = (num % 10) + (reversedNum * 10);
//Recalculate num to remove digit from tens place
num = num / 10;
if (doesOverflow(reversedNum) || doesUnderflow(reversedNum)) {
@yanil3500
yanil3500 / SerializingObjects.java
Last active November 29, 2018 16:58
Serializing objects in Java
import java.io.*;
import java.util.ArrayList;
import java.util.stream.Stream;
class Car implements Serializable {
private String make;
private String model;
public Car(String make, String model) {
this.make = make;
@yanil3500
yanil3500 / MemoizedFibonacci.swift
Created January 24, 2019 19:36
Memoized Fibonacci
func fibonacci(n: Int) -> Int {
var numbers = [Int:Int]()
return fibHelper(n: n, nums: &numbers)
}
func fibHelper(n: Int, nums: inout [Int:Int]) -> Int {
if let result = nums[n] {
return result;
} else if n == 1 {
@yanil3500
yanil3500 / Main.java
Last active February 27, 2019 17:37
Checkboxes
package com.company;
import java.util.Scanner;
//Uncomment the class definition.
/**
class Checkbox {
private boolean isChecked = false;
@yanil3500
yanil3500 / Heap.java
Created March 7, 2019 02:36
Max Heap Java Implementation
public class Heap {
private static int ROOT = 1;
private static int DEFAULT_SIZE = 3;
Integer[] elements;
int numberOfElements;
public Heap() {
this.numberOfElements = 0;
@yanil3500
yanil3500 / proper_parenthetics.py
Created March 9, 2019 19:41
Proper Parenthetics
def is_valid(string):
if (len(string)) % 2 != 0:
return False
braces = {'[':']', '{': '}', '(': ')'}
opening_braces = braces.keys()
stack = []
for char in string:
if char in opening_braces:
stack.append(char)
@yanil3500
yanil3500 / java_project.py
Last active May 6, 2019 03:53
Java Project Generator
import os, sys
JAVA_TEMPLATE = """
public class Main {
public static void main(String[] args) {
System.out.println("Hello world!");
}
}
"""
@yanil3500
yanil3500 / BinarySearchTree.java
Last active November 26, 2019 18:20
Binary Search Tree Java Implementation
import java.util.ArrayList;
import java.util.stream.Collectors;
class Node<K extends Comparable<K>, V> {
K key;
V value;
Node<K, V> parent;
Node<K, V> left;
Node<K, V> right;
@yanil3500
yanil3500 / ___FILEBASENAME___.swift
Last active June 6, 2019 02:57
Swift Helper Logger Class
//___FILEHEADER___
import Foundation
// To use this as a template, do the following:
// 1. Create the 'Custom' directory -> mkdir -p ~/Library/Developer/Xcode/Templates/File\ Templates/Custom
// 2. Open Finder, CMD + G into this directory /Applications/Xcode.app/Contents/Developer/Library/Xcode/Templates/File Templates
// 3. Open 'Source' directory and copy the Swift File.xctemplate
// 4. Paste the Swift File.xctemplate into to the 'Custom' directory from step 1
// 5. Rename the Swift File.xctemplate in the 'Custom' directory to the desired name for the template
@yanil3500
yanil3500 / Alert.swift
Created June 24, 2019 21:04
Show Basic Alert Controller
//
// Alert.swift
// DoTryCatch
//
// Created by Sean Allen on 8/30/17. (Big ups to Sean Allen)
// Copyright © 2017 Sean Allen. All rights reserved.
//
import Foundation
import UIKit