Jump to content

The under 100 line challenge!

fletch to 99
 Share

On 6/1/2021 at 7:00 AM, Dat Guy said:

You can't put a complete C++ program into one line, unless you don't need one single #.

Yes you can. Write it on many lines, run the C preprocessor, then minify.

Link to comment
Share on other sites

Link to post
Share on other sites

10 hours ago, BadBoyHaloCat said:

Yes you can. Write it on many lines, run the C preprocessor, then minify.

I mean, you're not wrong, but...

 

That's kind of not the point of "one-liners".

ENCRYPTION IS NOT A CRIME

Link to comment
Share on other sites

Link to post
Share on other sites

  • 1 month later...
On 6/15/2013 at 2:27 AM, fletch to 99 said:

The goal here is to make a useful program, that an end user is capable of using, that is under 100 lines! Ofcourse anything near 100 lines is awesome too, try to keep it fairly close though!

 

Please either link your source (if using an external site like pastie or github:gist) 

 

or

 

use code tags for example:


[code]Code here[ /code]

Here are some of my programs:

Biology Protein acronym converter: https://gist.github.com/fletchto99/5786050
Official LTT Story generator: https://gist.github.com/fletchto99/5786808

Screen Snapper: https://gist.github.com/fletchto99/5788659

The first link doesn't work

Link to comment
Share on other sites

Link to post
Share on other sites

  • 2 weeks later...

My attempt to make my own debugging tool lol
Might be useful to someone
Definitely NOT finished.
This was when I still used and was learning Python.
Clear-net link:
https://paste-bin.xyz/792

Onion service link:
http://strongerw2ise74v3duebgsvug4mehyhlpa7f6kfwnas7zofs3kov7yd.onion/pklxzwi9m
(link goes out in 1 year)

I cannot quote people with the built-in function because I almost never enable JavaScript on websites. You won't get notified if I reply to you, sadly :/

Link to comment
Share on other sites

Link to post
Share on other sites

  • 2 months later...
from gpiozero import LED
import requests
from bs4 import BeautifulSoup
import csv
import os
import time

greenled=LED(4)
redled=LED(26)

def scrape():

   result = requests.get("https://www.pro-football-reference.com/boxscores/")
   src = result.content

   soup = BeautifulSoup(src, 'html.parser')

   length = len(soup.find_all("table"))
   table=soup.find_all("table")


   os.system('clear')
   for i in range(0,length,1):

     league_table=table[i]

     teams=league_table.find_all("tr")


     for team in teams[1:3]:
       stats=team.find_all("td")
       team_name = stats[0].text
       points = stats[1].text

       if team_name=="Buffalo Bills":
          for team in teams[1:10]:
           stats=team.find_all("td")
           if stats[0].text=="Buffalo Bills":
               bills=stats[0].text
               bills_points=stats[1].text
           else:
               opponent=stats[0].text
               opponent_points=stats[1].text

   return bills_points,opponent_points,opponent

def lights():

   bills_points,opp_points,opp=scrape() #pass bills score and opponent score from scrape function

   localtime = time.asctime( time.localtime(time.time()) )
   os.system('clear')
   print("")
   print("Bills:", bills_points)
   print(opp,":", opp_points)
   print("")
    print("As of",localtime)

   #greenled=LED(4)  add back if lights not working correctly using the led as global
   #redled=LED(26)

   if bills_points>opp_points:
       greenled.on()
       redled.off()
   elif bills_points<opp_points:
       greenled.off()
       redled.on()
   else:
       greenled.on()  #score tied
       redled.on()

   time.sleep(30) #timeout for 30 seconds between updates


while True:
  lights()

This is a silly scraper program I wrote while I was learning Python. It is meant to work on a rpi zero w and pulls data from a very simple website using tabular data. It pulls the current score of my favorite NFL team. If the Bills are winning, it will illuminate a green led, if they're losing a red led and if the score is tied, both lights will be activated. It provides an easy visual to check the status. It should be pretty easy to manipulate the code to your favorite team and GPIO pins of your choosing. 😀

Link to comment
Share on other sites

Link to post
Share on other sites

new goal
make a code to predict if user will pass or fail using ai and the following fields

 

