Skip to content

Instantly share code, notes, and snippets.

View nicola88's full-sized avatar

Nicola nicola88

View GitHub Profile
@nicola88
nicola88 / ch05.sc
Created July 11, 2019 08:45
Programming in Scala #book
class Rational(n: Int, d: Int) {
require(d != 0)
private val g = gcd(n.abs, d.abs)
val numer = n / g
val denom = d / g
def this(n: Int) = this(n, 1)
@nicola88
nicola88 / replace.sc
Created April 3, 2019 14:41
String replacement
def concat(heads: List[Char], tails: List[String]): List[String] = {
for {
h <- heads
t <- tails
} yield h.toString + t
}
def replace(str: String, replacement_rules: Map[Char, List[Char]], max_replacements: Int): List[String] = {
def replaceStep(str: String, replacements_count: Int): List[String] = {
if (replacements_count == 0) List(str)
@nicola88
nicola88 / nat.sc
Last active March 21, 2019 16:29
w5
abstract class Nat {
def isZero: Boolean
def predecessor: Nat
def successor: Nat
def +(that: Nat): Nat
def -(that: Nat): Nat
}
object Zero extends Nat {
def isZero: Boolean = true
@nicola88
nicola88 / funsets.sc
Last active March 20, 2019 22:02
w3-intset
package funsets
/**
* 2. Purely Functional Sets.
*/
object FunSets {
/**
* We represent a set by its characteristic function, i.e.
* its `contains` predicate.
@nicola88
nicola88 / w1-counting-change.py
Created March 19, 2019 14:27
Functional programming principles with Scala
from typing import List
def count_change(money: int, coins: List[int]):
if money == 0:
return 1
# Amount > 0
if len(coins) == 0:
return 0
# Amount > 0, 1+ coins
coin = coins[0]
@nicola88
nicola88 / medium-nextcloud-s3-policy.json
Last active July 26, 2022 01:37
S3 bucket policy for Nextcloud
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:GetBucketLocation",
"s3:ListAllMyBuckets"
],
"Resource": "arn:aws:s3:::*"
@nicola88
nicola88 / medium-nextcloud-install.sh
Last active July 4, 2023 06:30
Nextcloud on AWS
# Install Nextcloud stack
sudo snap install nextcloud
# Create administrator account
sudo nextcloud.manual-install <admin_username> <admin_password>
# Configure trusted domains (only localhost by default)
sudo nextcloud.occ config:system:get trusted_domains
sudo nextcloud.occ config:system:set trusted_domains 1 --value=<dns-domain>
# Set 512M as PHP memory limit
sudo snap get nextcloud php.memory-limit # Should be 512M
sudo snap set nextcloud php.memory-limit=512M