Skip to content

Instantly share code, notes, and snippets.

View sw17ch's full-sized avatar

John VanEnk sw17ch

View GitHub Profile
/* gcc -Wall -O3 c_sqlite_test.c -lsqlite3 -o c_sqlite */
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <sqlite3.h>
/* Macros to simplify things. */
#define BEGIN_TRANSACTION() do { int e; char em[1024]; \
#include "memcat.h"
#define MIN(a,b) ((a) < (b) ? (a) : (b))
size_t memcat(uint8_t * dst,
struct memdesc * descriptors,
size_t descriptor_count,
size_t max_len)
{
size_t remaining = max_len;
require 'thread'
$id = 0
$sem = Mutex.new
def next_id
n = nil
$sem.synchronize do
n = $id
$id += 1
module Main where
import Control.Concurrent
import System.IO
main :: IO ()
main = do
hSetBuffering stdout NoBuffering
mapM_ (forkIO . putStrLn . repeat) ['a'..'z']
threadDelay 1000000
> module Units where
The goal of this module is to demonstrate some basic unit conversion and
manipulation using the Haskell type system.
First, let's define our data types. We'll represent things as Doubles for
convenience.
> newtype Meters = Meters Double deriving (Show)
> newtype Feet = Feet Double deriving (Show)
@sw17ch
sw17ch / preload_stack.asm
Last active December 16, 2015 00:09
Loop to preload my system stack with a value of 'X'.
ldr r0, =__stack_start__
ldr r1, =__stack_end__
mov r2, 0x58585858 /* 'XXXX' */
load_stack_word:
cmp r0, r1
beq stack_initted
str r2, [r0]
add r0, r0, #4
b load_stack_word
stack_initted:
@sw17ch
sw17ch / c_code_gen.hs
Created May 16, 2013 03:55
Just discovered language-c-quote. Wow.
{-# LANGUAGE QuasiQuotes #-}
module Data.Cauterize.Generators.C where
import Text.PrettyPrint.Mainland
import Language.C.Quote.C
genC :: IO ()
genC = print $ ppr f
where
ty = [cty|int|]
#!/usr/bin/env ruby
count = ARGV[0] ? ARGV[0].to_i : 1
opens = "(" * count
txt = STDIN.read.chomp
closes = ")" * count
puts(opens + txt + closes)
fn r̄ͬ̇ͦ̓u͗͗̅̐s̔̈́ͯ̄̓ͭ͋tͣͯͦ̂̃̆̓_̍͌̉̃l̆a͐̾̿̋̈́n̉ͬͥ́ͪ̊gͭ͛̾_́cͪͬ͑͂̈oͭͨ̊̋̓ͧm̌̿̐̿ͤ̆͐e̔̓̆ͭͨ̾̚s() {
println("ĭ̒̚tͧ̂͆ͫ̄ ̃ͬ͗̍̂c̈͒̊õ͑̓ͩͦ͒m̊͗̐̒esͩ͛!ͨ̀ͩ̀͆̄̚ ĭ̿̈̍̀ͮ͑tͦ͂̉̒̔̇ ̓co͛́̾ͤ̄̉͌m͂͆̀ͫe͛ͨ͌̇͆ͣͥs͂!̇̌̎̆");
}
fn main() {
r̄ͬ̇ͦ̓u͗͗̅̐s̔̈́ͯ̄̓ͭ͋tͣͯͦ̂̃̆̓_̍͌̉̃l̆a͐̾̿̋̈́n̉ͬͥ́ͪ̊gͭ͛̾_́cͪͬ͑͂̈oͭͨ̊̋̓ͧm̌̿̐̿ͤ̆͐e̔̓̆ͭͨ̾̚s();
}
# First, make the thing that I want.
class Object
# Becomes passes self to a block. The result of the
# operation is the result of the block rather than the
# original object. This allows us to transform an object
# in-line with a method chain without having to mix-in or
# add the method to any of the objects.
def becomes
yield self