print("If answer is yes write 1, if no write 0. If yes or no is not applicable, write the answer based on question. ")
age=int(input("What's the students age::"))
Medu=int(input("Is the mother educated::"))
Fedu=int(input("Is the father educated::"))
traveltime=int(input("For how much time does your ward travel::"))
studytime=int(input("How many hours does your ward study::"))
failures=int(input("How many failures::"))
famrel=int(input("How are the family relations::"))
freetime=int(input("How much free time does your ward get::"))
goout=int(input("How many hours does your ward go out::"))
Dalc=int(input("How much alchohol does the father consume::"))
Walc=int(input("How much alcohol does the mother consume::"))
health=int(input("How is the ward's health::"))
absences=int(input("How many absences::"))
school_GP=int(input("Is the school LPS::"))
school_MS=int(input("Is the school VIVEK::"))
sex_F=int(input("Is the sex Female::"))
sex_M=int(input("Is the sex Male::"))
address_R=int(input("Do you live in a rural area::"))
address_U=int(input("Do you live in an urban area::"))
famsize_GT3=int(input("Are there more then 3 members in your family::"))
famsize_LE3=int(input("Are there less than 3 members in your family::"))
Pstatus_A=int(input("Are the parents apart::"))
Pstatus_T=int(input("Are the parents together::"))
Mjob_at_home=int(input("Does your mother stay at home::"))
Mjob_health=int(input("Does your mother work in health sector"))
Mjob_other=int(input("Does your mother have a job other than staying at home or healthcare or services or teacher::"))
Mjob_services=int(input("Does your mother work in service sector::"))
Mjob_teacher=int(input("Is your mother a teacher::"))
Fjob_at_home=int(input("Does your father stay at home::"))
Fjob_health=int(input("Does your father work in health sector"))
Fjob_other=int(input("Does your father have a job other than staying at home or healthcare or services or teacher::"))
Fjob_services=int(input("Does your father work in service sector::"))
Fjob_teacher=int(input("Is your father a teacher::"))
reason_course=int(input("Was there a particular reason of joining this school::"))
reason_home=int(input("Was the reason that the school was near home::"))
reason_reputation=int(input("Was the reason the school's reputation::"))
reason_other=int(input("Was there some other reason::"))
guardian_father=int(input("Is the guardian father::"))
guardian_mother=int(input("Is the guardian mother::"))
guardian_other=int(input("Do you have some other guardian apart from parents::"))
schoolsup_no=int(input("You dont have education support from school::"))
schoolsup_yes=int(input("You have educational support from school::"))
famsup_no=int(input("The family doesnt support you::"))
famsup_yes=int(input("The family supports you::"))
paid_no=int(input("You dont take extra classes::"))
paid_yes=int(input("You take extra classes::"))
activities_no=int(input("You dont do extra curricular activities::"))
activities_yes=int(input("You do extra curricular activities.::"))
nursery_no=int(input("You didnt attend nursery::"))
nursery_yes=int(input("You attended nursery::"))
higher_no=int(input("You dont want to take higher education::"))
higher_yes=int(input("You want to take higher education::"))
internet_no=int(input("You dont have internet access::"))
internet_yes=int(input("You have internet access::"))
romantic_no=int(input("You are not in a relationship::"))
romantic_yes=int(input("You are in a relationship::"))
sample=[[age, Medu, Fedu, traveltime, studytime, failures, famrel, freetime, 
        goout, Dalc, Walc, health, absences, school_GP, school_MS, sex_F, 
        sex_M, address_R, address_U, famsize_GT3, famsize_LE3, Pstatus_A, Pstatus_T,
        Mjob_at_home, Mjob_health, Mjob_other, Mjob_services, Mjob_teacher,
        Fjob_at_home, Fjob_health, Fjob_other, Fjob_services, Fjob_teacher, 
        reason_course, reason_home, reason_other, reason_reputation,
        guardian_father, guardian_mother, guardian_other, schoolsup_no,
        schoolsup_yes, famsup_no, famsup_yes, paid_no, paid_yes, activities_no,
        activities_yes, nursery_no, nursery_yes, higher_no, higher_yes,
        internet_no, internet_yes, romantic_no, romantic_yes]]
 
if u can find a more efficient way to put forward these questions since with the model i was using there were some problems with acceping string data so every question is yes or no. The model i used was working but the code is 120 lines due to the unacceptance of string data. 
Link to comment
Share on other sites

Link to post
Share on other sites

also i know that i hv done int input so string input wont work but i tried normal string input earlier and that didnt work so...

Link to comment
Share on other sites

Link to post
Share on other sites

On 11/4/2021 at 7:30 AM, steelo said:
from gpiozero import LED
import requests
from bs4 import BeautifulSoup
import csv
import os
import time

greenled=LED(4)
redled=LED(26)

