Jump to content
Phishing Emails & YouTube Messages - Fake Giveaway Read more... ×
Search In
  • More options...
Find results that contain...
Find results in...
fletch to 99

The under 100 line challenge!

Recommended Posts

 

 

 
------------{asks user for number}-------------print("type a number")      local input = tonumber(io.read())----------{split number into digits within a table}----------- local Digit = {tonumber(string.sub(input, 1, 1)), tonumber(string.sub(input, 2, 2)), tonumber(string.sub(input, 3, 3))}local length = string.len(input)--------------{convert to number}--------------     local lengthNumber = tonumber(length)-----------{writing out the number}------------if lengthNumber == 1 thenif tonumber(input) == 1 thenio.write("One\n")endif tonumber(input) == 2 thenio.write("Two\n")endif tonumber(input) == 3 thenio.write("Three\n")endif tonumber(input) == 4 thenio.write("Four\n")endif tonumber(input) == 5 thenio.write("Five\n")endif tonumber(input) == 6 thenio.write("Six\n")endif tonumber(input) == 7 thenio.write("Seven\n")endif tonumber(input) == 8 thenio.write("Eight\n")endif tonumber(input) == 9 thenio.write("Nine\n")endendif (lengthNumber == 2 and Digit[1] == 1) thenif Digit[2] == 0 thenio.write("Ten\n")endif Digit[2] == 1 thenio.write("Eleven\n")endif Digit[2] == 2 thenio.write("Twelve\n")endif Digit[2] == 3 thenio.write("Thirteen\n")endif Digit[2] == 4 thenio.write("Fourteen\n")endif Digit[2] == 5 thenio.write("Fifteen\n")endif Digit[2] == 6 thenio.write("Sixteen\n")endif Digit[2] == 7 thenio.write("Seventeen\n")endif Digit[2] == 8 thenio.write("Eighteen\n")endif Digit[2] == 9 thenio.write("Nineteen\n")endendif (lengthNumber == 2 and Digit[1] == 2) thenio.write("Twenty")if Digit[2] == 1 thenio.write("One\n")endif Digit[2] == 2 thenio.write("Two\n")endif Digit[2] == 3 thenio.write("Three\n")endif Digit[2] == 4 thenio.write("Four\n")endif Digit[2] == 5 thenio.write("Five\n")endif Digit[2] == 6 thenio.write("Six\n")endif Digit[2] == 7 thenio.write("Seven\n")endif Digit[2] == 8 thenio.write("Eight\n")endif Digit[2] == 9 thenio.write("Nine\n")endend
 

LUA

 

this is my first real world application program, however it is not finished it only accepts integers 1-29., it probably could be under 100 lines, but i like to make my code readable. had trouble with the if, else, elseif and a few other small mistakes, but my friend Austin helped me out like the good friend that he is

 

Not sure if it would work, but you might be able to use two switch methods to make your code significantly shorter


I5-4670k @ 4.2ghz With Thermaltake C5 Push/Pull | 8Gb G.Skill Trident series @1600mhz Msi Z87A-G45 Gaming Edition | ASUS GTX 770 GPU | Thermaltake Toughpower Gold 750W | Samsung 840pro 128gb SSD | WD Green 2Tb |  2X 23" Philips M4238C1CWWT (IPS & Thin Bezel) Monitors

 

 

Link to post
Share on other sites

Not sure if it would work, but you might be able to use two switch methods to make your code significantly shorter

what is the two switch method?


Energy can not be created nor destroyed, just converted to a different Type of energy.
My blog: T3Krant.blogspot.com

Link to post
Share on other sites

what is the two switch method?

Lua doesn't have a C style switch statement, therefore one cannot be used. 

 

Though, you don't have to have a line break after the then statements and you could use elseifs so you don't have lots of end statements.


Arch Linux on Samsung 840 EVO 120GB: Startup finished in 1.334s (kernel) + 224ms (userspace) = 1.559s | U mad windoze..?

Link to post
Share on other sites

Unfortunately I can't post it here due to copyright issues with the company I work for, but I'll post what it does, in only 107 lines (I'm sure I could trim it down if needed). The program starts and monitors critical programs that our field users need in order to complete tasks.  There are 4 programs they need, VZAccess Manager, Cisco Anyconnect, Oracle RFTransport, and finally a Mobile Work tool they use for orders and instruction.  After opening the programs depending on the status of the required program in order above it, it then monitors the status and fixes any issues that could arise.  Basically it makes sure the programs are opened in the correct order, then it monitors the status for say a hiccup in the network connection, then corrects the issue to make sure the end product (The Mobile Tool) stays working.

 

The big issue is that 90% of the guys are completely ignorant as to how a computer works, let alone understanding why the wireless card needs to be on before starting VPN, and that VPN is required to access our internal network.  Since they don't get that, they don't get how to fix issues when they arise, and usually what happens is these neanderthals hit the laptop or make things worse trying to fix it themselves, so I had to create something to make it easier to use.

 

Anyway, I wish I could post it here considering it's a great example of how to use a single block of code (function) to complete many different actions, but I'm pretty sure the city I work for wouldn't appreciate me posting copyrighted material (even though I'm the author, gotta love politics).  One of the biggest things we always stress in programming is using code as efficiently as possible with the least amount of overhead.


01110100 01101000 01100101 00100000 01110001 01110101 01101001 01100101 01110100 01100101 01110010 00100000 01111001 01101111 01110101 00100000 01100010 01100101 01100011 01101111 01101101 01100101 00101100 00100000 01110100 01101000 01100101 00100000 01101101 01101111 01110010 01100101 00100000 01111001 01101111 01110101 00100000 01100001 01110010 01100101 00100000 01100001 01100010 01101100 01100101 00100000 01110100 01101111 00100000 01101000 01100101 01100001 01110010

 

Link to post
Share on other sites

Anyway, I wish I could post it here considering it's a great example of how to use a single block of code (function) to complete many different actions, but I'm pretty sure the city I work for wouldn't appreciate me posting copyrighted material (even though I'm the author, gotta love politics).  One of the biggest things we always stress in programming is using code as efficiently as possible with the least amount of overhead.

 

No offense, but you should really watch out with what you're saying here. In terms of overhead, the function call stack adds next to nothing, and modifying one part of this function can potentially break another part of it. If you're extending the same logic to Classes as well, you're violating https://en.wikipedia.org/wiki/Single_responsibility_principle'>single responsibility. Yes, overhead is important to consider, but having one function DoAllTheThings() is not good practice.

 

Other than that, carry on.


Case: CM HAF X NVidia Edition; MoBo: ASUS Sabertooth X58; CPU: Intel Core i7 950@stock (OC will happen later); Cooler: CM Nepton 140XL; RAM: 6x4GB Mushkin Blackline; GPU: MSI GTX 560-Ti Hawk Edition; Primary HDD: Seagate Momentus XT 750GB; OS: Windows 7 Ultimate; Storage: 4x1TB RAID5 (3TB effectively);
Link to post
Share on other sites

Okay so here is my submission. This is written in OCaml (functional language) which allows a different style of coding and the ability for short concise instructions (24 lines)

What the program does:
This is a function that sorts a list of non-empty lists increasingly according to the maximum element in the list.

e.g.

[ [7;6;5;4]; [4;3;2]; [1; 2; 3] ]   =   [ [1;2;3]; [4;3;2]; [7;6;5;4] ]

so 3 is the max element in the first list, 4 is the max element in the second, 7 is the max in the third and so on...

let rec matchlst l1 l2 = match l1,l2 with   | [],[] -> true   | [],_ -> false   | _,[] -> false   | hd1::tl1,hd2::tl2 -> if hd1=hd2 then matchlst tl1 tl2 else false let rec largestSingle lst max = match lst with   | [] -> max   | hd::tl -> if hd>max then largestSingle tl hd else largestSingle tl max let rec delete elem list = match list with   | [] -> []   | hd::tl -> if(matchlst hd elem) then tl else hd::(delete elem tl) let rec largest lst largeSing largeList = match lst with   | [] -> largeList   | hd::tl -> match hd with      | [] -> largest tl largeSing largeList      | hd'::tl' -> if (largestSingle hd min_int) >= largeSing then largest tl (largestSingle hd min_int) hd else largest tl largeSing largeListlet rec sortll lst = match lst with   | [] -> []   | hd::tl -> let max = (largest lst min_int []) in      (sortll (delete max lst))@([max])

http://try.ocamlpro.com/
^ an online parser for those interested.

Thanks for reading

Link to post
Share on other sites

Nice, OCaml. I love functional languages. Just so sexy. :)

 

Made me feel like writing something in OCaml, here's a powerset function. As the name implies, produces the powerset of a set (in a list).

let rec powerset l =     match l with        [] -> [[]]      | x::xs -> powerset xs @ List.map (fun l -> x::l) (powerset xs);; powerset [1;2;3] = [[]; [3]; [2]; [2; 3]; [1]; [1; 3]; [1; 2]; [1; 2; 3]];; 

 


Want to solve problems? Check this out.

Link to post
Share on other sites
package org.assume.ScriptInstaller;import java.io.File;import javax.swing.JFileChooser;import javax.swing.JOptionPane;import javax.swing.UIManager;import javax.swing.UnsupportedLookAndFeelException;import javax.swing.filechooser.FileNameExtensionFilter;import net.lingala.zip4j.core.ZipFile;import net.lingala.zip4j.exception.ZipException;public class ScriptInstaller{	public static void main(String[] args) throws ZipException, UnsupportedLookAndFeelException	{		UIManager.setLookAndFeel(UIManager.getLookAndFeel());		final JFileChooser fc = new JFileChooser();		ZipFile zip = null;		fc.setFileFilter(new FileNameExtensionFilter("zip","zip"));		fc.setFileFilter(new FileNameExtensionFilter("jar", "jar"));		fc.setAcceptAllFileFilterUsed(false);		String location = null;		if(fc.showOpenDialog(null) == JFileChooser.APPROVE_OPTION)		{			zip = new ZipFile(fc.getSelectedFile());		}		switch((String) JOptionPane.showInputDialog(null, 				"Extract to /bin or /bin/scripts",				"Location",				JOptionPane.QUESTION_MESSAGE, 				null, 				new String[]{"bin", "scripts"}, 				"scripts"))				{				case "bin":					location = System.getProperty("user.home")+					File.separator+					"AppData"+					File.separator+					"Roaming"+					File.separator+					".tribot"+					File.separator+					"bin";					break;				case "scripts":					location = System.getProperty("user.home")+					File.separator+					"AppData"+					File.separator+					"Roaming"+					File.separator+					".tribot"+					File.separator+					"bin"+					File.separator+                                        "scripts";					break;				}		if(zip != null && location != null)		{				zip.extractAll(location);		}	}} 

It doesn't really apply to any of you but it does for the people I created it for (they can't figure out how to extract zip or jar files). 

If you want to compile it from source you will need a 3rd party library.

Get it here: http://www.lingala.net/zip4j/

Link to post
Share on other sites
Posted · Original PosterOP
package org.assume.ScriptInstaller;import java.io.File;import javax.swing.JFileChooser;import javax.swing.JOptionPane;import javax.swing.UIManager;import javax.swing.UnsupportedLookAndFeelException;import javax.swing.filechooser.FileNameExtensionFilter;import net.lingala.zip4j.core.ZipFile;import net.lingala.zip4j.exception.ZipException;public class ScriptInstaller{	public static void main(String[] args) throws ZipException, UnsupportedLookAndFeelException	{		UIManager.setLookAndFeel(UIManager.getLookAndFeel());		final JFileChooser fc = new JFileChooser();		ZipFile zip = null;		fc.setFileFilter(new FileNameExtensionFilter("zip","zip"));		fc.setFileFilter(new FileNameExtensionFilter("jar", "jar"));		fc.setAcceptAllFileFilterUsed(false);		String location = null;		if(fc.showOpenDialog(null) == JFileChooser.APPROVE_OPTION)		{			zip = new ZipFile(fc.getSelectedFile());		}		switch((String) JOptionPane.showInputDialog(null, 				"Extract to /bin or /bin/scripts",				"Location",				JOptionPane.QUESTION_MESSAGE, 				null, 				new String[]{"bin", "scripts"}, 				"scripts"))				{				case "bin":					location = System.getProperty("user.home")+					File.separator+					"AppData"+					File.separator+					"Roaming"+					File.separator+					".tribot"					+File.separator+"bin";					break;				case "scripts":					location = System.getProperty("user.home")+					File.separator+					"AppData"+					File.separator+					"Roaming"+					File.separator+					".tribot"					+File.separator+"bin"+File.separator+"scripts";					break;				}		if(zip != null && location != null)		{			zip.extractAll(location);		}	}}

It doesn't really apply to any of you but it does for the people I created it for (they can't figure out how to extract zip or jar files). 

If you want to compile it from source you will need a 3rd party library.

Get it here: http://www.lingala.net/zip4j/

 

Runescape bots... I remember that haha. http://pastebin.com/9xi4a4CG

 

My first ever script for RSBot, over 1 million unique downloads. The code is horrendous but the script was flawless. And yeah I can see the purpose of your code, most of the botting scene is filled with idiots. :)

 

Also why use an external lib to extract the files?


There are 10 types of people in this world, those who can read binary and those who can't.

There are 10 types of people in this world, those who can read hexadecimal and F the rest.

~Fletch

Link to post
Share on other sites

Runescape bots... I remember that haha. http://pastebin.com/9xi4a4CG

 

My first ever script for RSBot, over 1 million unique downloads. The code is horrendous but the script was flawless. And yeah I can see the purpose of your code, most of the botting scene is filled with idiots. :)

 

Also why use an external lib to extract the files?

The default library can't handle zip files created from 7zip. 

 

@your script

 

My god, so many lines. My AIO combat script with banking is less than that :P

Link to post
Share on other sites
Posted · Original PosterOP

The default library can't handle zip files created from 7zip. 

 

@your script

 

My god, so many lines. My AIO combat script with banking is less than that :P

Ah okay.


There are 10 types of people in this world, those who can read binary and those who can't.

There are 10 types of people in this world, those who can read hexadecimal and F the rest.

~Fletch

Link to post
Share on other sites
Posted · Original PosterOP

You should get back into the botting scene. The money is absolutely insane for the amount of work you have to put in. 

 

I need to get a job haha. I'm 16 also, I'm assuming (no pun intended) that is how you make money? :P -- Also are you on pb or just tribot?


There are 10 types of people in this world, those who can read binary and those who can't.

There are 10 types of people in this world, those who can read hexadecimal and F the rest.

~Fletch

Link to post
Share on other sites

I need to get a job haha. I'm 16 also, I'm assuming (no pun intended) that is how you make money? :P -- Also are you on pb or just tribot?

I'm just on Tribot. I could never do anything on PB as I have no experience with EoC (the new combat system) so my scripts would be absolutely terrible. Tribot only does RuneScape 2007. When I say money, I mean a real amount of money (I out earned my teachers last month). 

Link to post
Share on other sites

URLUtil.java

package org.assume.api.networking;import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import java.net.URL;import java.util.ArrayList;import java.util.Collection;import org.assume.api.types.URLW;public class URLUtil{	private String url_;	private String extension_;	public URLUtil(String url, String extension)	{		this.url_ = url;		this.extension_ = extension;	}	public URLUtil(String url)	{		this.url_ = url;		this.extension_ = "";	}	public URLW[] getFileUrls() throws IOException	{		Collection<URLW> list = new ArrayList<URLW>();		BufferedReader in = new BufferedReader(				new InputStreamReader(new URL(url_).openStream()));		String line;		while((line = in.readLine()) != null)		{			for(String d : line.split(" "))			{				/* If the line of html contains the file extension that is passed it will execute the code below				 * Since a line of html could look like this http://someurlhere.com/blah/blah <src>http://someurlhere.com/image.jpg</src> 				 * You need to split at each space on the line (a url can't have a space) and check once again until you get to the end of the line				 * When it find a correctly formatted URL it creates a substring starting at http and ending at the file extension.				 * Since it will remove the file extension on the END of the url, you need to add it back after creating the substring				 * It does not remove http when creating a substring				 * It does not matter if you pass '.jpg' or 'jpg'. You can do either				 */				if(d.contains(extension_) && d.contains("http"))				{		list.add(new URLW(new URL(d.substring(d.indexOf("http"), d.indexOf(extension_)).concat(extension_))));				}			}		}		in.close();		return list.toArray(new URLW[list.size()]);	}	public URLW[] getImageUrls() throws IOException	{		Collection<URLW> list = new ArrayList<URLW>();		BufferedReader in = new BufferedReader(				new InputStreamReader(new URL(url_).openStream()));		String line;		while ((line = in.readLine()) != null)		{			if(line.contains(".jpg") ||		line.contains(".gif") ||		line.contains(".jpeg") ||		line.contains(".png") ||		line.contains(".bmp") ||		line.contains(".webp"))			{				/* If the line of html contains any of the above image file extensions it will execute the code below				 * Since a line of html could look like this http://someurlhere.com/blah/blah <src>http://someurlhere.com/image.jpg</src> 				 * You need to split at each space on the line (a url can't have a space) and check once again until you get to the end of the line				 * When it find a correctly formatted URL it creates a substring starting at http and ending at the file extension.				 * Since it will remove the file extension on the END of the url, you need to add it back after creating the substring				 * It does not remove http when creating a substring				 */				for(String d : line.split(" "))				{		if(d.contains(".jpg") && d.contains("http"))		{		list.add(new URLW(new URL(d.substring(d.indexOf("http"), d.indexOf(".jpg")).concat(".jpg"))));		}		else if(d.contains(".gif") && d.contains("http"))		{		list.add(new URLW(new URL(d.substring(d.indexOf("http"), d.indexOf(".gif")).concat(".gif"))));		}		else if(d.contains(".png") && d.contains("http"))		{		list.add(new URLW(new URL(d.substring(d.indexOf("http"), d.indexOf(".png")).concat(".png"))));		}		else if(d.contains(".jpeg") && d.contains("http"))		{		list.add(new URLW(new URL(d.substring(d.indexOf("http"), d.indexOf(".jpeg")).concat(".jpeg"))));		}		else if(d.contains(".bmp") && d.contains("http"))		{		list.add(new URLW(new URL(d.substring(line.indexOf("http"), d.indexOf(".bmp")).concat(".bmp"))));		}		else if(d.contains(".webp") && d.contains("http"))		{		list.add(new URLW(new URL(d.substring(d.indexOf("http"), d.indexOf(".webp")).concat(".webp"))));		}				}			}		}		in.close();		return list.toArray(new URLW[list.size()]);	}}
URLW.java

package org.assume.api.types;import java.io.BufferedOutputStream;import java.io.File;import java.io.FileOutputStream;import java.io.IOException;import java.io.InputStream;import java.io.OutputStream;import java.net.URL;import java.net.URLConnection;public class URLW{	private URL url_;	public URLW(URL url)	{		this.url_ = url;	}	public String getFileExtension()	{		return this.url_.toString().substring(this.url_.toString().lastIndexOf("."));	}	public String getFileName()	{		return this.url_.toString().substring(this.url_.toString().lastIndexOf("/"));	}	public boolean download(String fileName)	{		/* The file name is the FULL path 		 *  ex. System.getProperty("user.home")+		 *		File.separator+		 *		"Users"+		 *		File.separator+		 *		"Adam"+		 *		File.separator+		 *		"documents"+		 *		File.separator+		 *		"food"+		 *		"food.png");		 */		OutputStream out = null;		URLConnection connection = null;		InputStream in = null;		try {			out = new BufferedOutputStream(new FileOutputStream(fileName));			connection = this.getUrl().openConnection();			in = connection.getInputStream();			byte[] buffer = new byte[1024];			int read;			while ((read = in.read(buffer)) != -1) 			{				out.write(buffer, 0, read);			}		} catch (Exception e) 		{			e.printStackTrace();		} finally 		{			try 			{				if (in != null)				{		in.close();				}				if (out != null)				{		out.close();				}			} catch (IOException e) 			{			}		}		return new File(fileName).exists();	}	@Override	public String toString()	{		return this.url_.toString();	}	public URL getUrl()	{		return url_;	}}
(URL is a final class so you can't write a wrapper. This is the next best thing)

Usage:

 

import java.io.IOException;import org.assume.api.networking.URLFinder;public class Test{	public static void main(String[] args) throws IOException	{		for(URLW d : new URLUtil("http://imgur.com").getImageUrls())		{			System.out.println(d.toString());		}	}}
Output:

http://s.imgur.com/images/album-layout-blog.pnghttp://s.imgur.com/images/album-layout-vertical.pnghttp://s.imgur.com/images/album-layout-horizontal.pnghttp://s.imgur.com/images/album-layout-grid.pnghttp://i.imgur.com/ocehWZkb.jpghttp://i.imgur.com/1zY2EMN.jpghttp://i.imgur.com/mYHqxztb.jpghttp://i.imgur.com/ocehWZkb.jpghttp://i.imgur.com/rehzQkSb.jpghttp://i.imgur.com/rehzQkSb.jpghttp://s.imgur.com/images/blog_rss.pnghttp://s.imgur.com/images/follow_twitter.pnghttp://i.imgur.com/z0f7KK1b.jpghttp://i.imgur.com/wWHLwScb.jpghttp://i.imgur.com/PGk5v2xb.jpghttp://i.imgur.com/ocehWZkb.jpghttp://i.imgur.com/9C6dfnXb.jpghttp://i.imgur.com/rfCw5ehb.jpghttp://i.imgur.com/dGyiGtXb.jpghttp://i.imgur.com/AhSv0ZXb.jpghttp://i.imgur.com/kA3uAmsb.jpghttp://i.imgur.com/LiB1c6vb.jpghttp://i.imgur.com/5i4u09Fb.jpghttp://i.imgur.com/yFrA03eb.jpghttp://i.imgur.com/WKUURF8b.jpghttp://i.imgur.com/CMc6GzUb.jpghttp://i.imgur.com/h3SSqhgb.jpghttp://i.imgur.com/CEA8PBsb.jpghttp://i.imgur.com/NvQloghb.jpghttp://i.imgur.com/GWtiJFAb.jpghttp://i.imgur.com/IrF2pWab.jpghttp://i.imgur.com/WUk501Bb.jpghttp://i.imgur.com/Oxq9BjSb.jpghttp://i.imgur.com/PWq5A2gb.jpghttp://i.imgur.com/Oj1xRIdb.jpghttp://i.imgur.com/tjLBuipb.jpghttp://i.imgur.com/kHkReS5b.jpghttp://i.imgur.com/mdiKUWLb.jpghttp://i.imgur.com/D7g1nw6b.jpghttp://i.imgur.com/4dJzahYb.jpghttp://i.imgur.com/3PLD9Qub.jpghttp://i.imgur.com/y3ZSTqUb.jpghttp://i.imgur.com/qhOgOBKb.jpghttp://i.imgur.com/vyR0gohb.jpghttp://i.imgur.com/iDWcn6Nb.jpghttp://i.imgur.com/Ni7rq5tb.jpghttp://i.imgur.com/3WmyNe5b.jpghttp://i.imgur.com/r42WNAVb.jpghttp://i.imgur.com/1TnD4KVb.jpghttp://i.imgur.com/KsGnU1hb.jpghttp://i.imgur.com/1WARXenb.jpghttp://i.imgur.com/aP419pAb.jpghttp://i.imgur.com/GmybjVkb.jpghttp://i.imgur.com/OqfbeV3b.jpghttp://i.imgur.com/0Asd6gBb.jpghttp://i.imgur.com/SceIabXb.jpghttp://i.imgur.com/11e1VLLb.jpghttp://i.imgur.com/P3I24Xmb.jpghttp://i.imgur.com/mYHqxztb.jpghttp://i.imgur.com/9lru4d1b.jpghttp://i.imgur.com/3DnBIJPb.jpghttp://i.imgur.com/zULbRo6b.jpghttp://i.imgur.com/swui40Yb.jpghttp://i.imgur.com/cvYXfxzb.jpghttp://i.imgur.com/alEfzZ5b.jpghttp://i.imgur.com/4LjAvDrb.jpghttp://i.imgur.com/WmDhuSbb.jpghttp://i.imgur.com/Zn3iBqTb.jpghttp://s.imgur.com/images/album_loader.gif

 

import java.io.IOException;import org.assume.api.networking.URLUtil;public class Test{	public static void main(String[] args) throws IOException	{		for(URLW d : new URLUtil("http://engagdet.com", ".jpg").getFileUrls())		{			System.out.println(d.toString());		}	}}
Output:

http://www.blogcdn.com/www.engadget.com/media/2013/06/dsc06805-1371836249_320x170.jpghttp://www.blogcdn.com/www.engadget.com/media/2012/12/eng-podcast-620_320x170.jpghttp://www.blogcdn.com/www.engadget.com/media/2013/06/primesenseinteractionsronengoldman1_320x170.jpghttp://www.blogcdn.com/www.engadget.com/media/2013/06/untitled-1-1371757143_320x170.jpghttp://www.blogcdn.com/www.engadget.com/media/2013/06/boundlessinformant_320x170.jpghttp://www.blogcdn.com/www.engadget.com/media/2013/06/mobile-miscellany-1371947615.jpghttp://www.blogcdn.com/www.engadget.com/media/2013/06/mobile-miscellany-1371947615.jpghttp://www.blogcdn.com/www.engadget.com/media/2013/06/alt-week-2013-06-22-03.jpghttp://www.blogcdn.com/www.engadget.com/media/2013/06/alt-week-2013-06-22-03.jpghttp://www.blogcdn.com/www.engadget.com/media/2013/06/dsc06805-1371836249.jpghttp://www.blogcdn.com/www.engadget.com/media/2013/06/dsc06805-1371836249.jpghttp://www.blogcdn.com/www.engadget.com/media/2013/06/waze-android.jpghttp://www.blogcdn.com/www.engadget.com/media/2013/06/waze-android.jpghttp://www.blogcdn.com/www.engadget.com/media/2012/11/googlenews.jpghttp://www.blogcdn.com/www.engadget.com/media/2012/11/googlenews.jpghttp://www.blogcdn.com/www.engadget.com/media/2013/06/b-1371832321.jpghttp://www.blogcdn.com/www.engadget.com/media/2013/06/b-1371832321.jpghttp://www.blogcdn.com/www.engadget.com/media/2013/06/xbox-music-windows-8-june-2013.jpghttp://www.blogcdn.com/www.engadget.com/media/2013/06/xbox-music-windows-8-june-2013.jpghttp://www.blogcdn.com/www.engadget.com/media/2013/05/twitchfor360jt.jpghttp://www.blogcdn.com/www.engadget.com/media/2013/05/twitchfor360jt.jpghttp://www.blogcdn.com/www.engadget.com/media/2013/06/phone-wiretap-david-drexler-flickr.jpghttp://www.blogcdn.com/www.engadget.com/media/2013/06/phone-wiretap-david-drexler-flickr.jpg

Downloading:

import java.io.File;import java.io.IOException;import org.assume.api.networking.URLUtil;import org.assume.api.types.URLW;public class Test{	public static void main(String[] args) throws IOException	{		for(URLW d : new URLUtil("https://imgur.com").getImageUrls())		{			System.out.println(d.toString());			if(d.download(System.getProperty("user.home")+				File.separator+				"Test"+				File.separator+				d.getFileName()))			{			System.out.println("Success");			}		}	}}
Output:

cf9f4cc546.jpg

**Ignore the fucked up formatting. I don't know why the code tags are so shit.

Link to post
Share on other sites

 

No offense, but you should really watch out with what you're saying here. In terms of overhead, the function call stack adds next to nothing, and modifying one part of this function can potentially break another part of it. If you're extending the same logic to Classes as well, you're violating single responsibility. Yes, overhead is important to consider, but having one function DoAllTheThings() is not good practice.

 

Other than that, carry on.

 

I didn't say that I made ONE function to do EVERYTHING.  I made a generalized statement on how it's an example of how to have one function do many things.  Here is the exactly quote, as you quoted:

 

Anyway, I wish I could post it here considering it's a great example of how to use a single block of code (function) to complete many different actions, but I'm pretty sure the city I work for wouldn't appreciate me posting copyrighted material (even though I'm the author, gotta love politics).  One of the biggest things we always stress in programming is using code as efficiently as possible with the least amount of overhead.

 

 

