Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env runhaskell
-- This is a simple script to convert .a libs into .so ones.
-- More specifically I used it to convert static libs from LLVM for usage with GHCi.
import System.Directory
import System.FilePath
import System.Process
import Control.Applicative
import Data.List ( isSuffixOf )
@Tener
Tener / curand_host_example.c
Created January 30, 2011 23:03
CURAND host API example
/* This program uses the host CURAND API to generate 100
* pseudorandom floats.
*
* Code taken verbatim from CURAND library documentation.
*/
#include <stdio.h>
#include <stdlib.h>
#include <cuda.h>
#include <curand.h>
#define CUDA_CALL(x) do { if((x) != cudaSuccess) { \
@Tener
Tener / gist:809047
Created February 3, 2011 04:22
nvopencc bug
[code]__cuda_local_var_212953_15_non_const_tmp = ((((__T2408 = (((const float3 *)(&(__cuda_local_var_212940_13_non_const_ray.current_point)))->x)) , ((((2.0F) * __T2408) * ((((2.0F) * __T2408) * ((((2.0F) * __T2408) * ((((2.0F) * __T2408) * ((((2.0F) * __T2408) * ((((2.0F) * __T2408) * ((((2.0F) * __T2408) * ((((2.0F) * __T2408) * ((((2.0F) * __T2408) * ((((2.0F) * __T2408) * ((((2.0F) * __T2408) * ((((2.0F) * __T2408) * ((((2.0F) * __T2408) * ((((2.0F) * __T2408) * ((((2.0F) * __T2408) * __T2408) - (1.0F))) - __T2408)) - ((((2.0F) * __T2408) * __T2408) - (1.0F)))) - ((((2.0F) * __T2408) * ((((2.0F) * __T2408) * __T2408) - (1.0F))) - __T2408))) - ((((2.0F) * __T2408) * ((((2.0F) * __T2408) * ((((2.0F) * __T2408) * __T2408) - (1.0F))) - __T2408)) - ((((2.0F) * __T2408) * __T2408) - (1.0F))))) - ((((2.0F) * __T2408) * ((((2.0F) * __T2408) * ((((2.0F) * __T2408) * ((((2.0F) * __T2408) * __T2408) - (1.0F))) - __T2408)) - ((((2.0F) * __T2408) * __T2408) - (1.0F)))) - ((((2.0F) * __T2408) * ((((2.0F) * __T2408) * _
@Tener
Tener / gist:809048
Created February 3, 2011 04:22
nvopencc bug
__cuda_local_var_212953_15_non_const_tmp =
((((__T2408 = (((const float3 *)(&(__cuda_local_var_212940_13_non_const_ray.current_point)))->x))
, ((((2.0F) * __T2408) * ((((2.0F) * __T2408) * ((((2.0F) * __T2408) * ((((2.0F)
* __T2408) * ((((2.0F) * __T2408) * ((((2.0F) * __T2408) * ((((2.0F) * __T2408) *
((((2.0F) * __T2408) * ((((2.0F) * __T2408) * ((((2.0F) * __T2408) * ((((2.0F) *
__T2408) * ((((2.0F) * __T2408) * ((((2.0F) * __T2408) * ((((2.0F) * __T2408) * ((((2.0F)
* __T2408) * __T2408) - (1.0F))) - __T2408)) - ((((2.0F) * __T2408) * __T2408) -
(1.0F)))) - ((((2.0F) * __T2408) * ((((2.0F) * __T2408) * __T2408) - (1.0F))) - __T2408)))
- ((((2.0F) * __T2408) * ((((2.0F) * __T2408) * ((((2.0F) * __T2408) * __T2408) -
(1.0F))) - __T2408)) - ((((2.0F) * __T2408) * __T2408) - (1.0F))))) - ((((2.0F) *
@Tener
Tener / LookAndSay.hs
Created September 17, 2011 20:17
Quite efficient generation "look and say" sequence in Haskell
{-
ghc --make -Odph -fllvm -optlo-globalopt -optlo-loop-unswitch -optlo-mem2reg -optlo-prune-eh -O2 -fllvm -optl-O3 -rtsopts lookandsay.hs
time ./lookandsay > /dev/null
./lookandsay > /dev/null 6,02s user 0,24s system 99% cpu 6,284 total
-}
import System.IO
import Control.DeepSeq
data S = S1 | S2 | S3 -- deriving (Eq,Show,Read,Ord,Enum)
@Tener
Tener / LookAndSaySlow.hs
Created September 17, 2011 20:19
Slow generation of "look and say" sequence
import Data.List
import System.IO
say :: Integer -> Integer
say = read . concatMap saygroup . group . show
where saygroup s = (show $ length s) ++ [head s]
look_and_say :: [Integer]
look_and_say = 1 : map say look_and_say
pr (x,y) = do
@Tener
Tener / LookAndSay.cpp
Created September 18, 2011 22:09
Look and say in C++, reimplementation of algorithm first written in Haskell
/*
g++ -O3 -mtune=native -march=native -fomit-frame-pointer lookandsay.cpp -o lookandsay.out
time ./lookandsay.out > /dev/null
./lookandsay.out > /dev/null 2,88s user 0,05s system 99% cpu 2,948 total
*/
#include <vector>
#include <iostream>
@Tener
Tener / gist:1258736
Created October 3, 2011 08:59 — forked from anonymous/gist:1253064
GHC alias analysis
// Originally based on PyAliasAnalysis from the unladen-swallow project!
#include "llvm/ADT/APInt.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/Analysis/AliasAnalysis.h"
#include "llvm/Analysis/ScalarEvolution.h"
#include "llvm/Analysis/ScalarEvolutionExpressions.h"
#include "llvm/Analysis/Passes.h"
#include "llvm/Argument.h"
#include "llvm/Constants.h"
@Tener
Tener / plytkowanie.rb
Created March 3, 2012 10:31
Plugin for sketch up - with a bug!
# Wtyczka: "P-ytkuj"
# Autor: Krzysztof Skrzŕtnicki
# Licencja: GPLv3
# Wersja: 1.2
# First we pull in the standard API hooks.
require 'sketchup.rb'
# Show the Ruby Console at startup so we can
# see any programming errors we may make.
@Tener
Tener / plytkowanie.rb
Created March 5, 2012 08:54 — forked from DanRathbun/plytkowanie.rb
Plugin for sketch up - fixed up somewhat by Dan Rathbun - further minor fixes by original author
# -*- coding: utf-8 -*-
###
###
##### SAVE IN FORMAT: "UTF-8 WITHOUT BOM" OR "ANSI AS UTF-8"
###
###
# Plugin: "BathTiles"
# Author: Krzysztof Skrzetnicki, Dan Rathbun
# License: GPLv3