Skip to content

Instantly share code, notes, and snippets.

View Bennyelg's full-sized avatar

Benny Elgazar Bennyelg

View GitHub Profile
import "../src/parse_args.nim"
import sequtils, strutils, os
import tables
var res: Table[string, string]
res = parseArguments(commandLineParams)
echo res
import strutils
import sequtils
import os
import tables
proc parseArguments*(inputString: seq[string]): Table[string, string] =
var arguments = newSeq[string]()
if inputString.len == 0:
discard
else:
@Bennyelg
Bennyelg / merge_sort.nim
Created May 29, 2017 07:39
merge_sort implementation.
import strutils
import math
#[
Module name: Implementation of MergeSort recursion.
Author: Benny E.
Mail: elgazarbenny at gmail.com
]#
from decimal import Decimal
def apply_high_order(ind, element, expression_elements):
if element in ("*", "/"):
if element == "*":
evaluated_num = str(float(expression_elements[ind - 1]) * float(expression_elements[ind + 1]))
else:
evaluated_num = str(float(expression_elements[ind - 1]) / float(expression_elements[ind + 1]))
expression_elements = expression_elements[:ind - 1] + [evaluated_num] + expression_elements[ind + 2:]
elif element == "(":
if expression_elements[ind + 2] == "+":
type
User = ref object
name: string
paymentStrategy: proc ()
proc strategyA() =
echo("strategyA")
proc strategyB() =
echo("strategyB")
import random
import times
import sequtils
import strutils
import strformat
type
Singleton = object
value*: int
import singleton
import times
import strformat
for _ in countup(1, 3):
var start = now()
echo("Starting test..")
echo(singletonInstance.value)
echo(fmt"took: {(now() - start).milliseconds}")
proc merge[T](a: var seq[T], b: var seq[T]): seq[T] =
result = newSeqOfCap[T](a.len + b.len)
while a.len != 0 and b.len != 0:
if a[0] < b[0]:
result.add(a[0])
a = a[1..^1]
else:
result.add(b[0])
b = b[1..^1]
@Bennyelg
Bennyelg / plpythonu.sql
Created February 2, 2019 20:28 — forked from rturowicz/plpythonu.sql
postgresql: example use of python procedural language
-- query with stored plan
CREATE or replace FUNCTION pybench1(id int) RETURNS text AS '
if (SD.has_key("plan")):
plan = SD["plan"]
else:
plan = plpy.prepare("SELECT * FROM pagetimer pt, pagebrowser pb WHERE pt.idtimer = $1 and pt.idtimer = pb.idtimer", ["int4"])
SD["plan"] = plan
rec = plpy.execute(plan, [id])
if (rec.nrows() > 0):
def get_lucky_version(real_floor: int):
floors: List[int] = []
n = 1
def its_a_bad_luck_floor(floor_no: int):
return "4" in str(floor_no) or "13" in str(floor_no)
for i in range(1, real_floor + 1):
if its_a_bad_luck_floor(n):