Just to clarify, other than that, carry on smartly (military guys will get it).


01110100 01101000 01100101 00100000 01110001 01110101 01101001 01100101 01110100 01100101 01110010 00100000 01111001 01101111 01110101 00100000 01100010 01100101 01100011 01101111 01101101 01100101 00101100 00100000 01110100 01101000 01100101 00100000 01101101 01101111 01110010 01100101 00100000 01111001 01101111 01110101 00100000 01100001 01110010 01100101 00100000 01100001 01100010 01101100 01100101 00100000 01110100 01101111 00100000 01101000 01100101 01100001 01110010

 

Link to post
Share on other sites

A very simple program, to convert Pounds to Kilograms.

Can be useful if you aren't very quick with math or you're just lazy like me :)

package com.linustechtips;import javax.swing.JOptionPane;public class PoundsToKilogramsConverter {    public static void main(String[] args) {        while (true) {            String title = "Pounds => Kilograms Converter";            String lbsInput = JOptionPane.showInputDialog(null, "Type \"exit\" to close the program.\n\nEnter the number of pounds (lbs.):", title, JOptionPane.QUESTION_MESSAGE);            if (lbsInput.equalsIgnoreCase("exit")) exit();            try {                double lbs = Double.parseDouble(lbsInput);                double kg = lbs * 0.453592;                JOptionPane.showMessageDialog(null, "Convertion Complete!\n\n" + lbs + "lbs = " + kg + "Kg\n", title, JOptionPane.INFORMATION_MESSAGE);            }            catch (NumberFormatException e) {                JOptionPane.showMessageDialog(null, "\"" + lbsInput + "\" is not a number!\n\nPlease enter a number.\n", title, JOptionPane.ERROR_MESSAGE);            }            catch (NullPointerException e) {                exit();            }        }    }    private static void exit() {        System.exit(0);    }}

Intel i7-2700k @4.7GHz | Asus Maximus V Formula | Asus GTX 680 DirectCU II OC | Corsair Vengeance 16GB | Corsair H100i | Corsair AX860i | Corsair GTX Neutron 120GB | Corsair 800D | WD Black 1TB
If you can't tell, I like Asus & Corsair ;)

Link to post
Share on other sites

Here is one in VB I made today for a friend and remembered this thread, Don't know if VB is valid but here it is:

www.mediafire.com/download/2u84oerqc2aooa8/FlipsHorizontal.zip

He wanted me to teach him how to flip an image horizontally because his camera captures it flipped the wrong way, so instead I made this.

 

Public Class Form1    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load        Dim sourceImage As Bitmap        Dim pathParts() As String        Dim SavePath As String = String.Empty        Dim finalPath As String = String.Empty        Dim indexCount As Integer = 0        Dim Args As System.Collections.ObjectModel.ReadOnlyCollection(Of String) = My.Application.CommandLineArgs        If Args.Count = 0 Then            MsgBox("Please drag an image onto the" & vbNewLine & "executable to use the progam")        Else            For i As Integer = 0 To Args.Count - 1                indexCount = 0                SavePath = String.Empty                pathParts = Args(i).Split("\")                For x = 0 To pathParts.Length - 2 : SavePath &= pathParts(x) & "\" : Next                sourceImage = New Bitmap(Args(i))                sourceImage.RotateFlip(RotateFlipType.RotateNoneFlipX)                finalPath = SavePath & pathParts(pathParts.Length - 1).Split(".")(0) & " - Flipped.png"                Do While IO.File.Exists(finalPath)                    indexCount += 1                    finalPath = SavePath & pathParts(pathParts.Length - 1).Split(".")(0) & " - Flipped (" & indexCount.ToString & ").png"                Loop                sourceImage.Save(finalPath, Imaging.ImageFormat.Png)            Next            MsgBox("All images processed" & vbNewLine & "                  -By: TizzyT")        End If        Me.Close()    End SubEnd Class
Link to post
Share on other sites
Posted · Original PosterOP

Here is one in VB I made today for a friend and remembered this thread, Don't know if VB is valid but here it is:

www.mediafire.com/download/2u84oerqc2aooa8/FlipsHorizontal.zip

He wanted me to teach him how to flip an image horizontally because his camera captures it flipped the wrong way, so instead I made this.

I could use that for when I take pictures with my ipad. Thanks :)


There are 10 types of people in this world, those who can read binary and those who can't.

There are 10 types of people in this world, those who can read hexadecimal and F the rest.

~Fletch

Link to post
Share on other sites

I wrote a hex to dec(epoch) to English converter for a friend a while back in php: http://sysnative.com/drivers/hextime.php

 

Has a very specific purpose to check the time stamps on drivers so not a huge scope but, it works...

 

<?date_default_timezone_set('GMT');$curyear = date('Y'); //Current Year + 30if(isset($_POST['submit'])){$month = $_POST['month'];$day = trim($_POST['day']);$year = trim($_POST['year']);$hour = $_POST['hour'];$min = trim($_POST['min']);$sec = trim($_POST['sec']);if((!is_numeric($day))||(1 > $day)||($day > 31)) echo '<p class="red">Day is invalid</p>';elseif((!is_numeric($year))||(1970 > $year)||($year > $curyear)) echo '<p class="red">Year is invalid, please input a year later then 1970 and earlier than '.$curyear.'</p>';elseif((!is_numeric($min))||(0 > $min)||($min > 59)) echo '<p class="red">Minutes is invalid</p>';elseif((!is_numeric($sec))||(0 > $sec)||($sec > 59)) echo '<p class="red">Seconds is invalid</p>';else{echo "<p><b>Hex Time:</b> ";printf("%08s\n", strtoupper(dechex(mktime($hour, $min, $sec, $month, $day, $year))));echo "</p>";echo "<p><b>Dec Time:</b> ";printf("%08s\n", strtoupper(mktime($hour, $min, $sec, $month, $day, $year)));echo "</p>";//echo "<p style=\"font-size:10px;\"><b>Seconds since 1/1/1970:</b> ".mktime($hour, $min, $sec, $month, $day, $year)."</p>";}}?>...<?$hextime = "";if(isset($_POST['submit2'])){$hextime = trim($_POST['hextime']);if ((ereg("[a-fA-F0-9]{8}",$hextime) && strlen($hextime)==8)){echo '<p><b>Time:</b> '.date("D M j H:i:s Y","0x".$hextime).'</p>';echo '<p><b>Dec Time:</b> '.strtoupper(hexdec($hextime)).'</p>';}else echo "<p class=\"red\">Please input a valid Hex time. (8 digits 0-F)</p>"; }?>...<?$dectime = "";if(isset($_POST['submit3'])){$dectime = trim($_POST['dectime']);if (is_numeric($dectime)){echo '<p><b>Time:</b> '.date("D M j H:i:s Y","".$dectime).'</p>';echo '<p><b>Hex Time:</b> '.strtoupper(dechex((float)$dectime)).'</p>';}else echo "<p class=\"red\">Please input a valid Decimal time. (seconds since 1970)</p>"; }?>

 

