Skip to content

Instantly share code, notes, and snippets.

View yanil3500's full-sized avatar

Elyanil Liranzo-Castro yanil3500

View GitHub Profile
@yanil3500
yanil3500 / a_heap.py
Created December 24, 2019 15:02
[Heap Implementation] A general heap implementation that can be used as min-heap or max-heap. #data-structures #python
class Heap:
def __init__(self, array, is_min_heap=False):
self.comparison_func = MIN_HEAP_FUNC if is_min_heap else MAX_HEAP_FUNC
self.heap = self.build_heap(array)
self.length = len(self.heap)
def __len__(self):
return self.length
def build_heap(self, array):
@yanil3500
yanil3500 / decamelize.js
Created November 9, 2019 03:57
[Decamelize] Decamelizes a string with/without a custom separator (underscore by default) #javascript #camelcase #utility
/**
* Decamelizes a string with/without a custom separator (underscore by default).
*
* @param str String in camelcase
* @param separator Separator for the new decamelized string.
*/
function decamelize(str, separator){
separator = typeof separator === 'undefined' ? '_' : separator;
return str
@yanil3500
yanil3500 / stop.md
Last active October 24, 2019 22:00
[Stop Using Port] Bash script for terminating a process using a specific port #bash #tcp #ports

1. Go to /usr/local/bin/

2. Make file named stop and paste the below code in it.

3. Run chmod +x stop to make the script executable.

#!/bin/bash
touch temp.text
lsof -n -i4TCP:$1 | awk '{print $2}' > temp.text
pidToStop=`(sed '2q;d' temp.text)`
> temp.text
if [[ -n $pidToStop ]]
@yanil3500
yanil3500 / Helper.swift
Created October 5, 2019 00:47
[Bundle JSON Extension] Extension for loading JSON from a Bundle #json #bundle #swift #ios
//
// Helper.swift
// A small collection of quick helpers to avoid repeating the same old code.
//
// Created by Paul Hudson on 23/06/2019.
// Copyright © 2019 Hacking with Swift. All rights reserved.
//
import UIKit
@yanil3500
yanil3500 / BASH_GUIDE.md
Last active October 1, 2019 06:11
Bash Profile for Remote Host

Adding helpful shortcuts to your bash profile

After ssh-ing into our host, do the following:

  1. Ensure that you are currently in your home directory by running cd ~/.

  2. Run vi ~/.bash_profile. This command translates to "edit this text file in the vim text editor"

  3. Once you're in the text editor, press i to go into insert mode.

  4. Copy/paste the block of code below into your file:

    # reload bash
    
@yanil3500
yanil3500 / GettingInputAlertController.swift
Last active June 26, 2019 15:58
[Getting Input From User] Code for obtaining input from the user in an iOS application
import UIKit
// NEEDS to be used as an Xcode Snippet.
func getInputFromUser(){
let alert = UIAlertController(title: <#Domain-specific title: String>, message: "", preferredStyle: .alert)
@yanil3500
yanil3500 / SaveSwiftToDisk.swift
Last active June 26, 2019 06:17
[Saving Swift Custom Data Types To Disk] Code for saving objects to disk in Swift.
import Foundation
// NOTE: The objects you wish to save to disk must conform to the Codable protocol
class Todo: Codable {
let name: String
private(set) var done: Bool = false
init(name: String) {
self.name = name
@yanil3500
yanil3500 / Array+String+Character+Extensions.swift
Last active June 26, 2019 04:06
[Swift Convenience Extensions] A list of handy extensions on the String, Array, and Character types.
import Foundation
extension Array where Element: Numeric {
/// Returns a number that is sum of the elements in the sequence.
func sum() -> Element {
return self.reduce(0) { (res, next) -> Element in
res + next
}
}
}
@yanil3500
yanil3500 / String+Extension.swift
Last active June 26, 2019 04:05
[String To Integer]
import Foundation
precedencegroup ExponentiationPrecedence {
associativity: right
higherThan: MultiplicationPrecedence
}
infix operator **: ExponentiationPrecedence
func ** (lhs: Int, rhs: Int) -> Int {
@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