Skip to content

Instantly share code, notes, and snippets.

@peterdn
peterdn / main.c
Last active July 22, 2017 14:20
C HTTP response
#include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <unistd.h>
#include <string.h>
#define BUF_SIZE 1000000
int main(int argc, char *argv[]) {
fn main() {
let stack: &mut ~[~int] = &mut ~[];
stack.push(~0);
stack.push(~0);
stack.push(~0);
stack.push(~0);
stack.push(~0);
}
@peterdn
peterdn / locks.cs
Created March 12, 2012 10:42
Re-entrant locking vs blocking
class A
{
private object _lock = new object();
public void foo()
{
lock(_lock)
{
do_something();
}
@peterdn
peterdn / HMMTagger.cs
Created October 27, 2010 22:32
The beginnings of an HMM POS tagger for my computational linguistics course
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.IO;
namespace HMMTagger
{
class Tuple<T1, T2>
@peterdn
peterdn / ChrisPuzzle.cs
Created October 15, 2010 10:09
Finds a solution for a specific 16-piece edge matching puzzle.
/*
* Finds a solution for a specific 16-piece edge matching puzzle.
* Yields the following output:
*
* Success in 827772 comparisons!
* 0: Piece 1, Rot 2
* 1: Piece 9, Rot 2
* 2: Piece 15, Rot 2
* 3: Piece 5, Rot 1
* 4: Piece 6, Rot 2
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing.Printing;
using System.ComponentModel;
using WebKit.Interop;
using System.Drawing;
using System.Windows.Forms;
namespace WebKit
public void PrintHack()
{
PrintDocument doc = new PrintDocument();
doc.DocumentName = this.DocumentTitle;
doc.DefaultPageSettings = PageSettings;
doc.OriginAtMargins = true;
PrintManager pm = new PrintManager(doc, this, true);
pm.Print();
doc.Print();
}
@peterdn
peterdn / controllers\url.php
Created August 10, 2010 20:32
PHP source used in my URL shortener (uses the CodeIgniter framework)
<?php
/* Author: Peter Nelson / @_peterdn - controllers\url.php
* The main controller for the site. */
class Url extends Controller
{
public function Url()
{
parent::Controller();
$this->load->helper("url");
@peterdn
peterdn / UrlShortenerTextBox.xaml
Created August 8, 2010 00:17
Simple SL control for an URL shortener service that copies text to clipboard
<!-- Author: Peter Nelson / @_peterdn - A simple SL control that copies text
to the user's clipboard. Currently used in my URL (not-so) shortener
at http://u.peterdn.com, on supported clients. -->
<UserControl x:Class="UrlShortenerTextBox.UrlShortenerTextBox"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"