Skip to content

Instantly share code, notes, and snippets.

View billing.erl
-module(billing).
-export([print_bill/1]).
database() ->
[
{1111, "Hula Hoops", 21},
{1112, "Hula Hoops (Giant)", 133},
{1234, "Dry Sherry, 1lt", 540},
{4719, "Fish Fingers" , 121},
{5643, "Nappies" , 1010},
View input.txt
The heat bloomed in December .VB
as the carnival season .CV
kicked into gear. .LP
Nearly helpless with sun and glare, I avoided Rio's brilliant .RP
sidewalks
and glittering beaches,
panting in dark corners
and waiting out the inverted southern summer. .JU
View tail_recursion.erl
-module(tail_recursion).
-export([is_perfect/1]).
is_perfect(N) ->
2*N == lists:sum(divisors(N)).
divisors(N) ->
divisors(N, 1, []).
divisors(N, I, ACC) when I*I < N andalso N rem I == 0 ->
divisors(N, I+1, [I|[N div I|ACC]]);
@viniciusd
viniciusd / joining.erl
Created May 24, 2020
3rd section of the 2nd week of the Functional Programming in Erlang from the University of Kent
View joining.erl
-module(joining).
-export([join/2, concat/1]).
reverse([X|Xs]) -> reverse(Xs, [X]);
reverse([]) -> [].
reverse([X|Xs], ACC) -> reverse(Xs, [X | ACC]);
reverse([], ACC) -> ACC.
shunt([],Ys) ->
Ys;
View list_exercises.erl
-module(exercises).
-export([maximum/1,double/1,evens/1, median/1, modes/1]).
maximum([X|Xs]) -> maximum(Xs, X).
maximum([X|Xs], ACC) -> maximum(Xs, max(X, ACC));
maximum([], ACC) -> ACC.
double([X|Xs]) when is_number(X) -> double(Xs, [2*X]).
double([X|Xs], ACC) when is_number(X) -> double(Xs, [2*X|ACC]);
View download.rs
use hyper::{self,Client};
use hyper::rt::{self,Future,Stream};
use hyper_tls::HttpsConnector;
use std::fs::File;
use std::io::prelude::*;
use futures::future;
View tcpdump_context_manager.py
from datetime import datetime
import logging
import os
import subprocess
logger = logging.getLogger(__name__)
class TcpDump:
def __enter__(self):
now = int(datetime.now().timestamp())
View currying_and_clouses.java
import java.util.function.Function;
public class MyClass {
private static Function<Integer,Integer> outside(Integer y) {
return new Function<Integer, Integer>() {
@Override
public Integer apply(Integer x) {
return x + y;
}
View pivot.sql
CREATE OR REPLACE FUNCTION pivot(
refcursor, tablename character varying,
rowc character varying,
colc character varying,
cellc character varying,
celldatatype character varying)
RETURNS refcursor
LANGUAGE 'plpgsql'
COST 100
View concurrency.py
#!/usr/local/bin/python3
from multiprocessing import Process
from threading import Thread
import time
def f(n):
for i in range(n):
i
class Clock: