Skip to content

Instantly share code, notes, and snippets.

View nitrix's full-sized avatar

Alex Belanger nitrix

View GitHub Profile
@nitrix
nitrix / quine.php
Created June 14, 2012 19:51
PHP challenge
<?php
$y = "function q(\$q) {
\$q = str_replace('\\\\', '\\\\\\\\', \$q);
\$q = str_replace('\$', '\\\\\$', \$q);
\$q = str_replace('\\n', '\\\\n', \$q);
\$q = str_replace('\"', '\\\\\"', \$q);
return \$q;
}
echo \"<?php\\n\";
@nitrix
nitrix / .gitignore
Created July 23, 2012 15:50
Triangles! A small experiment with HTML canvas
*.swp
*.swo
----------
! Xft settings
! ------------
Xft.dpi: 96
Xft.antialias: true
Xft.rgba: rgb
Xft.hinting: true
Xft.hintstyle: hintslight
nitrix at meow in ~/Projects/testga/build
$ cmake .. && make && ./testga
-- The C compiler identification is GNU 4.7.1
-- The CXX compiler identification is GNU 4.7.1
-- Check for working C compiler: /usr/bin/gcc
-- Check for working C compiler: /usr/bin/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
urxvt*font: xft:terminus:pixelsize=8
urxvt*boldFont: xft:terminus:pixelsize=8
urxvt*termName: rxvt
urxvt*background: #212629
urxvt*foreground: #737c80
urxvt*scrollBar: false
urxvt*matcher.button: 1
urxvt*cursorBlink: true
urxvt*cursorColor: #c1c8c9
urxvt*colorBD: #9a7b88
<?php
function makeRandomPassword($length) {
$pass = '';
$characters = 'abcdefghijkmnopqrstuvwxyz23456789';
srand((double)microtime()*1000000);
for($i=0; $i<$length; $i++) {
$random = rand() % 33;
$pass .= substr($characters, $random, 1);
}
return $pass;
#include <iostream>
#include <iomanip>
using namespace std;
double getBMI (int h, int w, double s)
{
cout << "h: " << h << endl;
cout << "w: " << w << endl;
cout << "s: " << s << endl;
#include <iostream>
#include <iomanip>
using namespace std;
//This function needs floating point promotion to have a working division
//This way we don't lose precision in the division.
double getBMI(double h, double w, double s)
{
return (w / (h*h)) * s;
<?php
$url = 'http://slow.example.com';
$stream = fopen($url, 'r');
stream_set_timeout($stream, 20);
$response_body = stream_get_contents($stream);
?>
<?php
$c = curl_init('http://slow.example.com/');
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
curl_setopt($c, CURLOPT_CONNECTTIMEOUT, 15);
$page = curl_exec($c);
curl_close($c);
?>