The rest is all HTML forms and not really code...

 

Link to post
Share on other sites
Posted · Original PosterOP

This is perfect to annoy someone who is computer illiterate (specifically siblings who hog the family computer). Just throw this in startup on their account. Save it as troll.vbs in notepad and just throw it in startup.

CreateObject("SAPI.SpVoice").Speak"Seven a.m., waking up in the morning Gotta be fresh, gotta go downstairs Gotta have my bowl, gotta have cereal Seein' everything, the time is goin' Tickin' on and on, everybody's rushin' Gotta get down to the bus stop Gotta catch my bus, I see my friends (My friends) Kickin' in the front seat Sittin' in the back seat Gotta make my mind up Which seat can I take? It's Friday, Friday Gotta get down on Friday Everybody's lookin' forward to the weekend, weekend Friday, Friday Gettin' down on Friday Everybody's lookin' forward to the weekend Partyin', partyin' (Yeah) Partyin', partyin' (Yeah) Fun, fun, fun, fun Lookin' forward to the weekend 7:45, we're drivin' on the highway Cruisin' so fast, I want time to fly Fun, fun, think about fun You know what it is I got this, you got this My friend is by my right, ay I got this, you got this Now you know it Kickin' in the front seat Sittin' in the back seat Gotta make my mind up Which seat can I take? It's Friday, Friday Gotta get down on Friday Everybody's lookin' forward to the weekend, weekend Friday, Friday Gettin' down on Friday Everybody's lookin' forward to the weekend Partyin', partyin' (Yeah) Partyin', partyin' (Yeah) Fun, fun, fun, fun Lookin' forward to the weekend Yesterday was Thursday, Thursday Today i-is Friday, Friday (Partyin') We-we-we so excited We so excited We gonna have a ball today Tomorrow is Saturday And Sunday comes after ... wards I don't want this weekend to end R-B, Rebecca Black So chillin' in the front seat (In the front seat) In the back seat (In the back seat) I'm drivin', cruisin' (Yeah, yeah) Fast lanes, switchin' lanes Wit' a car up on my side (Woo!) (C'mon) Passin' by is a school bus in front of me Makes tick tock, tick tock, wanna scream Check my time, it's Friday, it's a weekend We gonna have fun, c'mon, c'mon, y'all It's Friday, Friday Gotta get down on Friday Everybody's lookin' forward to the weekend, weekend Friday, Friday Gettin' down on Friday Everybody's lookin' forward to the weekend Partyin', partyin' (Yeah) Partyin', partyin' (Yeah) Fun, fun, fun, fun Lookin' forward to the weekend It's Friday, Friday Gotta get down on Friday Everybody's lookin' forward to the weekend, weekend Friday, Friday Gettin' down on Friday Everybody's lookin' forward to the weekend Partyin', partyin' (Yeah) Partyin', partyin' (Yeah) Fun, fun, fun, fun Lookin' forward to the weekend" 

There are 10 types of people in this world, those who can read binary and those who can't.

There are 10 types of people in this world, those who can read hexadecimal and F the rest.

~Fletch

Link to post
Share on other sites

wow, this is all confusing? is it hard to learn from scratch this coding? what are you guys even using?..which code?


i7 5960X OC 4.40Ghz II GTX 1080 Asus Stryx II X99S Gaming 7 MSI II 16GB Vengence DDR4 II 250GB Samsung 850 II 3x 1 TB HDD WD II 

Designer by Heart, Gamer by Blood

Send me a PM if you want a custom Profile Pic or Background!  --

If you like what I made you , share it with everyone In this thread Here!

Link to post
Share on other sites

wow, this is all confusing? is it hard to learn from scratch this coding? what are you guys even using?..which code?

 

Plenty of tutorials online if you just want to start...

 

There are a lot of visual basic and java scripts on this page...

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

Buy VPN

×