Skip to content

Instantly share code, notes, and snippets.

View MarounMaroun's full-sized avatar
🎹
♫♩♬

Maroun Maroun MarounMaroun

🎹
♫♩♬
View GitHub Profile
@MarounMaroun
MarounMaroun / ByNameValue.scala
Created December 28, 2017 08:50
Call by name VS call by value in Scala
// defining a simple function that returns the current time
def getTime = System.currentTimeMillis
// defining a function, by NAME, that prints two times: now and one second later
def getTimeByName(f: => Long) = { println(f); Thread.sleep(1000); println(f)}
// defining it again, but this time, by VALUE
def getTimeByValue(f: Long) = { println(f); Thread.sleep(1000); println(f)}
getTimeByName(getTime)
@MarounMaroun
MarounMaroun / instance_types_extractor.py
Last active December 18, 2017 21:45
AWS instance types extractor
from lxml import etree
import urllib
web = urllib.urlopen("https://aws.amazon.com/ec2/instance-types")
s = web.read()
html = etree.HTML(s)
tr_nodes = html.xpath('//*[@id="aws-page-content"]/div/div/main/section/div[2]/div[43]/div/table/tbody/tr')
@MarounMaroun
MarounMaroun / get_repose.sh
Created November 25, 2017 09:15
Clone all of your public repositories
repos=$(curl -s https://api.github.com/users/{USER}/repos?per_page=1000 | grep -oP "(?<=clone_url\": \").*(?=\")")
echo "$repos" | while read line ; do
git clone $line
done
@MarounMaroun
MarounMaroun / strict_vs_lazy.scala
Created November 22, 2017 11:41
Strict VS Lazy evaluation in Scala
/**
* Assume we are interested in finding the first two even numbers in a very big file.
* Since we love functional programming, we don't want to use the traditional for loops.
* Instead, we want to apply a series of function to get the desired output.
*/
// for the sake of the example, I assume the input is found in a list, not a file
var l = List(1, 47, 38, 53, 51, 67, 39, 46, 93, 54, 45, 33, 87, 96, 100, 4, 84, 17, 31, 81, 88, 35, 36)
// we don't really need toList here, but since we're assuming the data is coming from a file, I'll use it anyway
@MarounMaroun
MarounMaroun / SingletonExample.scala
Created November 21, 2017 05:41
Scala singleton example using object
object Singleton {
private var i = 0
def create(): Int = {
i += 1
i
}
}
Singleton.create() // 1
@MarounMaroun
MarounMaroun / ExampleClass.scala
Created November 20, 2017 11:41
Difference between "case class" and "class" in Scala
/**
* Case classes define a factory method for creating instances:
* - lines 24-25 don't have the "new" keyword.
*
* Case classes generate implementations of toString, hashCode and quals:
* - see output in lines 24-27
*
* Much more differences, like immutability and generation of companion object.
*
* Note that in order to run the snippet below, use "scala" directly, don't attempt to compile with "scalac".
@MarounMaroun
MarounMaroun / install_java.sh
Last active November 19, 2017 05:41
Java 8/9 installation in Ubuntu
# add PPA
sudo add-apt-repository ppa:webupd8team/java
# install the installer script
sudo apt update; sudo apt install oracle-java8-installer
# optional - set env vars
sudo apt install oracle-java8-set-default
@MarounMaroun
MarounMaroun / SO.md
Last active October 19, 2017 13:25
Why Stack Overflow is part of my daily routine

"It is literally true that you can succeed best and quickest by helping others to succeed" - Napoleon Hill

If you've ever been interested in programming or anything related to, and been around the net long enough, you've came across Stack Overflow, accidentally or on purpose.

What is Stack Overflow?

Stack Overflow is a question and answer site for professional and enthusiast programmers. It's built and run by you as part of the Stack Exchange network of Q&A sites. With your help, we're working together to build a library of detailed answers to every question about programming

It was almost four years ago when I asked my first question in Stack Overflow (as a guest), got down-voted and my question was closed. Back then, I didn't know why was that; all what I asked for was a solution for my homework, and by saying "solution" I mean a full solution. I didn't expect comments like:

@MarounMaroun
MarounMaroun / install.sh
Last active September 12, 2021 10:58
Terminator installation
# Ubuntu
sudo add-apt-repository ppa:gnome-terminator
sudo apt-get update
sudo apt-get install terminator
# Fedora
yum install terminator
@MarounMaroun
MarounMaroun / config
Created September 11, 2017 13:47
Terminator custom configurations
[global_config]
enabled_plugins = LaunchpadCodeURLHandler, APTURLHandler, LaunchpadBugURLHandler
[keybindings]
broadcast_all = <Primary>g
broadcast_group = <Primary><Shift>underscore
broadcast_off = <Primary><Shift>g
close_window = <Primary><Shift>q
move_tab_left = <Shift><Alt>Page_Down
move_tab_right = <Shift><Alt>Page_Up
next_tab = <Alt>2