def scrape():

   result = requests.get("https://www.pro-football-reference.com/boxscores/")
   src = result.content

   soup = BeautifulSoup(src, 'html.parser')

   length = len(soup.find_all("table"))
   table=soup.find_all("table")


   os.system('clear')
   for i in range(0,length,1):

     league_table=table[i]

     teams=league_table.find_all("tr")


     for team in teams[1:3]:
       stats=team.find_all("td")
       team_name = stats[0].text
       points = stats[1].text

       if team_name=="Buffalo Bills":
          for team in teams[1:10]:
           stats=team.find_all("td")
           if stats[0].text=="Buffalo Bills":
               bills=stats[0].text
               bills_points=stats[1].text
           else:
               opponent=stats[0].text
               opponent_points=stats[1].text

   return bills_points,opponent_points,opponent

def lights():

   bills_points,opp_points,opp=scrape() #pass bills score and opponent score from scrape function

   localtime = time.asctime( time.localtime(time.time()) )
   os.system('clear')
   print("")
   print("Bills:", bills_points)
   print(opp,":", opp_points)
   print("")
    print("As of",localtime)

   #greenled=LED(4)  add back if lights not working correctly using the led as global
   #redled=LED(26)

   if bills_points>opp_points:
       greenled.on()
       redled.off()
   elif bills_points<opp_points:
       greenled.off()
       redled.on()
   else:
       greenled.on()  #score tied
       redled.on()

   time.sleep(30) #timeout for 30 seconds between updates


while True:
  lights()

This is a silly scraper program I wrote while I was learning Python. It is meant to work on a rpi zero w and pulls data from a very simple website using tabular data. It pulls the current score of my favorite NFL team. If the Bills are winning, it will illuminate a green led, if they're losing a red led and if the score is tied, both lights will be activated. It provides an easy visual to check the status. It should be pretty easy to manipulate the code to your favorite team and GPIO pins of your choosing. 😀

i did something similar. I basically created a code to take the highest rates movies from imdb and go into one of my tv channels providers websites and if any of the movies were coming in the database it would print the date and time to tell when the movie will be showing(this was a time when my ott subscriptions were cut so i had to rely on live TV channels)

Link to comment
Share on other sites

Link to post
Share on other sites

1 hour ago, Smyan Narang said:

new goal
make a code to predict if user will pass or fail using ai and the following fields

 

if u can find a more efficient way to put forward these questions since with the model i was using there were some problems with acceping string data so every question is yes or no. The model i used was working but the code is 120 lines due to the unacceptance of string data. 

If that's Python  maybe you should use tkinter or something to make a GUI and use  input boxes, checkboxes and selection lists 

Then store all your questions in a csv file, or a json file or whatever for example 

 

variable name ,  input type  (checkbox for yes/no, true/false , input ) , question text ,  answers , min , max 

 

input type :   'c' = checkbox yes/no  , 't' = text input , 'n' = number input , 'o' = option list / selection list

answers  = for selection list  , enter possible answers  separated by some special character, for example '|'  ex  "Please choose:|Female|Male|I'd rather not say"  and 0 is please choose / nothing selected , 1 is female , 2 is male , 3 is I'd rather not say 

min and max  - minimums  and maximum values allowed  ex for age, say min=1 , max = 100 and report error if number is outside range.  Or min = 1 max = 3 for the selection list above will force user to actually pick something and not leave the selection on the default "Please choose:"

 

So your first few entries above would be something like : 

 

"age" , "n" , "Student age:", "",1,100

"fedu", "c", "Mother is educated","",0,0

"medu" , "c", "Father is educated","",0,0

"traveltime" , "n", "Number of days in a year your ward travels (1..366):","",1,366

"studytime", "n", "Number of hours in a day your ward studies (1..24):", "",1,24

"fjob", "o", "Mother's workplace" , "Please choose:|Healthcare|Financial services|Education (Teacher)|Other", 1,4

"fjob_other", "t", "If Other, please enter mother's job description:", "",0,0

 

Makes it much much easier to add or remove questions, no going in code to add stuff ...  edit questions, correct limits, validate input to some degree, allow user to go back and correct instead of getting bad data... 

 

... so your program can read the csv file line by line and put them in an array and  automatically create the controls (checkbox, selection list etc) on the screen and make some basic validation. Then your program can also use the array to retrieve all the information and dump it to a file in some format you can handle (csv, json, binary dump etc)

Would be super easy to do in PHP or Javascript, to have a FORM tag and populate the form with checkboxes and text inputs and number inputs and selection lists and then when the form is submitted or a button is pressed , the php code or javascript can collect the data and save it as required.

 
Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, mariushm said:

