Topic: Java Code Repository

Offline Bell

  • Addicted
  • Bell is on the verge of being accepted.Bell is on the verge of being accepted.Bell is on the verge of being accepted.Bell is on the verge of being accepted.Bell is on the verge of being accepted.
  • Posts: 4,263
A major part of the project i'm working on involves this awesome scraper thing I made that rips a large data set from a government website reasonably fast.
I was setting up a cron job to automatically run the scraper every night at 9pm but I made an oopsy.

* 21 * * * /var/data/scraper/perform_scrape > /var/data/scraper/allout.txt 2>&1

So at 9pm that night I was simulantously drinking wine at a friends birthday dinner at a nice resturant and beginning a 12 hour long 'cyber-attack' on the georgian government.
So I'm pretty much James Bond.
Last Edit: March 07, 2013, 09:08:00 pm by Bell

Reply #75 Posted: March 07, 2013, 08:57:38 pm

Offline Tiwaking!

  • Hero Member
  • Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!
  • Posts: 12,583
Quote from: Bell;1520059
So I'm pretty much James Bond.
It is true.

You are exactly like Timothy Dalton
edit: It is common knowledge that you can insert a collection directly into a HashSet or ArrayList. However: You can convert an Array into list on the fly and add it
Code: [Select]
String[]effects={"range","duration","attack","defence"};
String[]jrange={"tori","inu","nezumi"};
String[]jdef={"hebi","ii"};
String[]jatk={"tora","uma","saru"};
String[]jtime={"ushi","tatsu","u"};
ArrayList<HashSet<String>>sets=new ArrayList<HashSet<String>>();
sets.add(new HashSet<String>(Arrays.asList(jrange)));
sets.add(new HashSet<String>(Arrays.asList(jtime)));
sets.add(new HashSet<String>(Arrays.asList(jatk)));
sets.add(new HashSet<String>(Arrays.asList(jdef)));
HashMap<String,HashSet<String>>map=new HashMap<String,HashSet<String>>();
for(int i=0;i<effects.length;i++){
map.put(effects[i],sets.get(i));
}
However: What you CANNOT do is the following
Code: [Select]
ArrayList>sets=new ArrayList>(new HashSet[]{
new HashSet(Arrays.asList(jrange)),
new HashSet(Arrays.asList(jtime)),
new HashSet(Arrays.asList(jatk)),
new HashSet(Arrays.asList(jdef))
});
This leads to a Generic Array Creation error on compile. There is no way to circumvent this. Just be aware that it exists
Last Edit: March 17, 2013, 12:03:17 pm by Tiwaking!

Reply #76 Posted: March 07, 2013, 09:32:18 pm
I am now banned from GetSome

Offline Pyromanik

  • Hero Member
  • Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!
  • Posts: 28,834
mod_slotlimit

Reply #77 Posted: March 07, 2013, 10:38:28 pm
Everyone needs more Bruce Campbell.

Offline Tiwaking!

  • Hero Member
  • Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!
  • Posts: 12,583
Although there is no documented way to kill a thread, an undocumented feature of Java is if you set a thread to null then memory allocation is instantly free for use by the program and does not require the Garbage Collector call

Please be aware that there is no way to 'restart' a thread in Java
I didn't think such thing as a java enthusiast existed.
Someone needs to learn the 13 Programmer Personality Types methinks
http://www.javaworld.com/article/2078524/mobile-java/programmer-personality-types--13-profiles-in-code.html

My type is number 9: The True Believer
Quote
Programming personality type No. 9: The True Believer


Did you know that the best way to run Ruby is with Java? The Java devotees will tell you this in case you're thinking. The C lovers know that it would run faster than a Ferrari if someone would rewrite it in C because that's the only way to "get close to the metal."

It usually seems moderately funny to set up a lunch with a Python lover and C devotee and watch them snipe at each other for an hour.

Car: Anything with a sticker showing Calvin peeing on the competition

Relationship status: Married to the one who should have led the homecoming parade

Household chore: Putting up flags for holidays

Role model: Richard Stallman or Steve Jobs or ....

Pet: "He won 'Best in Show' in 2009 and 2010."

Favorite programming construct: Sit down first and ask

Drink: It's tattooed on their arm

Reply #78 Posted: July 05, 2014, 10:41:50 am
I am now banned from GetSome

Offline Pyromanik

  • Hero Member
  • Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!
  • Posts: 28,834
