Page 8 of 9

Re: The programmer's corner.

Posted: Fri Feb 05, 2016 1:21 pm
by Peter
Maybe you can draw over the images that is possible in some cases, bur I'm not sure. I would cut the images up in a ton of smaller ones (google maps does this).
Technically you could load smaller images into google maps (web version at least) and then use google maps to show polylines on this map.

Re: The programmer's corner.

Posted: Sat Feb 06, 2016 3:22 am
by iEatGroceries

Code: Select all

1.Button Maps_Button = (Button)findViewById(R.id.Maps_Button);
2.Maps_Button.setOnClickListener(new View.OnClickListener(){
3.         public void onClick(View v) {
4.                 //i have some code here
5.          }
6.});
I am getting a NullPointerException at the setOnClickListener part i.e Line 2. The Android Studio shows no error when I type the code, the id of the button is correct and it stops during runtime. I have also imported the button widget. Even the XML file is proper. What's wrong here?
I checked for solutions online but all the links say that there wasn't a declaration for the button. But I just declared it on Line 1.
Pls Help me

Re: The programmer's corner.

Posted: Thu Feb 11, 2016 10:16 pm
by Peter
Moved anonymous v2's module code to it's own GIT repository.

https://git.pselten.info/peter/Anonymous


TO DO list:
https://git.pselten.info/peter/Anonymous/wiki/Todo

Re: The programmer's corner.

Posted: Wed Mar 16, 2016 1:49 pm
by Peter
Few bits of CUDA code.

Calculate the reverse complement strand:

Code: Select all

#include <stdio.h>

__global__ void do_reversecomplement(char *nucleotides, char *nucleotides_return){	
	int tid = threadIdx.x;
	int instances = (int)sizeof(nucleotides)/2;

	switch(nucleotides[tid]) {
		case 'A':
			nucleotides_return[instances-tid-1] = 'T';
			break;
		case 'T':
			nucleotides_return[instances-tid-1] = 'A';
			break;
		case 'C':
			nucleotides_return[instances-tid-1] = 'G';
			break;
		case 'G':
			nucleotides_return[instances-tid-1] = 'C';
			break;
	}
}

int main(void){
	char nucleotides1[4] = {'A','T','G','C'};
	int instances = (int)sizeof(nucleotides1);
	int size = instances * sizeof(char);
	char *nucleotides_return;
	char *d_nucleotides_return;
	char *d_nucleotides;

	//Allocate memory.
	nucleotides_return = (char *)malloc(size);
	cudaMalloc((void **)&d_nucleotides, size);
	cudaMalloc((void **)&d_nucleotides_return, size);
	
	//Copy nucleotides1 to d_nucleotides.
	cudaMemcpy(d_nucleotides, nucleotides1, size, cudaMemcpyHostToDevice);
	cudaMemcpy(d_nucleotides_return, nucleotides_return, size, cudaMemcpyHostToDevice);

	//Execute on 1 block with the amount of instances the array is.
	do_reversecomplement<<<1,instances>>>(d_nucleotides, d_nucleotides_return);
	
	//Copy d_nucleotides_return to nucleotides_return
	cudaMemcpy(nucleotides_return, d_nucleotides_return, size, cudaMemcpyDeviceToHost);

	//Display results
	printf("%s\n", nucleotides_return);

	// Cleanup
	cudaFree(d_nucleotides);
	cudaFree(d_nucleotides_return);
	free(nucleotides_return);
}
Simple Hello World in CUDA

Code: Select all

#include "cuPrintf.cu"
#include <stdio.h>

__global__ void device_greetings(void){	
	int tid = threadIdx.x;
	int bid = blockIdx.x;

	cuPrintf("Hello, world from the device!\n");
}

int main(void){
	// greet from the host
	printf("Hello, world from the host!\n");

	// initialize cuPrintf
	cudaPrintfInit();

	// launch a kernel with one block and one thread per block
	device_greetings<<<10,10>>>();

	// display the device's greeting
	cudaPrintfDisplay();

	// clean up after cuPrintf
	cudaPrintfEnd();

	return 0;
}

Simple math in CUDA, where 2 arrays are added to each other.

Code: Select all

#include <stdio.h>

__global__ void do_addition(int *num1, int *num2){	
	int tid = threadIdx.x;
	num1[tid] = num1[tid]+num2[tid];
}

int main(void){
	int array1[10] = {0,1,2,3,4,5,6,7,8,9};
	int array2[10] = {0,1,4,9,16,25,36,49,64,81};
	int *d_array1;
	int *d_array2;
	int *h_results;
	int instances = sizeof(array1)/sizeof(int);
	int size = instances * sizeof(int);

	//Allocate memory.
	cudaMalloc((void **)&d_array1, size);
	cudaMalloc((void **)&d_array2, size);
	h_results = (int *)malloc(size);

	//Copy array1 & array2 to d_array1 and d_array2.
	cudaMemcpy(d_array1, array1, size, cudaMemcpyHostToDevice);
	cudaMemcpy(d_array2, array2, size, cudaMemcpyHostToDevice);

	//Execute on 1 block with the amount of instances the array is.
	do_addition<<<1,instances>>>(d_array1,d_array2);
	
	//Copy d_array1 to h_results
	cudaMemcpy(h_results, d_array1, size, cudaMemcpyDeviceToHost);

	//Display results
	for (int i=0; i<instances; i++) printf("%d %d\n", i, h_results[i]);

 	// Cleanup
	cudaFree(d_array1);
	cudaFree(d_array2);
	free(h_results);

	return 0;
}

Re: The programmer's corner.

Posted: Wed Mar 16, 2016 7:51 pm
by wasay0029
Nice, try mentioning the language also always, it'll be helpful for me and others who aren't good at this.

Re: The programmer's corner.

Posted: Wed Mar 16, 2016 9:13 pm
by Peter
wasay0029 wrote:Nice, try mentioning the language also always, it'll be helpful for me and others who aren't good at this.
I said it's CUDA :P

Re: The programmer's corner.

Posted: Thu Mar 17, 2016 12:40 am
by wasay0029
I'm stupid, nevermind

Re: The programmer's corner.

Posted: Thu Sep 08, 2016 6:40 pm
by Fuet
Changes current weather ID to number of ammo remaining in clip.

https://www.youtube.com/watch?v=MitvBH7a1do

I'm actually going to share the complete source code for this, it is extraordinarily lengthy, so be prepared.

Ready?
Spoiler!

Code: Select all

mov [00C81320], edx

Re: The programmer's corner.

Posted: Thu Sep 08, 2016 7:11 pm
by Ragna
That looks awesome :O
and that code,too long man..

Re: The programmer's corner.

Posted: Thu Sep 08, 2016 8:42 pm
by Aztec.is back
Wow, Good one fuet! (that's why you never lose a race? Hmm) :D
it took me 1 hour ΒΌ to read that code