Hey, long time no write!
I've been busy working at developing www.olympian.mx and the recently-launched www.sharemybytes.com. Both are great examples of coding.
Olympian.mx was created using Django. Although it was my first time using the framework, I found it extremely easy and fast to use. Backend integration is seamless, although you do have to get used to working with versioned migrations and how to mange them in a production environment. One of the coolest things that 'came in the box' with Django was the admin site. This site contains an already built UI for people in the backoffice to work with and generate their analysis. No need to give them direct permission on the actual database.
The only letdown from Django was the frontend templates and lack of support or consideration for AJAX calls. although the DRY mentality is kept with the frontend, and there are ways to avoid writing every field in each form, I find that the templates are way too coupled with the backend. This is a problem because having a separate UI designer and frontend engineer working to develop the website, it creates a need for the FE to learn the templating system, which can slow down the development of the website.
Sharemybytes.com on the other hand was created solely by me. I used a plain old LAMP server to serve the website using PHP. After having developed websites in Django and Java it felt weird to use the same language to develop the backend code as well as the frontend one. It's like creating a website using JSPs for the backend too. The fun part about www.sharemybytes.com is the idea of creating a web file host with an unlimited capacity. The whole idea relies on living the storage to the user and using the server only as a bridge between the host and the client. Using AJAX leases I was able to pull and push files on demand without any user interaction. Very interesting project.
Finally I have been also writing on www.aboutworld.com. I still have only 6 posts which is frequency of about 1 post per month. However it has some 500 monthly views which is pretty good.
Mostrando entradas con la etiqueta Programming. Mostrar todas las entradas
Mostrando entradas con la etiqueta Programming. Mostrar todas las entradas
lunes, 1 de febrero de 2016
martes, 3 de marzo de 2015
Posting some cool sites I've been working on
Hey so I've been programming some webapps. I have been using my own home-cooked webapp framework, but will move maybe to struts for my next project. In the meantime I leave you these jewels:
www.apartmentsml.com
www.tm1consultant.com | www.tm1group.com
mindflow.hostzi.com
www.apartmentsml.com
www.tm1consultant.com | www.tm1group.com
mindflow.hostzi.com
viernes, 24 de octubre de 2014
Last Project Euler for 75
Problem 99 (Python ... painfully slow but easy to code):
maxn = 0;
ind = 1;
with open("base_exp.txt") as f:
for line in f:
base = int(line.split(",")[0]);
exp = int(line.split(",")[1]);
res = base ** exp;
if(res > maxn):
maxn = res
print ind
ind += 1;
maxn = 0;
ind = 1;
with open("base_exp.txt") as f:
for line in f:
base = int(line.split(",")[0]);
exp = int(line.split(",")[1]);
res = base ** exp;
if(res > maxn):
maxn = res
print ind
ind += 1;
Etiquetas:
algorithms,
code,
codigo,
csv,
dijkstra,
lenguajes de programacion,
matrices,
pe92,
Perl,
programacion,
Programming,
programming languages,
Project Euler
Project Euler 92 in Perl
Esp: Para no olvidar Perl decidi echarme el Project Euler 92 en Perl. Como en el problema solo puedes moverte hacia abajo o a la derecha, el codigo se vuelve mucho mas simple. De otra manera tendria que implementar Dijkstra en matrices en Perl (demasiado para una noche de ocio despues del trabajo...). Pero bueno aqui les dejo mi solucion:
Eng: Trying not to lose my working knowledge of Perl I decided to write this problem using it. The more general solution is where you can move up, down, left and right in which case you must use Dijkstra's algorithm using a matrix as the data structure. However for this particular problem you can only move down or right which makes it a lot easier. The algorithm just traverses the matrix in diagonal strips and adds its upper and left cell:
Eng: Trying not to lose my working knowledge of Perl I decided to write this problem using it. The more general solution is where you can move up, down, left and right in which case you must use Dijkstra's algorithm using a matrix as the data structure. However for this particular problem you can only move down or right which makes it a lot easier. The algorithm just traverses the matrix in diagonal strips and adds its upper and left cell:
use strict;
use warnings;
$| = 1; #turn autoflush on
use Text::CSV;
my @data; # 2D array for CSV data
my $file = 'matrix.txt';
my $csv = Text::CSV->new;
open my $fh, '<', $file or die "Could not open $file: $!";
while( my $row = $csv->getline( $fh ) ) {
print join(", ", @$row) ."\n";
#shift @$row; # throw away first value
push @data, $row;
}
my $w = scalar @{$data[0]};
for (my $slice = 0; $slice < 2 * $w - 1; ++$slice) {
my $z = $slice < $w ? 0 : $slice - $w + 1;
for (my $j = $z; $j <= $slice - $z; ++$j) {
my $x = $j;
my $y = $slice - $j;
my $val = $data[$x][$y];
if($x - 1 <= 0 && $y - 1 >= 0){
$val += ($data[$x-1][$y] > $data[$x][$y-1])?$data[$x][$y-1]:$data[$x-1][$y];
} else {
if($x - 1 >= 0){
$val += $data[$x-1][$y];
}
if($y - 1 >= 0){
$val += $data[$x][$y-1];
}
}
print "x: $x, y: $y, data: $data[$x][$y], val: $val\n";
$data[$x][$y] = $val;
}
}
for (my $i = 0; $i < $w; $i++){
for(my $j = 0; $j < $w; $j++){
print $data[$i][$j] ." ";
}
print "\n";
}
print "res: " . $data[$w-1][$w-1];
Etiquetas:
92,
algorithms,
code,
codigo,
csv,
dijkstra,
lenguajes de programacion,
matrices,
pe92,
Perl,
programacion,
Programming,
programming languages,
Project Euler
viernes, 22 de febrero de 2013
Javascript animation
Siguiendo el aprendizaje de js con typescript y html5 ahora les presento una animación hecha en javascript. Se trata de un simulador de "tiro libre" donde se encuentra numéricamente el mejor ángulo de disparo: CLICK AQUI PARA VER ANIMACIÓN
Etiquetas:
angulo,
angulodedisparo,
animación,
animation,
bestangle,
browser,
explorador,
física,
html5,
javascript,
programación,
Programming,
tirolibre,
typescript
jueves, 1 de diciembre de 2011
Rotate array k times in linear time
int gcd ( int a, int b )
{
int c;
while ( a != 0 ) {
c = a; a = b%a; b = c;
}
return b;
}
void shift(volatile int*arr, int len, int k){
int i,j,c;
int t1,t2;
printf("gcd:%d\n",gcd(len,k));
for(i=0;i<gcd(len,k);i++){
j=k+i;
if(j>=len)
j-=len;
t1 = arr[j];
arr[j]=arr[i];
while(j!=i){
j+=k;
if(j>=len)
j-=len;
t2 = arr[j];
arr[j]=t1;
t1=t2;
printf("j:%d\n",j);
for(c=0;c<len;c++)printf("%d,",arr[c]);
printf("\n");
}
printf("i:%d\n",i);
}
}
jueves, 28 de abril de 2011
Project Euler 61
Tengo que decir que me llevo un buen rato resolver éste. Al final mi solución tarda unos cuantos ms... Escribí mi propio método para permutar (lo cual SIEMPRE me había dado mucha flojera), y otros cuantos. Estuvo pesado pero lo saqué:
Triangle, square, pentagonal, hexagonal, heptagonal, and octagonal numbers are all figurate (polygonal) numbers and are generated by the following formulae:
Triangle P3,n=n(n+1)/2 1, 3, 6, 10, 15, ...
Square P4,n=n2 1, 4, 9, 16, 25, ...
Pentagonal P5,n=n(3n1)/2 1, 5, 12, 22, 35, ...
Hexagonal P6,n=n(2n1) 1, 6, 15, 28, 45, ...
Heptagonal P7,n=n(5n3)/2 1, 7, 18, 34, 55, ...
Octagonal P8,n=n(3n2) 1, 8, 21, 40, 65, ...
The ordered set of three 4-digit numbers: 8128, 2882, 8281, has three interesting properties.
The set is cyclic, in that the last two digits of each number is the first two digits of the next number (including the last number with the first).
Each polygonal type: triangle (P3,127=8128), square (P4,91=8281), and pentagonal (P5,44=2882), is represented by a different number in the set.
This is the only set of 4-digit numbers with this property.
Find the sum of the only ordered set of six cyclic 4-digit numbers for which each polygonal type: triangle, square, pentagonal, hexagonal, heptagonal, and octagonal, is represented by a different number in the set.
Approaches:
1.- Fuerza muy a lo bruta. Combinaciones de 2 en 1000 a 9999. Si tienen chance, seguir con tercer número etc. etc. Muy largo....
2.- Sacar la lista de todos los números poligonales, y hacer lo mismo que en el paso anterior: Funciona, aunque todavía se pueda mejorar mucho más, y con menos códgio:
Triangle, square, pentagonal, hexagonal, heptagonal, and octagonal numbers are all figurate (polygonal) numbers and are generated by the following formulae:
Triangle P3,n=n(n+1)/2 1, 3, 6, 10, 15, ...
Square P4,n=n2 1, 4, 9, 16, 25, ...
Pentagonal P5,n=n(3n1)/2 1, 5, 12, 22, 35, ...
Hexagonal P6,n=n(2n1) 1, 6, 15, 28, 45, ...
Heptagonal P7,n=n(5n3)/2 1, 7, 18, 34, 55, ...
Octagonal P8,n=n(3n2) 1, 8, 21, 40, 65, ...
The ordered set of three 4-digit numbers: 8128, 2882, 8281, has three interesting properties.
The set is cyclic, in that the last two digits of each number is the first two digits of the next number (including the last number with the first).
Each polygonal type: triangle (P3,127=8128), square (P4,91=8281), and pentagonal (P5,44=2882), is represented by a different number in the set.
This is the only set of 4-digit numbers with this property.
Find the sum of the only ordered set of six cyclic 4-digit numbers for which each polygonal type: triangle, square, pentagonal, hexagonal, heptagonal, and octagonal, is represented by a different number in the set.
Approaches:
1.- Fuerza muy a lo bruta. Combinaciones de 2 en 1000 a 9999. Si tienen chance, seguir con tercer número etc. etc. Muy largo....
2.- Sacar la lista de todos los números poligonales, y hacer lo mismo que en el paso anterior: Funciona, aunque todavía se pueda mejorar mucho más, y con menos códgio:
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
/**
*
* @author Andres
*/
public class pe61{
public static void main(String[] args) throws InterruptedException{
HashMap tups = new HashMap();
double a = 0.5;
double b = 0.5;
for (int j = 0; j < 6; j++){
int i = 0;
int k = (int)(a*i*i+b*i);
while(k<1000 data-blogger-escaped-br=""> i++;
k = (int)(a*i*i+b*i);
}
while(k<10000 data-blogger-escaped-br=""> tups.put(k,j);
i++;
k = (int)(a*i*i+b*i);
}
a+=0.5;
b-=0.5;
System.out.println("size: " + tups.size());
}
System.out.println(isSCycle(new int[]{3066,6655}));
for (Integer integer : tups.keySet()) {
findCycle(new int[]{integer},tups);
System.out.println(integer);
}
}
public static void findCycle(int[] in, HashMap list){
for (Integer integer : list.keySet()) {
boolean ret = false;
for(int c = 0 ; c < in.length;c++)
if(integer==in[c] || list.get(integer) == list.get(in[c]))
ret = true;
if(ret)
continue;
int[] arr = new int[in.length+1];
for (int j = 0; j < in.length; j++)
arr[j]=in[j];
arr[arr.length-1]=integer;
if(arr.length==6 && isCycle(arr)){
System.err.println(Arrays.toString(arr));
return;
} else if(arr.length==6){
//System.out.println(Arrays.toString(arr));
return;
}else if (isSCycle(arr)){
findCycle(arr,list);
}
}
}
public static long iFact(long x) {
for (long i = x - 1; i > 1; i--) {
x = x * i;
}
return x;
}
public static boolean isSCycle(int[] arr){
String[] s = new String[arr.length];
for (int i = 0; i < s.length; i++)
s[i]=arr[i]+"";
String[][] perms = new String[(int)iFact(arr.length)][arr.length];
permute(perms,0,s,0);
for (int i = 0; i < perms.length; i++) {
boolean check = true;
for (int j = 0; j < perms[i].length-1; j++) {
if(!perms[i][j].substring(2, 4).equals(perms[i][j+1].substring(0, 2)))
check= false;
}
if(check)
return true;
}
return false;
}
public static boolean isCycle(int[] arr){
String[] s = new String[arr.length];
for (int i = 0; i < s.length; i++)
s[i]=arr[i]+"";
String[][] perms = new String[(int)iFact(arr.length)][arr.length];
permute(perms,0,s,0);
for (int i = 0; i < perms.length; i++) {
boolean check = true;
for (int j = 0; j < perms[i].length; j++) {
if(j == perms[i].length-1){
if(!perms[i][j].substring(2, 4).equals(perms[i][0].substring(0, 2)))
check= false;
continue;
}
if(!perms[i][j].substring(2, 4).equals(perms[i][j+1].substring(0, 2)))
check= false;
}
if(check)
return true;
}
return false;
}
public static int permute(String[][] perms, int pc, String[] original, int a){
if(a==original.length-2){
perms[pc++] = original.clone();
swap(original,original.length-1,original.length-2);
perms[pc++] = original.clone();
return pc;
}
ArrayList list = new ArrayList();
for(int c = a ; c < original.length;c++)
list.add(original[c]);
while(!list.isEmpty()){
String t = list.remove(0);
if(!t.equals(original[a]))
swap(original,a,find(original,t));
pc=permute(perms,pc,original,a+1);
}
return pc;
}
public static int find(String[] t, String k){
for (int i = 0; i < t.length; i++)
if(t[i].equals(k))
return i;
return -1;
}
public static void swap(T[] arr, int a, int b){
T t= arr[a];
arr[a] = arr[b];
arr[b] = t;
}
}
Suscribirse a:
Entradas (Atom)