Skip to content

Instantly share code, notes, and snippets.

@duane
duane / SmallVector.h
Created November 2, 2011 23:36
LLVM SmallVector
//===- llvm/ADT/SmallVector.h - 'Normally small' vectors --------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file defines the SmallVector class.
@duane
duane / gist:1371111
Created November 16, 2011 19:43
Type error in small haskell program
module Main where
import Graphics.Sketch
import Data.Array.Repa
import Data.Word
import Control.Monad
import System.Random
randomWord8 :: IO Word8
@duane
duane / gist:1474880
Created December 14, 2011 01:55
mutability not working?
use std;
fn poke(value: uint, index: uint, data: @mutable [mutable uint]) {
(*data)[index] = value;
}
fn main(_args: [str]) {
let vec = [mutable 4u];
std::io::println(#fmt["%u", vec[0]]);
poke(3u, 0u, @mutable vec);
@duane
duane / gist:1475365
Created December 14, 2011 05:14
A merge-sort implementation
fn merge_sort<copy a>(&&d: [mutable a]) {
fn merge<copy a>(&&data: [mutable a], &&temp: [mutable a], low: uint, middle: uint, high: uint) {
let resultI = low;
let tempI = low;
let destI = middle;
while tempI < middle && destI <= high {
if data[destI] < temp[tempI] {
data[resultI] = data[destI];
resultI += 1u;
destI += 1u;
#[cfg(target_os = "macos")]
native mod c {
fn mach_absolute_time() -> u64;
}
#[cfg(target_os = "macos")]
#[link_name=""]
#[link_args = "-framework CoreServices"]
native mod CoreServices {
#[link_name = ""]
#[link_args = "BAD LINKING"]
native mod c {
fn random() -> int;
}
@duane
duane / redw.lhs
Created December 27, 2011 11:10
Reddit aeson/bytestring
> {-# LANGUAGE OverloadedStrings #-}
This is the main driver of the program.
> module Main where
We need System.Environment for access command line arguments:
> import System.Environment (getArgs)
@duane
duane / mysql_auth.md
Last active December 15, 2015 22:28
How to set root password for mysql

Note: the indented bits are intended to be copy/pasted. If you don't know your way around a unix system, and on top of that whatever weird design desisions ubuntu has implemented, it's very easy to mess them up.

Kill mysql and start it up in a completely unprivileged mode:

sudo /etc/init.d/mysql stop
sudo mysqld_safe --skip-grant-tables &

Now, mysqld_safe will block input, so you'll need to open a new terminal tab. Then, connect to mysql's meta database that includes auth information:

mysql -uroot mysql

@duane
duane / postgresql_9.1.9_plist_create.rb
Last active December 17, 2015 16:30
A script to generate a postgres launchctl plist for homebrew.
prefix = `brew --prefix`.chomp
var = "#{prefix}/var"
domain = "homebrew.mxcl.postgresql"
File.open("#{`brew --cellar postgresql`.chomp}/9.1.9/#{domain}.plist", "w") do |file|
file.write %Q{
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>KeepAlive</key>
require 'formula'
class ScalaDocs < Formula
homepage 'http://www.scala-lang.org/'
url 'http://www.scala-lang.org/files/archive/scala-docs-2.9.2.zip'
sha1 'b49ef500314d968ddbd683b64628925a747f35e5'
end
class ScalaCompletion < Formula
homepage 'http://www.scala-lang.org/'