Half and half
Member
What's wrong with databases? I love databases!
I'm teasing
Though I must admit I'm quickly lost when reading job descriptions for database programmers.
What's wrong with databases? I love databases!
I'd actually suggest libgdx over slick2d.
range(8) * 2
[x for x in range(8) for y in range(2)]
ok questions with list comprehension in python. this from the coursera class
creating a list with 16 elements and all elements are from 0 to 7 with each appearing twice
numlist =[ i for i in range(16] gives 0 to 15. I need 0 to 7 twice.
for i in range(2):
for j in range(8):
numlist.append(j)
numlist == [0, 1, 2, 3, 4, 5, 6, 7]
numlist.extend(numlist)
numlist == [0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7]
numlist = numlist * 10
One thing you can try is to write a loop within a loop, which if you've done before is fairly trivial. Write an outer for loop that goes 2 times, and the inner for loop which will be used to populate the list, eg:
Code:for i in range(2): for j in range(8): numlist.append(j)
An alternative, more Pythonish way:
If you already have the list assigned with the values 0 to 7, you can then call the extend method of the list to add those values in a second time. Like so:
Code:numlist == [0, 1, 2, 3, 4, 5, 6, 7] numlist.extend(numlist) numlist == [0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7]
Alternatively you can use the * operator if you need to copy the values some n number of times, and reassign the list.
Will reassign numlist the initial values 10 times. So if it contains 0-7 it will now have 10 sets of that, for 70 total values.Code:numlist = numlist * 10
import random
numlist = [ i for i in range (8)]
numlist = numlist * 2
num_list = random.shuffle(numlist)
print(num_list)
thanks
for the following code I am getting none as the output. Is there way to look at the shuffled list ?
Code:import random numlist = [ i for i in range (8)] numlist = numlist * 2 num_list = random.shuffle(numlist) print(num_list)
EDIT : print (numlist) displays it.
Spent the weekend working on a Django project for school was interesting and educational since I haven't used Python or Django before. So I was learning a new language and a framework at the same time.
One thing I wish I used was a proper Python IDE instead of doing everything in ST2/Vim. Outside of spelling mistakes, my biggest problem was the mysterious indentation syntax errors which I could never figure out what caused them. All what I did to fix them was cut and paste the block of code again, or just rewrite it again in Vim.
I think every C programmer should learn JavaScript and Ruby just to experience the stark existential horror of how modern languages have evolved both syntactically and in their execution environment. Or, as a friend puts it, "if you love string concatenation, you'll love JavaScript."
When I learned how the automatic dispatch system for Rails table lookups worked (override the missing method handler, perform heuristics on the method name, etc.), I was truly amazed and terrified.
Broadly, I use a 2-step process.When you guys are given a program, how do you go on about designing it and implementing it?
Do you go straight to your IDE or whatever use to make it? Do you write a lot of stuff down on paper first and try to work it out? What do you guys do?
I usually think about it in my head for a while and then go for trial and error in Visual Studio, but this method kind of sucks. I need to find a better way to working on programs.
What kind of keyboards do you guys use for programming? I've got a Logitech one, but I had a play around with a mechanical keyboard and found it fun to use, but not sure if the benefits are worth the price of admission.
This + a standing desk is god like.
Does anyone know how to check whether a window has focus in Swing? Preferably Scala Swing but Java would be fine. The basic structure of my program is that there's a main window and theoretically an infinite number of sub-windows. If someone clicks a button on the main window, I only want it to effect the last sub-window that was selected.
I can think of a few ways I could easily hack out a solution but I hate hacks. Though I imagine I've been a bit daft and completely overlooked something.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
// based on MSDN example code
namespace Task1
{
class Program
{
//public System.IO.StreamWriter log_file = new StreamWriter("C:\\Users\\Warpony\\Desktop\\App Dev 2\\App 1\\logfile.csv");
static void Main(string[] args)
{
try
{ // check for file existance and creates the files if they do not exist
if (!File.Exists("C:\\Users\\Warpony\\Desktop\\App Dev 2\\App 1\\log_file.csv"))
{
File.Create("C:\\Users\\Warpony\\Desktop\\App Dev 2\\App 1\\log_file.csv");
}
}
catch { Console.WriteLine("Cannot Create file!"); }
string path = "C:\\Users\\Warpony\\Desktop\\App Dev 2\\App 1\\Storage\\"; //the path to the folder that will be used
System.IO.StreamWriter log_file = new StreamWriter("C:\\Users\\Warpony\\Desktop\\App Dev 2\\App 1\\log_file.csv");
System.IO.StreamReader temp = new StreamReader("C:\\Users\\Warpony\\Desktop\\App Dev 2\\App 1\\temp.csv");
if (!Directory.Exists(path)) // checks to see if the specified path exists
{
Console.WriteLine("watch folder not found, creating watch folder...\n");
Directory.CreateDirectory(path); // creates the folder
}
Console.Out.WriteLine("Filesystem watcher started...\nWatching " + path + "\n\nPress q to quit");
FileSystemWatcher FileSystem = new FileSystemWatcher(path);
FileSystem.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName; //sets up the file data to use for detecting changes
FileSystem.Filter = "*.*"; //filter uses a wildcard for any changes to any file
FileSystem.Changed += new FileSystemEventHandler(Changed); // event handler some times fires twice
FileSystem.Created += new FileSystemEventHandler(Changed);
FileSystem.Deleted += new FileSystemEventHandler(Changed);
FileSystem.Renamed += new RenamedEventHandler(Renamed);
FileSystem.EnableRaisingEvents = true; // allows the system to automatically notify about events
do
{
string line = temp.ReadLine();
log_file.WriteLine(line + ",");
}
while (Console.Read() != 'q');
}
private static void Changed(object source, FileSystemEventArgs file)
{
Console.WriteLine("File: " + file.FullPath + " " + file.ChangeType + " " + DateTime.UtcNow); // gives full file path, change type and the time that it occured at
System.IO.StreamWriter log_file = new StreamWriter("C:\\Users\\Warpony\\Desktop\\App Dev 2\\App 1\\temp.csv");
log_file.WriteLine("File: " +file.FullPath + " " + file.ChangeType + " " + DateTime.UtcNow + ",");
log_file.Close();
}
private static void Renamed(object source, RenamedEventArgs file)
{
Console.WriteLine("File: " + file.OldFullPath + "\n" + file.ChangeType + " to " + file.FullPath + " " + DateTime.UtcNow);// gives old and new full file path and time it was renamed
}
}
}
Haha holy shit, this thing looks like a beast. What makes it so much better than a standard keyboard? Just ergonomics?
I'm trying to set up a File system watcher that monitors a folder for any changes to the contents and output the changes to a csv file. I've used the FileSystemWatcher class example on MSDN as a start but can't get the program to write to the csv file. I tried something crazy involving two separate files but that didn't work very well.
Sorry for the crappy code, been working all day and have just commented out something when I was messing about instead of deleting them
...
private static void Changed(object source, FileSystemEventArgs file)
{
Console.WriteLine("File: " + file.FullPath + " " + file.ChangeType + " " + DateTime.UtcNow); // gives full file path, change type and the time that it occured at
using (var log_file = new StreamWriter(@"C:\Users\Mike\Dropbox\log.csv", true))
{
log_file.WriteLine("File: " + file.FullPath + " " + file.ChangeType + " " + DateTime.UtcNow + ",");
}
}
private static void Renamed(object source, RenamedEventArgs file)
{
Console.WriteLine("File: " + file.OldFullPath + "\n" + file.ChangeType + " to " + file.FullPath + " " + DateTime.UtcNow);// gives old and new full file path and time it was renamed
}
private static void Main(string[] args)
{
string path = @"C:\Users\Mike\Desktop";
var watcher = new FileSystemWatcher(path);
watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName |
NotifyFilters.DirectoryName; //sets up the file data to use for detecting changes
watcher.Filter = "*.*"; //filter uses a wildcard for any changes to any file
watcher.Changed += new FileSystemEventHandler(Changed); // event handler some times fires twice
watcher.Created += new FileSystemEventHandler(Changed);
watcher.Deleted += new FileSystemEventHandler(Changed);
watcher.Renamed += new RenamedEventHandler(Renamed);
watcher.EnableRaisingEvents = true;
while (true)
{
Thread.Sleep(1000);
}
}
Really though you'll find Java very easy to pick up coming from C++ once you get used to the new everywhere. Oh god so much new.
int somefunc(int a, int b, int c)
{
//code
}
where
int a is in %rdi
int b is in %rsi
int c is in %rdx
For Vim, this should be handy: http://vim.wikia.com/wiki/Highlight_unwanted_spaces
Quick question, when dealing with x86-64 assembly:
I have to write a stub function which doesn't call anything. 3 integers are passes as parameters (int a, int b, int c). Even though they are really 32bit, or a long in asm terms, I can access them via the 64bit registers to which they are assigned, correct?
I.E:
Code:int somefunc(int a, int b, int c) { //code } where int a is in %rdi int b is in %rsi int c is in %rdx
(I don't have to write anything besides this small stub accessing the parameters and working with them. It's a handwritten assignment, so I think the main point is to demonstrate the lack of need to use the stack and its offsets and use the far faster registers instead...)
Thanks for the link.
Just changed my settings for Vim so now everything becomes spaces and not tabs. Should fix the problem when coding in with it, but I guess I should do the same to Sublime Text 2 cause when using it, I'm still getting weird syntax indentation errors.
Is it just me or are there no reflections yet? If so, I'd suggest you handle reflections before refraction. Also, you need to adjust your colour values there. It kinda looks like you just have ambient lighting in, but then you have a shade of specular in the center that makes me think otherwise.
Edit: NM, looks like that dim lighting IS your diffuse lighting and that you don't have any ambient (judging by your shadows).
Oh and my bad on the double post.
<button id="example">Example</button>
google.maps.event.addDomListener(document.getElementById('example'), 'click', someFunction);
//this gives me TypeError: a is null for some reason
function someFunction(){
// SOMETHING THAT CHANGES THE PANORAMA
}
I don't know anything about the google maps api but if you're getting a null value than that probably means that your "example" button is named incorrectly or something similar. Document.getElementById will give back a null if it can't locate the element specified.
This convenience method has a signature as shown below:
addDomListener(instance:Object, eventName:string, handler:Function)
where instance may be any DOM element supported by the browser, including:
Hierarchical members of the DOM such as window or document.body.myform
Named elements such as document.getElementById("foo")
so I got no idea why it can't find the said element. Weird.
The example from Google uses double quotes for document.getElementById("foo"), while you use single quotes document.getElementById('example'), maybe that makes any difference. The only thing that struck me, I don't know any JS.
I believe so. I know you can access them with the 32 bit register names even in 64 bit (edi, esi, edx).
I think for that one I had disabled reflections in order to lock down what was going wrong with my refraction. I have both now. Likewise with the ambient. And a fresnel term, and my local reflection is normalized but I'd kind of like to give up on specular coefficient and scale my reflection ray further off the glossiness of my surface. Ah well, after this semester's over I'll start working on some sort of GPU path tracer. I'm thinking CUDA but I don't know, I'll have to look into it.
Are you thinking of doing any of that realtime path tracing stuff on the gpu? That stuff is pretty inspiring.
I'm working on a standard take-forever ray tracer, but am going to generate the first hit on the gpu as a speed-up. Then the following rays will do their standard traces on the cpu.
I decided to switch to php and learn that. I have been reading there is the "right" way of learning it and the "wrong" way that makes you a bad php programmer. The more I search there is no consensus from people on what to do / what way / what to read to learn php the right way. Can anyone direct me in the right direction?
Thanks.![]()
By generic programming, you're referring to this right?Where can I read easy to understand basics about generic programming in c#? I have a rudimentary bubble sorter kind of running but it's not very pretty(for class)
Yes, I think soBy generic programming, you're referring to this right?
http://www.codeguru.com/csharp/.net/article.php/c19413/Introducing-NET-Generics.htm
http://msdn.microsoft.com/en-us/library/ms379564(VS.80).aspx
If you have any questions, or want some advice specific to your code, feel free to ask.
I usually have luck googling things like "python for java programmers" etc. I don't know any places specifically though.I've learned or at least been introduced to a lot of the basics in C++ and Java. Are there any good resources for not a fresh beginner, but by no means an expert to learn Python without wading through all the hand holding?
Something that mostly covers syntax, mechanics, and difference in Python, not necessarily what computer science is.