I'd like to say I too am also a #9... but realistically I'll have to say I'm probably a Duct taper.
I just reimplemented that heap of shit that was so popular because everyone on the internet is so damn retarded: code igniter.
In SilverStripe. Because I want to actually have classes I can fucking INHERIT from. Y'know... that pretty much the entire point of them. Oh and (easily) have more than one instance of. That isn't a fucking pseudo global variable.

... But I coudln't be fucked rewriting the entire legacy app. So I wrote a translation proxy. It seemed easier. And now I can use a proper fucking view layer.

And I did work on an N64 emulator for a bit once...
Because C is the truth of the world.
Last Edit: July 08, 2014, 10:48:54 am by Pyromanik

Reply #79 Posted: July 08, 2014, 10:45:00 am
Everyone needs more Bruce Campbell.

Offline Tiwaking!

  • Hero Member
  • Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!
  • Posts: 12,583
The \n function in Java no longer works as a universal new line character.
Use one of the following:
String.format("%n")
System.getProperty("line.separator")

System.getProperty is universal
Thank you

Reply #80 Posted: September 26, 2014, 11:20:55 pm
I am now banned from GetSome

Offline Xenolightning

  • Moderator
  • Xenolightning is awe-inspiring!Xenolightning is awe-inspiring!Xenolightning is awe-inspiring!Xenolightning is awe-inspiring!Xenolightning is awe-inspiring!Xenolightning is awe-inspiring!Xenolightning is awe-inspiring!Xenolightning is awe-inspiring!Xenolightning is awe-inspiring!Xenolightning is awe-inspiring!Xenolightning is awe-inspiring!Xenolightning is awe-inspiring!
  • Posts: 3,485
The \n function in Java no longer works as a universal new line character.
Use one of the following:
String.format("%n")
System.getProperty("line.separator")

System.getProperty is universal
Thank you
What an awful change... That's going to require massive change.

And surely they could've at least made getting the new character easier. Say.... Environment.NewLine

Reply #81 Posted: September 27, 2014, 02:47:21 pm
-= Sad pug is sad =-

Offline Tiwaking!

  • Hero Member
  • Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!
  • Posts: 12,583
The \n function in Java no longer works as a universal new line character.
Thank you
What an awful change... That's going to require massive change.

And surely they could've at least made getting the new character easier. Say.... Environment.NewLine
The \n function works, it just does not seem to work when you try saving to a text file.

I have no idea why. For example:
Code: [Select]
Absolute monarchy\nA form of government where the monarch rules unhindered, i.e., without any laws, constitution, or legally organized oposition.Is being saved as
Code: [Select]
Absolute monarchyA form of government where the monarch rules unhindered, i.e., without any laws, constitution, or legally organized oposition.This is happens when you use the file writer e.g
fileWriter.write("Absolute monarchy\nA form of government where the monarch rules unhindered, i.e., without any laws, constitution, or legally organized oposition.");

Reply #82 Posted: September 27, 2014, 04:26:39 pm
I am now banned from GetSome

Offline Lias

  • Administrator
  • Lias is awe-inspiring!Lias is awe-inspiring!Lias is awe-inspiring!Lias is awe-inspiring!Lias is awe-inspiring!Lias is awe-inspiring!Lias is awe-inspiring!Lias is awe-inspiring!Lias is awe-inspiring!Lias is awe-inspiring!Lias is awe-inspiring!Lias is awe-inspiring!
  • Posts: 3,975
The \n function in Java no longer works as a universal new line character.
Thank you
What an awful change... That's going to require massive change.

And surely they could've at least made getting the new character easier. Say.... Environment.NewLine
The \n function works, it just does not seem to work when you try saving to a text file.

I have no idea why. For example:
Code: [Select]
Absolute monarchy\nA form of government where the monarch rules unhindered, i.e., without any laws, constitution, or legally organized oposition.Is being saved as
Code: [Select]
Absolute monarchyA form of government where the monarch rules unhindered, i.e., without any laws, constitution, or legally organized oposition.This is happens when you use the file writer e.g
fileWriter.write("Absolute monarchy\nA form of government where the monarch rules unhindered, i.e., without any laws, constitution, or legally organized oposition.");

You probably need to escape it somehow?

Reply #83 Posted: September 30, 2014, 06:45:44 pm

Offline Xenolightning

  • Moderator
  • Xenolightning is awe-inspiring!Xenolightning is awe-inspiring!Xenolightning is awe-inspiring!Xenolightning is awe-inspiring!Xenolightning is awe-inspiring!Xenolightning is awe-inspiring!Xenolightning is awe-inspiring!Xenolightning is awe-inspiring!Xenolightning is awe-inspiring!Xenolightning is awe-inspiring!Xenolightning is awe-inspiring!Xenolightning is awe-inspiring!
  • Posts: 3,485
You probably need to escape it somehow?
The backslash is escaping it. '\n' is a line feed, or more commonly "new line"

The whole thing looks like a bit of balls up. Back when I did Java \n worked fine for files. I used \r\n for "safety", but meh.

Out of interest what OS were you on? Should also try running the same code against an older VM see when they "broke" it.

Also Tiwa, this is why you should most definitely move to C# :P
Last Edit: September 30, 2014, 08:27:59 pm by Xenolightning

Reply #84 Posted: September 30, 2014, 08:23:06 pm
-= Sad pug is sad =-

Offline Tiwaking!

  • Hero Member
  • Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!
  • Posts: 12,583
You probably need to escape it somehow?
The backslash is escaping it. '\n' is a line feed, or more commonly "new line"

The whole thing looks like a bit of balls up. Back when I did Java \n worked fine for files. I used \r\n for "safety", but meh.

Out of interest what OS were you on? Should also try running the same code against an older VM see when they "broke" it.

Also Tiwa, this is why you should most definitely move to C# :P
I never use \n. I was running a test on a file that listed government types to see if I could convert it to a "Government.name\nGovernment.text" but the text file came out all wrong.

I've attached the government text file if anyone wants it. They're all the real world government systems. line.substring(0,line.indexOf(" - ")) works fine to get the name. Of course you should save the index of line.indexOf but I shouldnt have to tell you such things.

OS: Windows XP, also affects Windows Vista and Windows 7 and Windows 8.

It really isnt a big deal. I usually use an sql database instead of text files

Reply #85 Posted: September 30, 2014, 09:26:45 pm
I am now banned from GetSome

Offline Lias

  • Administrator
  • Lias is awe-inspiring!Lias is awe-inspiring!Lias is awe-inspiring!Lias is awe-inspiring!Lias is awe-inspiring!Lias is awe-inspiring!Lias is awe-inspiring!Lias is awe-inspiring!Lias is awe-inspiring!Lias is awe-inspiring!Lias is awe-inspiring!Lias is awe-inspiring!
  • Posts: 3,975
The backslash is escaping it. '\n' is a line feed, or more commonly "new line"

I know what a newline is Xeno.. I was troubleshooting PC's when you were still in your dads ballbag  ;D I'm actually old enough to remember using dot matrix and line printers where these sort of things were quite relevant :-P

What I mean is that the \n is clearly being discarded/ignore by the filewriter.write. If the output Tiwa posted is accurate,it's not processing it, or passing it through, it's simply ignoring it. I don't Java,but that suggests to me that somehow it needs to be escaped an additional degree so that whatever logic in the filewriter.write statement is formatting it, doesn't interpret it and format it.

Does that make sense?


Reply #86 Posted: October 01, 2014, 07:40:59 am

Offline Tiwaking!

  • Hero Member
  • Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!Tiwaking! is awe-inspiring!
  • Posts: 12,583
What I mean is that the \n is clearly being discarded/ignore by the filewriter.write. If the output Tiwa posted is accurate,it's not processing it, or passing it through, it's simply ignoring it. I don't Java,but that suggests to me that somehow it needs to be escaped an additional degree so that whatever logic in the filewriter.write statement is formatting it, doesn't interpret it and format it.

Does that make sense?
I think I found out what the problem is. Those mofo's at Oracle added a new Package which includes new Charsets. The \n encoding is no longer default and I cant seem to load that java.nio.charset package at all. The obvious solution is to use a delimiter which is not a newline, which is what I do anyway. I am pretty sure decisions like these are what caused James Gosling to stop being a consultant for Java

Reply #87 Posted: October 01, 2014, 08:22:13 am
I am now banned from GetSome

Offline Xenolightning

  • Moderator
  • Xenolightning is awe-inspiring!Xenolightning is awe-inspiring!Xenolightning is awe-inspiring!Xenolightning is awe-inspiring!Xenolightning is awe-inspiring!Xenolightning is awe-inspiring!Xenolightning is awe-inspiring!Xenolightning is awe-inspiring!Xenolightning is awe-inspiring!Xenolightning is awe-inspiring!Xenolightning is awe-inspiring!Xenolightning is awe-inspiring!
  • Posts: 3,485