If that's Python  maybe you should use tkinter or something to make a GUI and use  input boxes, checkboxes and selection lists 

Then store all your questions in a csv file, or a json file or whatever for example 

 

variable name ,  input type  (checkbox for yes/no, true/false , input ) , question text ,  answers , min , max 

 

input type :   'c' = checkbox yes/no  , 't' = text input , 'n' = number input , 'o' = option list / selection list

answers  = for selection list  , enter possible answers  separated by some special character, for example '|'  ex  "Please choose:|Female|Male|I'd rather not say"  and 0 is please choose / nothing selected , 1 is female , 2 is male , 3 is I'd rather not say 

min and max  - minimums  and maximum values allowed  ex for age, say min=1 , max = 100 and report error if number is outside range.  Or min = 1 max = 3 for the selection list above will force user to actually pick something and not leave the selection on the default "Please choose:"

 

So your first few entries above would be something like : 

 

"age" , "n" , "Student age:", "",1,100

"fedu", "c", "Mother is educated","",0,0

"medu" , "c", "Father is educated","",0,0

"traveltime" , "n", "Number of days in a year your ward travels (1..366):","",1,366

"studytime", "n", "Number of hours in a day your ward studies (1..24):", "",1,24

"fjob", "o", "Mother's workplace" , "Please choose:|Healthcare|Financial services|Education (Teacher)|Other", 1,4

"fjob_other", "t", "If Other, please enter mother's job description:", "",0,0

 

... so your program can read the csv file line by line and put them in an array and  automatically create the controls (checkbox, selection list etc) on the screen and make some basic validation. Then your program can also use the array to retrieve all the information and dump it to a file in some format you can handle (csv, json, binary dump etc)

Would be super easy to do in PHP or Javascript, to have a FORM tag and populate the form with checkboxes and text inputs and number inputs and selection lists and then when the form is submitted or a button is pressed , the php code or javascript can collect the data and save it as required.

 

i did use tkinter and made a gui and all the questions were stored in a csv file in the final project but this is the root of the project and wanted to make this part right

Link to comment
Share on other sites

Link to post
Share on other sites

2 hours ago, mariushm said:

If that's Python  maybe you should use tkinter or something to make a GUI and use  input boxes, checkboxes and selection lists 

Then store all your questions in a csv file, or a json file or whatever for example 

 

variable name ,  input type  (checkbox for yes/no, true/false , input ) , question text ,  answers , min , max 

 

input type :   'c' = checkbox yes/no  , 't' = text input , 'n' = number input , 'o' = option list / selection list

answers  = for selection list  , enter possible answers  separated by some special character, for example '|'  ex  "Please choose:|Female|Male|I'd rather not say"  and 0 is please choose / nothing selected , 1 is female , 2 is male , 3 is I'd rather not say 

min and max  - minimums  and maximum values allowed  ex for age, say min=1 , max = 100 and report error if number is outside range.  Or min = 1 max = 3 for the selection list above will force user to actually pick something and not leave the selection on the default "Please choose:"

 

So your first few entries above would be something like : 

 

"age" , "n" , "Student age:", "",1,100

"fedu", "c", "Mother is educated","",0,0

"medu" , "c", "Father is educated","",0,0

"traveltime" , "n", "Number of days in a year your ward travels (1..366):","",1,366

"studytime", "n", "Number of hours in a day your ward studies (1..24):", "",1,24

"fjob", "o", "Mother's workplace" , "Please choose:|Healthcare|Financial services|Education (Teacher)|Other", 1,4

"fjob_other", "t", "If Other, please enter mother's job description:", "",0,0

 

Makes it much much easier to add or remove questions, no going in code to add stuff ...  edit questions, correct limits, validate input to some degree, allow user to go back and correct instead of getting bad data... 

 

... so your program can read the csv file line by line and put them in an array and  automatically create the controls (checkbox, selection list etc) on the screen and make some basic validation. Then your program can also use the array to retrieve all the information and dump it to a file in some format you can handle (csv, json, binary dump etc)

Would be super easy to do in PHP or Javascript, to have a FORM tag and populate the form with checkboxes and text inputs and number inputs and selection lists and then when the form is submitted or a button is pressed , the php code or javascript can collect the data and save it as required.

 

but this is really good thanks

Link to comment
Share on other sites

Link to post
Share on other sites

<html>
  <body>
    <a href="https://lttstore.com" padding="30px" background="orange" margin="auto" border-radius="20px">get off of this terrible website</a>
  </body>
