Skip to content

Instantly share code, notes, and snippets.

View rahulmutt's full-sized avatar

Rahul Muttineni rahulmutt

View GitHub Profile
@rahulmutt
rahulmutt / 5-Lens.hs
Created August 2, 2017 03:07
Lens Example in Eta
module Main where
import Control.Lens
import Data.Aeson
import Data.Aeson.Lens
import Data.Aeson.Encode.Pretty
import qualified Data.ByteString.Lazy.Char8 as BS
main :: IO ()
main = do
@rahulmutt
rahulmutt / Hello.hs
Last active August 2, 2017 01:17
Test Medium
module Main where
main :: IO ()
main = putStrLn "Hello World!"
@rahulmutt
rahulmutt / Trace.md
Created April 27, 2017 09:55
Trace of text bug
objc[11695]: Class JavaLaunchHelper is implemented in both /Users/rahulmuttineni/.jenv/versions/1.8/bin/java and /Library/Java/JavaVirtualMachines/jdk1.8.0_102.jdk/Contents/Home/jre/lib/libinstrument.dylib. One of the two will be used. Which one is undefined.
[main] INFO eta.main - >> main(1=[])
[main] INFO eta.runtime.RtsConfig - >> getDefault()
[main] INFO eta.runtime.RtsFlags$RtsOptsEnabled - >> <clinit>()
[main] INFO eta.runtime.RtsFlags$RtsOptsEnabled - >> RtsFlags$RtsOptsEnabled(1=RtsOptsNone, 2=0)
[main] INFO eta.runtime.RtsFlags$RtsOptsEnabled - << RtsFlags$RtsOptsEnabled(1=RtsOptsNone, 2=0)
[main] INFO eta.runtime.RtsFlags$RtsOptsEnabled - >> RtsFlags$RtsOptsEnabled(1=RtsOptsSafeOnly, 2=1)
[main] INFO eta.runtime.RtsFlags$RtsOptsEnabled - << RtsFlags$RtsOptsEnabled(1=RtsOptsSafeOnly, 2=1)
[main] INFO eta.runtime.RtsFlags$RtsOptsEnabled - >> RtsFlags$RtsOptsEnabled(1=RtsOptsAll, 2=2)
@rahulmutt
rahulmutt / Main.hs
Created March 3, 2017 05:07
Length of HList
{-# LANGUAGE DataKinds, TypeFamilies, ScopedTypeVariables, TypeOperators, GADTs, UndecidableInstances, FlexibleContexts #-}
module Main where
import GHC.TypeLits
import Data.Proxy
main :: IO ()
main = print $ hlength (HCons "Hello" (HCons (1 :: Int) HNil))
hlength :: forall xs. KnownNat (Length xs) => HList xs -> Integer
@rahulmutt
rahulmutt / Results.md
Created January 30, 2017 07:04
Monad Transformer Benchmark Results
Setting phasers to stun... (port 3000) (ctrl-c to quit)
Setting phasers to stun... (port 3003) (ctrl-c to quit)
Setting phasers to stun... (port 3002) (ctrl-c to quit)
Setting phasers to stun... (port 3001) (ctrl-c to quit)
benchmarking renderText
time                 6.612 ms   (6.528 ms .. 6.686 ms)
                     0.999 R²   (0.999 R² .. 1.000 R²)
mean                 6.563 ms   (6.546 ms .. 6.585 ms)
std dev              58.50 μs   (43.10 μs .. 75.69 μs)
@rahulmutt
rahulmutt / Hexdump.md
Created January 28, 2017 14:43
Corrupted Jars

Hexdump of the corrupted jar:

00000000: 504b 0304 1400 0000 0800 4072 3c4a f0b8  PK........@r<J..
00000010: e8a0 7901 0000 8a02 0000 2000 1400 6768  ..y....... ...gh
00000020: 637a 6d70 7269 6d2f 6768 632f 4d61 6769  czmprim/ghc/Magi
00000030: 6324 696e 6c69 6e65 2e63 6c61 7373 0100  c$inline.class..
00000040: 1000 8a02 0000 0000 0000 7901 0000 0000  ..........y.....
00000050: 0000 7d91 4b4b c350 1085 cfd8 b469 637c  ..}.KK.P.....ic|
00000060: b6b6 bedf 8fd6 8a51 5c2a 8214 8482 dda8  .......Q\*......
00000070: 745b aef5 1a83 691a 925b b0fe 2637 7551 t[....i..[..&amp;7uQ

Replacing imaginary/queens with the implemenation below in rahulmutt/nofib:

{-# LANGUAGE BangPatterns #-}

-- solution by Oystein Kolsrud
-- https://www.youtube.com/watch?v=I2tMmsZC1ZU
okToAdd :: Int -> [Int] -> Bool
okToAdd q qs = all (okToAddDirection q qs) [succ, pred, id]
    where

In https://github.com/rahulmutt/nofib, run using:

nofib-runner imaginary/queens --run --jmh="-wi 10 -i 10" --way="-O2"

Queens Solution:

-- !!! count the number of solutions to the "n queens" problem.
-- (grabbed from LML dist)
@rahulmutt
rahulmutt / Rendering.md
Last active January 14, 2017 04:46
FFI Import Generation

Rendering.hs:

{-# LANGUAGE FlexibleContexts #-}
module JavaFX.Rendering where

import Java
import JavaFX.Types

type Render a = Java GraphicsContext a
@rahulmutt
rahulmutt / JVM.md
Created December 14, 2016 17:58
JVM Class Naming

The file 2.jar contains a file 2.class that was generated manually (without javac). You can download it here.

Running java -jar 2.jar works perfectly and should output

Hello World!

Here is the output of running javap -c -v 2.class:

Classfile 2.class