The backslash is escaping it. '\n' is a line feed, or more commonly "new line"

I know what a newline is Xeno.. I was troubleshooting PC's when you were still in your dads ballbag  ;D I'm actually old enough to remember using dot matrix and line printers where these sort of things were quite relevant :-P

What I mean is that the \n is clearly being discarded/ignore by the filewriter.write. If the output Tiwa posted is accurate,it's not processing it, or passing it through, it's simply ignoring it. I don't Java,but that suggests to me that somehow it needs to be escaped an additional degree so that whatever logic in the filewriter.write statement is formatting it, doesn't interpret it and format it.

Does that make sense?
No, no. I think you misunderstood. \n represents a "new line" and the backslash is the escape character.





 ;D 8) ;D 8)

Reply #88 Posted: October 01, 2014, 11:36:35 am
-= Sad pug is sad =-

Offline Xsannz

  • Addicted
  • Xsannz is awe-inspiring!Xsannz is awe-inspiring!Xsannz is awe-inspiring!Xsannz is awe-inspiring!Xsannz is awe-inspiring!Xsannz is awe-inspiring!Xsannz is awe-inspiring!Xsannz is awe-inspiring!Xsannz is awe-inspiring!Xsannz is awe-inspiring!Xsannz is awe-inspiring!Xsannz is awe-inspiring!
  • Posts: 5,412
this is why i hate java, even worse when i am doing c# dev at work but then the have to consult on another team that uses a JS runtime template processor that is used to inject values into sql templates and then that is running on a JVM.

its like a clusterfuck of ooops

Reply #89 Posted: October 02, 2014, 08:22:58 am

Codex

  • Guest
I'm so sorry for those of you that have to look at Java

I send my condolences

Reply #90 Posted: October 06, 2014, 12:08:41 pm

Offline Apostrophe Spacemonkey

  • Fuck this title in particular.

  • Apostrophe Spacemonkey is awe-inspiring!Apostrophe Spacemonkey is awe-inspiring!Apostrophe Spacemonkey is awe-inspiring!Apostrophe Spacemonkey is awe-inspiring!Apostrophe Spacemonkey is awe-inspiring!Apostrophe Spacemonkey is awe-inspiring!Apostrophe Spacemonkey is awe-inspiring!Apostrophe Spacemonkey is awe-inspiring!Apostrophe Spacemonkey is awe-inspiring!Apostrophe Spacemonkey is awe-inspiring!Apostrophe Spacemonkey is awe-inspiring!Apostrophe Spacemonkey is awe-inspiring!
  • Posts: 19,050

Reply #91 Posted: October 06, 2014, 03:07:15 pm

Offline Lias

  • Administrator
  • Lias is awe-inspiring!Lias is awe-inspiring!Lias is awe-inspiring!Lias is awe-inspiring!Lias is awe-inspiring!Lias is awe-inspiring!Lias is awe-inspiring!Lias is awe-inspiring!Lias is awe-inspiring!Lias is awe-inspiring!Lias is awe-inspiring!Lias is awe-inspiring!
  • Posts: 3,975
I don't Java,but that suggests to me that somehow it needs to be escaped an additional degree so that whatever logic in the filewriter.write statement is formatting it, doesn't interpret it and format it.
No, no. I think you misunderstood. \n represents a "new line" and the backslash is the escape character.
[/quote]

You know exactly what I mean xeno :-P

I know it's an escape character hence saying it needs to be escaped an additional degree.. the escape character needs to be escaped via (whatever java does to escape such things) so that it's parsed through rather than being escaped, interpreted and apparently ignored by the logic in the filewriter.write thing.

Like in Bash you'd either enclose it in '\n' or double escape it like \\n (or perhaps the n might need escaping too like \\\n I'd have to check)


Reply #92 Posted: October 06, 2014, 06:53:07 pm

Offline Xsannz

  • Addicted
  • Xsannz is awe-inspiring!Xsannz is awe-inspiring!Xsannz is awe-inspiring!Xsannz is awe-inspiring!Xsannz is awe-inspiring!Xsannz is awe-inspiring!Xsannz is awe-inspiring!Xsannz is awe-inspiring!Xsannz is awe-inspiring!Xsannz is awe-inspiring!Xsannz is awe-inspiring!Xsannz is awe-inspiring!
  • Posts: 5,412
Lias .. you should know you have to Bash before they escape not after.

Reply #93 Posted: October 08, 2014, 09:54:06 am