Skip to content

Instantly share code, notes, and snippets.

View Bennyelg's full-sized avatar

Benny Elgazar Bennyelg

View GitHub Profile
import sequtils
import nimpy
import tables
import intsets
proc remove_duplications_nim(n: seq[int]): seq[int] {.exportpy.} =
var t1 = initTable[int, int]()
for t in n:
discard t1.hasKeyOrPut(t, 1)
@Bennyelg
Bennyelg / dedup.py
Last active February 12, 2019 21:38
dedup python and nim test
import random
import dedupnim # (dedupnim) https://gist.github.com/Bennyelg/d472cc66d3150d0bb549c14c9a17c253
def remove_duplicates(n):
return list({e for e in n})
def remove_duplicates2(n):
return {e: 1 for e in n}.keys()
if __name__ == '__main__':
@Bennyelg
Bennyelg / 20171104_2.md
Created February 7, 2019 07:49 — forked from shotahorii/20171104_2.md
(un)pivot on Presto

Pivot

Query
SELECT
  uid,
  kv['c1'] AS c1,
  kv['c2'] AS c2,
  kv['c3'] AS c3
FROM (
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):
@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):
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]
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}")
import random
import times
import sequtils
import strutils
import strformat
type
Singleton = object
value*: int
type
User = ref object
name: string
paymentStrategy: proc ()
proc strategyA() =
echo("strategyA")
proc strategyB() =
echo("strategyB")
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] == "+":