Skip to content

Instantly share code, notes, and snippets.

Introduction

With Genetic Algorithms (GAs) you can solve following problems:

  • There are 10 points on the map. What is the shortest path in order to travel all of them?
  • Solve an equation with N variables
  • [Vectorize Mona Lisa][1]

In a sense GAs are a marriage of brute force algorithm and evolution theory.

Pseudo algorithm

# http://wiki.apache.org/solr/FAQ#How_can_I_delete_all_documents_from_my_index.3F
# http://wiki.apache.org/solr/UpdateXmlMessages#Updating_a_Data_Record_via_curl
curl http://index.websolr.com/solr/a0b1c2d3/update -H "Content-Type: text/xml" --data-binary '<delete><query>*:*</query></delete>'
@mmiliaus
mmiliaus / gist:2275091
Created April 1, 2012 12:35
MySQL backups
= Considerations and Trade offs
== What can you afford to lose?
A "soft" point-in-time recovery requirement means you’d like to be able to recreate your data so that it’s "close enough"
to where it was when the problem happened. A "hard" requirement means
you can never tolerate the loss of a committed transaction, even if something terrible
happens (such as the server catching fire). This requires special techniques, such as
keeping your binary log on a separate SAN volume or using DRBD disk replication.
...
Don’t consider a backup (especially a raw backup) to be good until you’ve tested it.
@mmiliaus
mmiliaus / pso_example1.py
Created March 25, 2012 15:52
PSO example
# To change this template, choose Tools | Templates
# and open the template in the editor.
from random import uniform
import functools
import math
def calc_fitness(individ):
etalon = 500
return math.fabs( etalon - individ )
@mmiliaus
mmiliaus / yii_cheatsheet.php
Created March 2, 2012 14:30
Yii cheatsheet
// Migrations
yiic migrate create create_news_table
...
$this->createTable('tbl_news', array(
'id' => 'pk',
'title' => 'string NOT NULL',
'content' => 'text',
));
...
$this->dropTable('tbl_news');
@mmiliaus
mmiliaus / varnish_notes.sh
Created March 1, 2012 14:26
Varnish notes
# start varnish using /etc/varnish/default.vcl as config file
# allocate 1GB of memory
# administrative panel can be accessed at 127.0.0.1:2000
# bind it to 8008 port
sudo varnishd -f /etc/varnish/default.vcl -s malloc,1G -T 127.0.0.1:2000 -a 0.0.0.0:8008
@mmiliaus
mmiliaus / l.sh
Created February 16, 2012 10:24
Shell Logbook script
#!/bin/bash
/bin/echo `date` $* | tee -a logbook.log
/bin/echo >> logbook.log
@mmiliaus
mmiliaus / Getting img pixel data
Created December 24, 2011 21:23
cold JS cuts
canvas = document.createElement("canvas"),
ctx = canvas.getContext("2d");
canvas.className = "myClass";
canvas.id = "myId";
canvas.width = image.width;
canvas.height = image.height;
ctx.drawImage(image, 0, 0);
pixelData = ctx.getImageData(0, 0, image.width, image.height);
@mmiliaus
mmiliaus / cs.py
Created December 23, 2011 13:03
python cheatsheet
def foo(x, y=10, **kwargs):
# dictionaries
dict = {'a':1, 'b':23, 'c':'eggs'}
del dict['b']
dict.has_key('e')
# list comprehension
[x for x in range(5) if x%2 == 0]
# exception
def match! battle, winner, loser
r_a = winner.rating
r_b = loser.rating
max = battle.max.to_i
min = battle.min.to_i
th = ( max - min ) / 2
e_a = 1.0 / ( 1 + 10 ** ( (r_b - r_a) / 400 ))
e_b = 1.0 / ( 1 + 10 ** ( (r_a - r_b) / 400 ))