Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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.
# 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>'

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

<?php
/*
* Zend Controller responsible for handling online payments.
* + Talking to PayPal API
* + Talking to PaymentSense API
* + Talking to SalesForce API
* + Auto-registering paying user with our system
* + Notifying about new lead
*
* @author Martynas Miliauskas <[email protected]>
<?php
/**
*
* Generates anchor HTML markup, which can perform GET/POST requests
*
* Example usage in the view
* <code>
* $this->linkTo(
'new',

Goal

Prerequisite

Installation

Ubuntu

Mac OS X