Skip to content

Instantly share code, notes, and snippets.

View rethab's full-sized avatar
🏠
Working from home

rethab

🏠
Working from home
View GitHub Profile
@rethab
rethab / strcat-malloc.s
Created December 31, 2020 11:11
concat string in dynamic memory using malloc from x86-64 assembly with at&t syntax
.data
.stringfmt:
.string "'%s'\n"
.s1:
.asciz "ab"
.s2:
.asciz "cd"
.text
.global main
@rethab
rethab / string-concat.s
Last active December 31, 2020 10:32
string concat in x86-64 assembly AT&T. run with `gcc string-concat.s -o concat && ./concat`
.data
.stringfmt:
.string "'%s'\n"
.s1:
.asciz "ab"
.s2:
.asciz "cd"
.text
.global main
@rethab
rethab / Disk.sh
Created October 31, 2016 08:23
Copy of the function mountedDevices from xmobar's Disk.hs to reproduce problem
import qualified Data.ByteString.Lazy.Char8 as B
import Data.Maybe (catMaybes)
import Data.List (isPrefixOf)
import System.Directory (doesFileExist, canonicalizePath)
main :: IO ()
main = mountedDevices ["mapper/home"] >>= print
mountedDevices :: [String] -> IO [(String, String)]

Keybase proof

I hereby claim:

  • I am rethab on github.
  • I am rethab (https://keybase.io/rethab) on keybase.
  • I have a public key whose fingerprint is E235 F740 4419 5B4B 29EC 3437 CBF2 2CB7 67D3 0264

To claim this, I am signing this object:

@rethab
rethab / named-instance.scala
Created September 12, 2016 09:49
get instance by named annotation from guice injector with the play framework
import play.api.inject.{QualifierInstance, BindingKey}
import com.google.inject.name.Names
val injector = ???
injector.instanceOf(BindingKey(classOf[MyType], Some(QualifierInstance(Names.named("my-thing")))))
@rethab
rethab / ManualAwait.scala
Created June 17, 2016 07:19
Awaiting a scala future for completion w/o the Await.result, which may spawn a new thread.
private def block[T](f: Future[T]): T = {
val barrier = new CountDownLatch(1)
import play.api.libs.concurrent.Execution.Implicits.defaultContext
f onComplete {_ =>
barrier.countDown()
}
barrier.await(30, TimeUnit.SECONDS)
@rethab
rethab / CancellableFuture.scala
Created June 16, 2016 07:41
Await.result doesn't cancel Futures on timeout
import java.util.concurrent.TimeUnit
import scala.concurrent.duration.Duration
import scala.concurrent.{Await, Future}
/**
* Test if Futures are cancelled once the duration of
* the await has timed out.
*
* This demonstrates, that even after the 'Await.result'
@rethab
rethab / WithFancyApp.scala
Last active January 23, 2016 06:01
Enhanced WithApplication class to test Play 2.4 applications with dependency injection using
/**
* Provides Messages implicit and the default Guice-Container
* into the context for testing Play 2.4 applications.
*
* Sample:
*
* "use the overridden bindigs" in new WithFancyApp(
* lang = Lang("en", "US"),
* overrideModules = Seq(bind[MyInterface].to[MyImplementation])
* ) {
@rethab
rethab / php-android-todo.php
Last active August 29, 2015 14:15
simple android todo app in php
<?php
// droid is coming from testnow.php
// all this app can do. corresponding functions are
// named do_XXX where XXX is the action
$actions = array('create', 'list', 'done', 'exit');
// database as array. read when started, saved on exit.
$data = null;
@rethab
rethab / grouper.hs
Last active August 29, 2015 14:10
group values of list of key values pairs
{-# LANGUAGE RecordWildCards #-}
import Control.Arrow (second)
import Control.Applicative ((<$>), (<*>))
import Data.List (groupBy, genericLength)
import System.Console.GetOpt (ArgDescr(..), ArgOrder(..))
import System.Console.GetOpt (OptDescr(..), getOpt, usageInfo)
import System.IO (hPutStrLn, stderr)
import System.Environment (getArgs)
import System.Exit (exitFailure)