Tag: python

  • @dicewarebot, the solution I needed that no one asked for

    @dicewarebot, the solution I needed that no one asked for

    A number of years ago I was trying to learn python. Random numbers have always amused me (as I was recently reminded by a twitter nod to the weird usage of spreadsheets).

    A user named @context_ing tweeted: “I love finding the ways in which people use spreadsheets. Personally, I use them for mostly budgeting, workout tracking and travel planning. Here’s a few in the wild I’ve found. Would love to see more! Please share if you’ve come across any or have any yourself.”

    I felt compelled to reply with my own little story. “Reminds me of a decade old excel project. A playwriting book said something like “I guess it would be a play if you cut up words from a dictionary and pulled them out one-by-one, arranging them into lines of 10 words under character names, but it wouldn’t be a very good one.” So I took the entire public domain text of Oscar Wilde’s classic and had Excel recreate the play on every reopen of the file by randomly selecting words and character names I think using a vlookup and random. The result was interesting (and likely bad theatre).”

    The text in question (blasted tweet limits!) was Oscar Wilde’s The Importance of Being Earnest. The resulting play was garbage, but that random interger generation was magical. When combined with other functions it really could do wonderful things for art.

    Fast forward some (10?) years and I had a different problem to deal with: I needed to seamlessly transition all staff and clients from one grouping of technology services at one company to a different group of technology services at a new and different non-profit that was going to just continue doing basically the same work for basically the same people.

    To remove almost all complexity from this story: I needed passwords; lots of random, unique, and strong passwords.

    I once again turned to my friend the random number generator, but this time in python rather than excel. I coded up a script that would allow me to specify the number of words I wanted, unique separator I desired, and―importantly―how many of these unique passwords I wanted to be generated in one go.

    I had the program roll digital dice and lookup words from the EFF’s Diceware password list and then spit them out. People would get their passwords and privately think I was just very adept at coming up with wacky sounding passwords, but I did not deserve this misconception as random integers were to blame for everything.

    Eventually I thought it would be a good idea to create a sort of Public Service Announcement on the web about the odd truth that a list of words obtained by rolling dice really can be unique.

    The end result is a Twitter bot and a Mastodon bot that very frequently tweet out unique passwords they’ve generated (though you probably shouldn’t use them). More people follow on Mastodon than Twitter, and Twitter relatively frequently blocks my bot’s tweets makes me unnecessarily prove that there’s a human behind the bot to get things going again (anyone at Twitter can explain this?).

    At any rate, here’s some examples embedded below. Note that I also added the Harry Potter wordlist as well. There are others for your enjoyment on EFF’s site.

    Lastly, there are infinitely better versions of this if you’re looking to generate a password. I’d recommend the much more easily installed passphraseme by Micah Lee.

    At any rate, I hope you enjoyed my PSA.

  • hello!!! … World?

    This is the original playscript I wrote for The Art of Python that took place at PyCon U.S. in 2019. I additionally performed the piece at PyCon with the directorial help of Sumana Harihareswara and the stage management work and acting performance as the Figure by Mel Chua.

    There were some changes to this script for the live performance. I created slides for the event and they were displayed behind me during the performance and are presented throughout the script below as images.

    The Void

    (slide reads: “THE VOID”)

    (the stage is empty. We can make out one person, a figure, front and center.)

    Kyle

    (staring, wide-eyed, excited, past the audience – beat * 3)

    Hello!!!

    (slide reads: “This is Kyle –”)

    (beat * 3)

    Hello?

    (slide reads: “he’s learning the new skill of –”)

    Hello?!

    (Terrified / heavy breathing / beat * 1)

    (slide reads: “computer programming –”)

    Hello, World?

    (Covers his eyes with one hand, twists away from the audience as if what he is about to do might blind him, and clicks a single finger down on an imaginary ENTER key. Bright lights up full. Beat * 3 – he peaks through his fingers.)

    It worked? It worked! Ha ha! Yes! Look at that. There it is: “Hello, World!” (Hand on hips – power pose) And you thought this programming thing would be hard.

    (slide reads: “but Kyle was in for – “)

    (Red lights, loud, blaring sirens)

    (Kyle freezes in a macabre, horrific expression and body position)

    (slide reads: “– a rude awakening.”)

    Not a Programmer

    (slide reads: “on not being a programmer”)

    Kyle

    No, I’m not a programmer, I’m just better than you are at excel spreadsheets.

    (click sound. beat.)

    No, I’m not a programmer, I just figured out how to use this query-like syntax with your data in Google’s spreadsheets.

    (click sound. beat.)

    No, I’m not a programmer. It’s just a little bash script I wrote that helps me journal better from my phone, laptop, and desktop.

    (click sound. beat.)

    Ha! I wouldn’t say I’m a programmer, I just needed to batch download a really big list of files from a service we were using and python seemed easiest after a google search.

    (beat.)

    I’m sorry, what?

    (beat.)

    No, yeah―it did work―ran for about 80 hours straight before finishing. Lots of files.

    (click sound. beat.)

    Okay―fine―I’m doing some programming: but I’m not really a programmer…

    Picking a Language

    (slide reads: “on picking a programming language”)

    Kyle

    Hi. My name is Kyle and I’ve decided to become a programmer. Several blog posts, books, and twitter surveys have lead me to believe that it is of the utmost importance that I:

    (the next sequence is rapid-fire)

    (between each beat are quick head, body, and vocal tone adjustments)

    (very short beat. matter-of-fact:)

    Learn Visual Basic, because my high school teacher gave me a book one time and I can probably find that in my basement if I look hard enough.

    (very short beat. sarcastic:)

    Learn Bash, because it’s already installed on the self-inflicted torture device known as my Linux Desktop.

    (very short beat. in jest:)

    Learn emacs lisp, because you’ve already invested the time into memorizing emacs keybindings and you’ve heard it could use a good text editor.

    (very short beat. whatever:)

    Learn Go because people talk about it on twitter a lot and it was created by Google.

    (very short beat. haughty:)

    Learn COBOL because it’ll always need maintaining, and it pays the best in my geographic location.

    (very short beat. overheard/whisper:)

    Learn Python because it’s the “second best language at everything.”

    (very short beat. honest:)

    Learn Javascript because it pairs well with my graphic design background for web development.

    (very short beat. snooty:)

    Learn R, because it’s the best language at data analysis and graphical representation.

    (very short beat. authoritative:)

    Learn HTML and CSS because you can make things on the internet―oh, wait―nevermind―there’s disagreement as to whether or not these are programming languages?

    (beat. drop all pretense. speak directly to audience―with pure, sincere, exasperation:)

    Am I really learning programming if I just know something like “hello, world!” in 10 programming languages!?

    (beat.)

    … and HTML and CSS?

    stack overflow

    (slide reads: “submitting a question to stack overflow”)

    Kyle

    (Kyle appears frustrated, staring straight ahead and typing in furious bursts.)

    Python. Sort. Array. Count. Items. … Search.

    (beat. scrolling:)

    No. No. No way! What? No.

    (beat. scrolling:)

    And… no.

    (loud sigh. lowered head. stretch neck. he tries again:)

    Python. Array. Group-by-count.

    (beat.)

    No… no…

    (beat. tilts head:)

    Sort of?

    (clicks. beat.)

    Oh. No. No, no, no. Not that, kind of…

    (beat. types again)

    SQL group by with python?

    (beat. smiles/excited:)

    Hey! That’s kind of it…

    (face drops.)

    Oh! Rude! That’s not a helpful or kind response. Do I even want to submit the question here?―mean!―I already don’t know what to ask or how to ask it and apparently that’s a reason to say that you shouldn’t even ask the question.

    (beat.)

    Maybe I’ll just figure it out myself…>

    (a transition. Kyle is holding a rubber duck.)

    I’ve heard talking to you helps…

    (slide reads: “Kyle works.”)

    (duck is gone. cracking knuckles and stretching:)

    Done―well, an example anyway, explaining exactly what I want to do and suffers the same problem as my actual work. But I still don’t know how to solve it.

    (beat.)

    Submit to stack overflow? Submit?

    (resolve. clicks enter confidently:)

    SUB. MIT.

    (transition. later:)

    An answer!―that does basically what I need―and they think I asked a good question―and I got fake internet points!

    (beat.)

    Okay then. Maybe I can do this.

    (smile.)

    Meetup

    (slide reads: “on going to a meetup”)

    Kyle

    (hands in pockets. kicking dirt. retelling:)

    So, I was sick of trying to learn things on my own―by myself, in my basement―and I found a meetup online. It was at a chain soup and sandwich place on a Saturday.

    (beat.)

    I clicked “attending” and went.

    (miming what’s described.)

    I got my laptop charged up, threw it in my laptop bag along with a notebook, a pen, and my charger, and slung it over my shoulder and headed in.

    (beat.)

    I guess I didn’t know what I was expecting? When I walked in and scanned the room looking for more than like four college students with their laptops open over coffee. There they were―I think. Play it cool!

    (beat. walking:)

    I headed to the counter and ordered a coffee―maybe I’d get thirsty―and walked up: “Is this the python group?”

    (uncomfortable smile, holding breath and upright―more uncomfortable long beat…)

    It was. That’s what it felt like―forever. They were nice. Young. Old. Macs, Linuxes, and Windows. Qwerty, Colemak, and Dvorak. Gnome and i3. Emacs and Vim and VSCode and Sublime. Working in finance, consulting, healthcare, insurance, startups, and going to college.

    (beat.)

    They were just people.

    (beat.)

    I didn’t learn much about programming that day―I did learn that there are real people in real life who care about some of the things I do.

    (beat.)

    I needed to reach out to more of them.

    (break fourth wall. wink.)

    Sending an email to a stranger in tech.

    (slide reads: “on sending an email to a stranger in tech”)

    Kyle

    (straight to audience. single light.)

    (like an awkward introduction at a job interview. exasperated:)

    Hi. I’m Kyle. I’m new here. I want to get better at this technology thing. Can you help me? You seem like you could help me.

    (beat.)

    ’cause I need a lot of help.

    (ding sound. beat. overly formal:)

    Hello. My name is Kyle R. Conway. I have a PhD … in Fine Arts … and you do art … and so do I … but you also do tech things … tech things with art. I would like to do what you do. May I join you?

    (extends hand for handshake. beat. wide eyes. beat. more intense.)

    (ding sound. beat. casual:)

    Hey, tech blogger. I really liked your post about unpackaged fonts with permissive licenses. I think that’s really cool.

    (ding sound. beat. rapid-fire round. cheeky:)

    Howdy!

    (ding sound. beat. Irish:)

    Dia duit!

    (ding sound. beat. concerned:)

    I promise I’m not a creepy stranger.

    (ding sound. beat. intense:)

    I. Am. Your. Biggest. Fan.

    (gong sound. rubbing eyes. honest:)

    This is never going to work.

    (quick fade. slide reads: “Kyle’s actual first email to a stranger in tech.”)

    Thu, Mar 17, 2011 at 11:36 PM>
    Máirín,
    Would the “Nina” font meet the criteria for inclusion?
    http://www.archive.org/details/NinaPaleyFonts
    Thanks,
    KYLE

    (slide reads: “Thanks for writing back, Máirín”)

    The Figure and the Void.

    Figure

    (A figure stands alone in the darkness.)

    (The figure shouts with naive confidence into the void a single word:)

    “Hello!!!”

    (and… waits…)

    (The figure finishes the phrase―now a question:)

    “World?”

    (figure stands awkwardly, concerned, awaitang a response with growing insecurity.)

    (slide reads, slowly, word-by-word: “what. can. you. do. to. make. this. journey. easier. for. others?)

    (slide reads: “end”. )

    (ding sound.)

  • One True Thing

    One True Thing


    TL;DR

    I’m asking you to submit a single sentence that tells your own One True Thing about working in tech for a unique performance at this year’s PyCon conference. Please click here to submit (takes less than a minute!).

    Or, if you’re up for something more involved, to submit a longer proposal for the larger event.

    Last Year

    At last year’s PyCon I was one of several writers and performers at a Hatchery event called The Art of Python, which sought to encourage and showcase novel performance art that aimed to help technologists share their emotionally charged experiences of programming. I wrote and performed an original show titled Hello!!! … World? which outlined my own trials and tribulations in a series of vignettes on trying to get into programming without being around or knowing anyone personally who was a part of those communities. As a small taste, one vignette was titled on submitting a question to stack overflow.

    This Year

    This year I’m part of the team that’s organizing the event again. We are aiming to create a dramatic narrative around programming and programming culture that shapes so much of all of our daily lives (from our smart phone interactions to surfing the web to banking and even reading this post). We are interested in how fictional narrative, visual and performance art, and different presentation formats can lead to a new sort of self-consciousness and reflection on culture. All society is permeated by technology, whether or not someone is a programmer, and most people have had positive, neutral, and adverse interactions with technology (whether building, consuming, or indirectly being impacted). In short, technology is not a black or white issue, but instead a collection of frustratingly similar shades of gray.

    The Zeitgeist is teeming with moral and ethical issues both in and brought about by computer technology―be it developers challenging companies’ practices that conflict with personal values, software licenses trying to append morality clauses, the increasing omnipresence of technology that enables controversial surveillance, or the seemingly endless push toward dark patterns in design.

    Technologists face many ethical and moral decisions in computer science and software development. What was the situation? What was the ethical and/or moral discord? What decision was made? How did you come to that decision? What was the outcome for all stakeholders? How do you feel about it now? What might you do differently in the future? Why?

    These questions take time to answer and are difficult to dramatize successfully to honor their truth.

    An Old Technology

    Storytelling is an old technology―a powerful medium―through which we gain empathetic understanding.

    All culture is now technological culture to some extent. We believe it is important to integrate the stories of those making this technology to broaden their lexicon and ours. We must highlight their ethical struggles to bring greater transparency and self-consciousness to both technology industry professionals and the public at large. Hopefully this also inspires empathy for all people, and urgency for any obvious changes that result from our workshops and the resulting art.

    From Audience to Creator

    While our event this year will have unique and pre-rehearsed performances as we did last year, we will also have a workshop following the scheduled performances. During our workshop we will discuss collaboratively how a variety of issues have cropped up in the lives of the programmers participating, as well as the end-users who experienced the technologies. Everyone will have a chance to work with the other directors and playwrights in order to take these insights and begin to turn these stories into dramatic narratives highlighting the personal struggles of these developers that are building the technology that ends up on the front pages of our papers and the billions of tiny-screened pocket computers.

    One True Thing

    As a part of the planned performances we want to transition into our workshop with a series of real issues crowdsourced from the broader tech community. To that end, we’re asking you to share One True Thing with us so that we can share your truth at PyCon this year (and elsewhere) in a collaborative performance that we hope will inspire more art from technologists.

    One True Thing is a performance comprised of single-sentence statements of truth crowd-sourced and eventually read out loud by members of a live audience as statements of someone else’s truth to be publicly shared and communally experienced.

    Examples

    Note: At the moment I’ve sourced these from technologists on Twitter. Obviously every group would provide their own unique takes, so these should serve only as an example.

    Here are some example statements:

    • “Racism struggle does not belong to one race.” – @LambyTech
    • “Mentors are incredibly important for succeeding in tech” – @js_tut
    • “I always joke that someday I will quit the tech industry so I can code all day” – @sarah_edo
    • “Moral and political issues of tech aren’t moral and political issues because they are tech.” – @dingstweets
    • “A women in tech recently asked me if I had any advice & all I could think of was: have the patience to prove people wrong the rest of your career.” – @jessfraz
    • “When you ask a Deaf person if they can read lips, you are asking if you can put the burden of communication solely on them.” – @csano
    • “you tech people need to hang out with artists and creative folks more, seriously.” – @noopkat
    • “algorithms reflect the biases of the people who make them.” – @evacide
    • “So many of the concerns raised about tech today seem to conflate societal issues with the technology that makes those societal issues more visible.” – @mmasnick

    Share your One True Thing

    Please click here to submit your One True Thing (it takes less than a minute!).

    Thanks for reading and for sharing your truth.

  • Download Issue of MagPi with python from Raspberry Pi 3 Model B+

    # MagPi Issue Downloader
    
    ## Import 
    import urllib.request
    import shutil
    import requests
    import os
    from bs4 import BeautifulSoup
    
    # Identify URL to parse
    url = 'https://www.raspberrypi.org/magpi-issues/'
    
    # soup it
    Link = requests.get(url)
    soup = BeautifulSoup(Link.content,"html5lib")
    
    # get all link tags
    tags = soup('a')
    
    # loop tags
    for hlink in tags:
    	
    	# create variable for full url
    	issue = hlink.get('href', None)
    	
    	# only follow hlinks with PDF in the url
    	if 'pdf' in issue:
    		
    		# download files with wget to current directory
    		print("Downloading: " + issue)
    		issue_link = url + issue
    		os.system('wget %s'%issue_link)
  • Rolling Dice in Python

    The below rolls dice in python.  I’ve long loved python for dice-rolling―having created a now defunct twitterbot and a mastodon bot―it was nice to write this up briefly as I’m working on re-re-re-learning python.

    #!/usr/bin/python3 
    from random import randint 
     
    total_dice = int(input('How many dice? ')) 
    dice_val = int(input("How many sides? ")) 
     
    rolls = [] 
    high_roll = 0 
    low_roll = 0 
     
    for i in range(total_dice): 
     roll = randint(1, dice_val) 
     rolls.append(roll) 
     
    nums = len(rolls) 
     
    print("") 
    print("Roll #\tRoll") 
    print("------------------") 
     
    for i in range(nums): 
     print("#" + str(i+1) + ":\t" + str(rolls[i])) 
     
     
    print("------------------") 
    print("Highest: " + str(max(rolls))) 
    print("Lowest: " + str(min(rolls))) 
    print("------------------") 
    print("TOTAL: " + str(sum(rolls)))

    Output looks like the below:

    How many dice? 20 
    How many sides? 20
    
    Roll # Roll 
    ------------------ 
    #1: 8 
    #2: 6 
    #3: 18 
    #4: 7 
    #5: 14 
    #6: 7 
    #7: 6 
    #8: 12 
    #9: 2 
    #10: 10 
    #11: 2 
    #12: 13 
    #13: 3 
    #14: 10 
    #15: 20 
    #16: 5 
    #17: 6 
    #18: 19 
    #19: 1 
    #20: 15 
    ------------------ 
    Highest: 20 
    Lowest: 1 
    ------------------ 
    TOTAL: 184
    
    

    Wonderful fun.