Skip to content
Snippets Groups Projects
Commit 971af254 authored by tuhe's avatar tuhe
Browse files

Refactor dir snip

parent 9574dfb6
No related branches found
No related tags found
No related merge requests found
Showing
with 87 additions and 6 deletions
File added
File added
...@@ -20,10 +20,8 @@ if __name__ == "__main__": ...@@ -20,10 +20,8 @@ if __name__ == "__main__":
from snipper.fix_s import save_s from snipper.fix_s import save_s
from snipper.snipper_main import censor_file from snipper.snipper_main import censor_file
EX_BASE = "../examples"
# np = EX_BASE + "/latex"
# EX_BASE = "../examples"
# np = EX_BASE + "/new_project"
# if os.path.isdir(np): # if os.path.isdir(np):
# shutil.rmtree(np) # shutil.rmtree(np)
...@@ -40,7 +38,7 @@ if __name__ == "__main__": ...@@ -40,7 +38,7 @@ if __name__ == "__main__":
# my_nup(np + "/index.pdf") # my_nup(np + "/index.pdf")
# my_nup(f"{np_basic1}/index.pdf") # my_nup(f"{np_basic1}/index.pdf")
# #
# # convert.pdf2png(np + "/index.pdf", "./index0.png") convert.pdf2png(np + "/index.pdf", "./index.png", scale_to=600)
# output = np +"/index_2up.pdf" # output = np +"/index_2up.pdf"
# #
# data = {} # data = {}
......
from snipper.fix_s import get_s #!s
from snipper.block_parsing import block_split
import textwrap
import numpy as np
# Implement a sieve here.
def primes_sieve(limit):
limitn = limit+1 #!b
primes = range(2, limitn)
for i in primes:
factors = list(range(i, limitn, i))
for f in factors[1:]:
if f in primes:
primes.remove(f)
return primes #!b
#!s
def obscure(blk, fun):
blok = block_split(blk, "#!b")
lines2 = blok['first'] + fun(blok['block']) + blok['last']
s = '\n'.join(lines2)
print(s)
return s
# driver program
if __name__ == '__main__':
with open(__file__, 'r') as f:
s = f.read().splitlines()
blk = get_s(s)['']
def cmnt(lines):
whitespace = " " * (len(lines[0]) - len(lines[0].lstrip()))
lines = textwrap.dedent("\n".join(lines)).splitlines()
lines = ["# " + l for l in lines]
return lines, whitespace
def f1(lines):
lines, whitespace = cmnt(lines)
lines = [lines[i] for i in np.random.permutation(len(lines))]
lines = textwrap.indent("\n".join(lines), whitespace).splitlines()
return lines
obscure(blk, f1)
def f2(lines):
lines, whitespace = cmnt(lines)
kp = """#'"[](){},.+-012345679:="""
l2 = []
for line in lines:
line2 = []
for w in line.split(' '):
if w in ['', 'return', 'if', 'else' '=', '#', "for", "in"]:
line2.append(w)
else:
w2 = "".join( [ (t if t in kp else '?') for t in w] )
line2.append(w2)
l2.append(" ".join(line2))
lines = l2
lines = textwrap.indent("\n".join(lines), whitespace).splitlines()
return lines
obscure(blk, f2)
File moved
def myfun(): #!s
"""
Simple aux references \ref{eq1} in \ref{sec1}.
Simple bibtex citations: \cite{bertsekasII} and \cite[Somewhere around the middle]{herlau}
Example of custom command (reference notes)
> \nref{fig1}
Other example of custom command (reference assignment)
> \aref2{sec1}
"""
print("See \\ref{sec1}") # Also works.
return 42 #!s
def fun1(l1, l2):
s1 = sum(l1) #!s
s2 = sum(l2)
print("Hello worlds!") #!s
return s1 + s2
File moved
File moved
File moved
File moved
File moved
File moved
File moved
File moved
File moved
File moved
File moved
...@@ -3,7 +3,7 @@ import os ...@@ -3,7 +3,7 @@ import os
def reference_example(): def reference_example():
# Load references and insert them. # Load references and insert them.
from snipper.citations import get_bibtex, get_aux #!s=a from snipper.load_citations import get_bibtex, get_aux #!s=a
bibfile = "latex/library.bib" bibfile = "latex/library.bib"
auxfile = 'latex/index.aux' auxfile = 'latex/index.aux'
bibtex = get_bibtex(bibfile) bibtex = get_bibtex(bibfile)
......
File moved
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment