Skip to content

Instantly share code, notes, and snippets.

extern crate rusqlite;
extern crate chrono;
use rusqlite::Connection;
#[allow(dead_code)]
fn lfsr3(x : u8) -> u8 {
let bit = ((x >> 0) ^ (x >> 1)) & 1;
(x >> 1) | (bit << 2)
}
@c000
c000 / ocl-logistic.rs
Created February 28, 2017 13:01
Logistic map
extern crate ocl;
extern crate image;
use ocl::traits::MemLen;
const SIZE: [u32; 2] = [1600, 1600];
const PROGRAM: &'static str = r"
__kernel void init(__global uchar *buf, int height) {
int x = get_global_id(0);
int width = get_global_size(0);
{-# LANGUAGE Arrows #-}
module Main where
import Prelude hiding (init, (.))
import Control.Exception
import Control.Monad
import Data.Bits
import Foreign.C.Types
@c000
c000 / timer.rs
Last active September 17, 2016 17:51
Simple timer in Rust
extern crate chrono;
extern crate term;
extern crate ctrlc;
use chrono::duration::Duration;
use chrono::offset::utc::UTC;
use std::env::args;
use std::io;
use std::io::Write;
use std::thread;
num = 768 # value
block_n = 32
result = []
while num > 0:
if num & 1 == 1:
result.append(block_n)
num >>= 1
block_n -= 1
@c000
c000 / fizz.rs
Created November 23, 2015 07:24
fn fizz(n: i32) -> String {
match n {
n if n % 15 == 0 => format!("{}", "FizzBuzz"),
n if n % 3 == 0 => format!("{}", "Fizz"),
n if n % 5 == 0 => format!("{}", "Buzz"),
n => format!("{}", n),
}
}
@c000
c000 / A.cpp
Last active August 29, 2015 14:03 — forked from cocodrips/A.cpp
#include <iostream>
#include <utility>
#include <tuple>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;
const int N = 150;
@c000
c000 / altest.hs
Created August 5, 2013 02:19
OpenAL sound test
import Control.Monad
import Sound.ALUT
main = runALUT "" [] $ \_ _ -> do
listenerPosition $= Vertex3 0 0 0
listenerVelocity $= Vector3 0 0 0
buf <- createBuffer (Sawtooth 220 0 1)
buf2 <- createBuffer (Sawtooth 440 0 1)
sources@(s1:s2:_) <- genObjectNames 2
forM_ sources $ \s -> do
@c000
c000 / gist:5129661
Last active December 14, 2015 18:29
Haskell with GTK Test TreeView, MultibyteString and Timeout
import Control.Monad.Trans
import Control.Monad
import Control.Applicative
import Graphics.UI.Gtk
data MainWindow = MainWindow
{ window :: Window
, mainContainer :: VBox
, scrollArea :: ScrolledWindow
, scrollContent :: TreeMVC String