Skip to content

Instantly share code, notes, and snippets.

@xeoncross
xeoncross / traveling-salesman.php
Created September 18, 2012 14:07 — forked from tlhunter/traveling-salesman.php
PHP Traveling Salesman Genetic Algorithm
<?php
ini_set("error_reporting", E_ALL & ~E_NOTICE);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Genetic Algorithm : TSP : PHP Implementation by Thomas Hunter</title>
<style>
body {
@riklomas
riklomas / adding-to-user-admin-form.py
Created August 6, 2010 15:01
How to add a field to the Django Admin Add User form using UserCreationForm. Add this to a admin.py and alter to whatever fields you'd like
# How to add a field to the Django Admin Add User form
# using UserCreationForm. Add this to a admin.py and alter
# to whatever fields you'd like
from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth.models import User
from django.contrib.auth.admin import UserAdmin
from django import forms
from django.utils.translation import ugettext_lazy as _
from django.contrib import admin
@stanislavb
stanislavb / mongoconsole.sh
Last active February 10, 2023 16:34
Backup and restore MongoDB running in a Docker container
#!/bin/bash
usage() {
echo "Usage $0 -c mongo_docker_container_name"
}
while [[ $# > 1 ]]
do
key="$1"
@rnorth
rnorth / gist:2031652
Created March 13, 2012 21:14
Cookie-based authentication with nginx
worker_processes 1;
error_log logs/error.log;
events {
worker_connections 1024;
}
@tbjers
tbjers / check-apache-instances.sh
Last active April 6, 2023 18:25
Script to determine Apache ServerLimit and MaxClients.
#!/bin/sh
available=$(free --mega -tw | grep "Total:" | awk '{print $4}')
ps -ylC httpd --sort:rss | awk -v avail="$available" '{ s += $8; } END { print "Average Size:", s/(NR-1)/1024, "MB,", NR-1, "Processes, Total usage:", (s/(NR-1)/1024)*(NR-1), "MB, Max Servers:", avail/(s/(NR-1)/1024) }'
@cschlyter
cschlyter / mongo_group_by_day.js
Created June 12, 2013 16:46
MongoDB: group by day (aggregate)
var mention_id = 620996;
db.mentionStats.aggregate([
{ $match: {'mention_id': mention_id}},
{ $group: {'_id': {
'year': { '$year': "$verification_date" },
'month': { '$month': "$verification_date" },
'day': { '$dayOfMonth': "$verification_date" }
},
'retweets': { $last: "$retweets" }}},
@NARKOZ
NARKOZ / db_backup.sh
Created October 23, 2010 18:15
MySQL backup shell script
#!/bin/bash
# Shell script to backup MySQL database
# Set these variables
MyUSER="" # DB_USERNAME
MyPASS="" # DB_PASSWORD
MyHOST="" # DB_HOSTNAME
# Backup Dest directory
DEST="" # /home/username/backups/DB
@jrue
jrue / index.html
Last active August 9, 2023 14:21
HTML & CSS Wheel Of Fortune / Bingo Game
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Wheel of Fortune Bingo</title>
<!--
MIT License
@renzok
renzok / Dockerfile
Last active September 6, 2023 04:55
docker: mapping host uid and gid to user inisde container
FROM debian:jessie
ENV USER=boatswain USER_ID=1000 USER_GID=1000
# now creating user
RUN groupadd --gid "${USER_GID}" "${USER}" && \
useradd \
--uid ${USER_ID} \
--gid ${USER_GID} \
--create-home \
@uris77
uris77 / repo_pattern.py
Last active September 20, 2023 15:08
Example of Repository Pattern with SQLAlchemy
# This is a very crud example of using the Repository Pattern with SQLAlchemy. It allows me to completely ignore interactions with
# the database. This is only pulled in whenever I require to persist or retrieve an object from the database. The domain/business
# logic is entirely separated from persistence and I can have true unit tests for those.
# The tests for persistence are then limited to very specific cases of persistence and retrieving instances, and I can do those
# independent of the business logic. They also tend to be less tests since I only need to test them once.