![]() |
|
Small usefull program - Printable Version +- Sinisterly (https://sinister.li) +-- Forum: Coding (https://sinister.li/Forum-Coding) +--- Forum: Coding (https://sinister.li/Forum-Coding--71) +--- Thread: Small usefull program (/Thread-Small-usefull-program) |
Small usefull program - Vi-Sion - 11-23-2016 So i was really bored had that idea to code something useful in small lines of code . I ended up coding a small program to randomly choose a movies from some movies i choose why well it happens a lot to me that i have some movies to watch and can't choose which one to watch first. Spoiler:Code: import java.util.Scanner;
import java.util.Random;
public class Movies {
public static String[] chooseYourMovies(){
Scanner in=new Scanner(System.in);
in.useDelimiter("\\n");
System.out.println("how many movies you want to enter :");
String []movies=new String[in.nextInt()];
for(int i=0;i<movies.length;i++){
System.out.println(i);
movies[i]=in.next();}
return movies;}
public static void randomMovie(String[]movies){
Random rand=new Random();
System.out.println(movies[rand.nextInt(movies.length)]);}
public static void main(String[] args) {
randomMovie(chooseYourMovies());
}}your turn what can you code something useful in a max of 20 lines ? RE: Small usefull program - Inori - 11-23-2016 20 lines is a lot of freedom if you know how to use it effectively. Run the program with a question mark as the first argument to see the syntax. Code: from urllib.parse import unquote
from requests import get
from sys import argv
if argv[1]=='?':
print("usage: python projectfinder.py [hot|new] [hour|day|week|month|year|all] [0-100]")
exit()
def get_settings():
if len(argv)==1: return ['hot','week','5']
return argv[1:].extend(['week','5'][:-(len(argv)-3)])
query=get(
"https://www.reddit.com/r/ProgrammingPrompts/{}.json?t={}&limit={}".format(*get_settings()),
headers={'user-agent': 'project-picker/0.1.0'}
).json()
for c in query['data']['children']:
print("\"%s\"\nlink: %s author: %s\n"%(unquote(c['data']['title']),'https://redd.it/'+c['data']['id'],c['data']['author']))RE: Small usefull program - Vi-Sion - 11-24-2016 @Inori if i'm not mistaken your using a library here, that's not what i was looking to see. RE: Small usefull program - Inori - 11-24-2016 (11-24-2016, 01:15 PM)Vi-Sion Wrote: @Inori if i'm not mistaken your using a library here, that's not what i was looking to see. I'm using a library for an http request; I could use urllib, which is part of the Python Standard Library, but it's shitty and bulky. RE: Small usefull program - Blink - 12-01-2016 Get public ip in 2 lines of Python: Code: import urllib2
urllib2.urlopen("http://icanhazip.com").read().decode("utf-8") |