Skip to content

Instantly share code, notes, and snippets.

Nil-Zil

Block or report user

Report or block Nil-Zil

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View set.hs
head1 :: [a] -> a
head1 [] = error "empty List"
head1 (x:xs) = x
head2 :: [a] -> Maybe a
head2 [] = Nothing
head2 (x:xs) = Just x
filter' :: (a -> Bool) -> [a] -> [a]
filter' _ [] = []
@Nil-Zil
Nil-Zil / factorial.hs
Created Jan 20, 2018
Iterating and recursing implementation of factorial.
View factorial.hs
factRecur :: Int -> Int
factRecur 0 = 1
factRecur n = n * factRecur (n - 1)
factIter :: Int -> Int -> Int
factIter 0 m = m
factIter n m = factIter (n - 1) n * m
@Nil-Zil
Nil-Zil / add4ways.hs
Last active Jan 20, 2018
4 ways to implement `add` in Haskell.
View add4ways.hs
add :: (Int, Int) -> Int -- function with 2 parameters
add (x, y) = x + y
add2 :: Int -> (Int -> Int) -- Curry
add2 x y = x + y
-- return partially applied functions
addone = add2 1
addlambda :: Int -> Int -> Int
addlambda = \x y -> x + y
View factorial.py
#!/usr/bin/env python3
# created at Jun 3, 2017 01:19 by Nil-Zil
class Factorial(object):
def factorial_recur(self, n):
if n is 1:
return 1
else:
View leap_frog.py
#!/usr/bin/env python
# created at Jan 18, 2017 22:06 by Nil-Zil
"""
Leap frog algorithm.
"""
import matplotlib.pyplot as plt
import numpy as np
time = 10
View sort_lists.py
#!/usr/bin/env python3
# created at Jun 23, 2017 21:04 by Nil-Zil
"""
Sort list d, e, f by the elements in a, b, c.
"""
from operator import itemgetter
import numpy as np
View tree.py
from typing import *
class Tree(dict):
"""
A tree implementation using python's autovivification feature.
"""
def __init__(self, data: Optional[Any] = {}):
"""
View sort_listD_by_list_A.py
#!/usr/bin/env python3
# created at Jun 23, 2017 21:04 by Nil-Zil
"""
Sort list d, e, f by the elements in a, b, c.
"""
from operator import itemgetter
import numpy as np
View curve_fit.py
import numpy as np
from scipy.optimize import curve_fit
import matplotlib.pyplot as plt
def func(x, a, b, c):
return a * np.exp(-b * x) + c
x_data = np.linspace(0, 10, 20)
y_data = [1.005530886735986, 0.36271009697000134, 0.10282751652440644, 0.03638464925638259, 0.0177328764419975, 0.007038622747455951, -0.011725650107022643, 0.017847156954980542, -0.0006555003543666825, 0.021014391787336193, -
View memfree.rb
#!/usr/bin/env ruby
# encoding: utf-8
if `uname`.strip == "Darwin"
def get_paged_memory_usage(match_string, paging=4096)
mvar = 3
if match_string.split(/[^\w]/).length > 1
mvar = 4
end
paged_val = `vm_stat | grep "Pages #{match_string}:" | awk '{ print $#{mvar}}'`.to_i
You can’t perform that action at this time.