</html>

 

please quote me or tag me @wall03 so i can see your response

motherboard buying guide      psu buying guide      pc building guide     privacy guide

ltt meme thread

folding at home stats

 

pc:

 

RAM: 16GB DDR4-3200 CL-16

CPU: AMD Ryzen 5 3600 @ 3.6GHz

SSD: 256GB SP

GPU: Radeon RX 570 8GB OC

OS: Windows 10

Status: Main PC

Cinebench R23 score: 9097 (multi) 1236 (single)

 

don't some things look better when they are lowercase?

-wall03

 

hello dark mode users

goodbye light mode users

Link to comment
Share on other sites

Link to post
Share on other sites

  • 2 weeks later...
On 11/8/2021 at 1:14 AM, Smyan Narang said:

i did something similar. I basically created a code to take the highest rates movies from imdb and go into one of my tv channels providers websites and if any of the movies were coming in the database it would print the date and time to tell when the movie will be showing(this was a time when my ott subscriptions were cut so i had to rely on live TV channels)

I'm very new to web scraping and am finding it's really difficult to understand the layout of web sites and knowing how to consistently pull the correct data when a website updates. I've tinkered with python for about a year and would consider myself to be a beginner-intermediate. Mainly, I'm trying to find useful projects for my rpi's 😁

Link to comment
Share on other sites

Link to post
Share on other sites

On 11/19/2021 at 4:19 AM, steelo said:

I'm very new to web scraping and am finding it's really difficult to understand the layout of web sites and knowing how to consistently pull the correct data when a website updates. 😁

Take a look at css selectors.

Development tools in browsers (F12 or right click -> inspect) can help a lot to find the data you are looking for. Under the console tab there is a fancy live javascript console where you can type code. For example typing in $$("#content .game_summary") will find all elements with the game_summary class inside the #content div.

image.thumb.png.8de3561862f49bc961e725539370f8f6.png

 

The same thing using BeautifulSoup would look like this: soup.select('#content .game_summary')

I hope this helps

ಠ_ಠ

Link to comment
Share on other sites

Link to post
Share on other sites

  • 2 weeks later...

Something that always drives me nuts is when I'm using an interface, and go to click on some part of the menu, but I do it at roughly the same time the program decides to make some change to the interface, and so I end up clicking on some button, option, etc.  It's always irritating, and depending on what the new item I can click on is, the results can be disastrous.

What I've started doing on the sites I work on is to "pause" certain events when I make changes to the interface for a few hundred milliseconds, to give the user time to recognize that the interface has changed.

The way I accomplish this is to attach an event listener to the document itself during the capturing phase (i.e. where the very first event listeners are called) and have it stop propagation and stop default.  I then use setTimeout to remove the handler after a certain period of time.

 

	function disableEvent(event, time){
	  var h = function(e){
	      e.preventDefault();
	      e.stopPropagation();
	      return false;
	  }
	  var ref = document;
	  ref.addEventListener(event, h, true);

	  setTimeout(function(){
	      ref.removeEventListener(event, h, true);
	  }, time);
	}
    
    //Example using it.  Disable the click event for 800ms
    disableEvent('click', 800);
    

Technically it doesn't fully prevent any action from taking place;  if another event listener was added to the document before this one, which also used capturing, then it could still get executed, however this is extremely unlikely since a) most people don't attach event listeners to the document itself, and b) most people don't event listeners with capturing.

 

 

 

 

 

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

  • 2 weeks later...

Simulate tail -f in the PowerShell:

function tail-f([string]$filename) {
	Get-Content "$filename" -Tail 10 -Wait
}

Write in C.

Link to comment
Share on other sites

Link to post
Share on other sites

  • 5 months later...

Made this Webscrapper (In Python) for an ecommerce site called Flipkart in my country. It plays you're music when the price of an the item goes below (or equal) a threshold given by the user. Mostly made it for my personal use before a sale.

 

Link

 

86 Lines!

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

  • 4 months later...
  • 1 month later...

Simple Fahrenheit <-> Celsius converter in Powershell:

function FtoC([double]$fahrenheit) {
    $celsius = ($fahrenheit - 32) * (5/9)
	'{0} °F = {1} °C' -f $fahrenheit,[math]::Round($celsius,3)
}

function CtoF([double]$celsius) {
    $fahrenheit = ($celsius * (9/5)) + 32
	'{0} °C = {1} °F' -f $celsius,[math]::Round($fahrenheit,3)
}

 

Write in C.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share



×