Skip to content

Instantly share code, notes, and snippets.

@flq
flq / josephus.hs
Last active August 16, 2018 20:27
Stuff I made in Haskell
module Josephus where
import Data.List
-- own, atrocious solution to josephus problem
lastSurvivor :: Int -> Int
lastSurvivor 1 = 1
lastSurvivor noOfPeople = fst . last $ unfoldr theSurvivors (1,(1,[])) where
theSurvivors (person, (count, theKilled))
| length theKilled == noOfPeople - 1 = Just (countOn, breakCondition)
@flq
flq / spaceinvaders.hs
Created September 10, 2013 20:39
A subset of the Space invaders game with moving left/right, shooting with space. The "game" ends when exiting with x or all enemies being dead.h
module Main where
import Control.Monad
import Data.List (maximumBy,minimumBy,find,(\\))
import Data.Ord
import Graphics.UI.SDL as FX
type Point = (Int,Int)
type MovementPattern = [(Movement, [(Int, Int)] -> Bool)]
@flq
flq / UiMessages.cs
Created September 20, 2013 15:01
Example setup for Membus to dispatch messages of a certain kind onto the UI thread...
// Use like BusSetup.StartWith<Conservative>().Apply<UiMessages>().Construct();
internal class UiMessages : ISetup<IConfigurableBus>
{
void ISetup<IConfigurableBus>.Accept(IConfigurableBus setup)
{
setup.ConfigurePublishing(obj =>
{
obj.MessageMatch(mi => mi.IsType<IUIMsg>()).PublishPipeline(new UiMsgDispatcher());
});
@flq
flq / euler001.hs
Last active December 24, 2015 08:09
Euler Problems solved with Haskell
-- http://projecteuler.net/problem=1
sum [x | x <- [0..999], any (\d -> mod x d == 0) [3,5]]
@flq
flq / ast.fs
Last active August 29, 2015 14:07
Lexing and Parsing in F# on Cobol
module Ast
open System
type slotDeclaration= {
Index : int
Name : string
Size : int
}
@flq
flq / CompileHub.cs
Last active March 8, 2019 22:18
Roslyn Refactoring
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reactive.Linq;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.MSBuild;
namespace ReFuc
@flq
flq / Permutation.hs
Last active August 29, 2015 14:23
No-frills permutation code in Haskell
module Permutation where
permutate :: [a] -> [[a]]
permutate [x1,x2] = [[x1,x2],[x2,x1]]
permutate items = concat $ map p $ getEachInFrontOnce items
where
p (x:xs) = map (\items -> [x]++items) $ permutate xs
getEachInFrontOnce items = map (putItemAtIndexToFront items) [0..length items-1]
putItemAtIndexToFront items idx = [items!!idx] ++ take idx items ++ drop (idx+1) items
@flq
flq / EntryPoint.ts
Last active October 10, 2015 23:45
Gists for the blog post porting react app to tyescript
import {assign} from 'lodash'
function startModule() {
//etc.
}
global['Project'] = assign(global['Project'] || {}, {
startModule
});
@flq
flq / IiUnitTests.cs
Last active December 30, 2015 21:40
Gist for using NMeasure for surplus energy in atmosphere...
using System.Collections.Generic;
using Xunit;
using static NMeasure.U;
using static NMeasure.Tests.IiUnits;
namespace NMeasure.Tests
{
public class IIUnitsTests
{
public IIUnitsTests()

Keybase proof

I hereby claim:

  • I am flq on github.
  • I am fquednau (https://keybase.io/fquednau) on keybase.
  • I have a public key ASDraf_OUnnhDWmgwKEoWTSV7QHQ1pjDPm0pCCSGME0ttwo

To claim this, I am signing this object: