Skip to content

Instantly share code, notes, and snippets.

//blue/1/~/ pacman -Qqe > qqe
//blue/0/~/ pacman -Qqm > qqm
//blue/0/~/ cat qqe | grep -Fvx "$(cat qqm)" | head # useless cat on purpose
abcde
abook
abs
acl
acpid
alsa-lib
alsa-oss
-- | Conditionally apply the monadic f to the Maybe value when it is
-- Just and wrap the /inner/ value in Just, or return Nothing
(=<?) :: (Monad m) => (a -> m b) -> Maybe a -> m (Maybe b)
f =<? (Just a) = return . Just =<< f a
f =<? Nothing = return Nothing
-- can this not be done with some variation of liftM and fmap?
@pbrisbin
pbrisbin / gist:883120
Created March 23, 2011 13:59
mpd visualizer setup.
mpd config
299 ## A Fifo output for visualizations in ncmpcpp-git
300 #
301 audio_output {
302 type "fifo"
303 name "ncmpcpp visualizer"
304 path "/tmp/mpd.fifo"
305 format "44100:16:1"
@pbrisbin
pbrisbin / mpdroutes.hs
Created March 27, 2011 04:51
haskell rocks
-- | Execute any mpd action then redirect back to status page
actionRoute :: YesodMPC m => MPD.MPD () -> GHandler MPC m RepHtmlJson
actionRoute f = do
authHelper
_ <- withMPD f
tm <- getRouteToMaster
redirect RedirectTemporary $ tm StatusR
-- | Toggle any mpd setting then redirect back to status page
toggleRoute :: YesodMPC m => Toggle -> GHandler MPC m RepHtmlJson
@pbrisbin
pbrisbin / Boolish.hs
Created April 4, 2011 18:35
Does something like this already exist?
module Data.Boolish (Boolish(..)) where
-- | Class for boolean-like datastructures
class Boolish a where
isTrue :: a -> Bool
-- | Default binding is @'not' . 'isTrue'@
isFalse :: a -> Bool
isFalse = not . isTrue
@pbrisbin
pbrisbin / Proposed.hs
Created May 3, 2011 15:45
Generic search
{-# LANGUAGE OverloadedStrings #-}
module Search where
import Data.List
import Data.Ord
import Data.Maybe
import qualified Data.Text as T
data SearchResult a = SearchResult
{ searchRank :: Double
@pbrisbin
pbrisbin / Satisfy.hs
Created May 14, 2011 14:09
Satisfiability, second attempt
{-# LANGUAGE NoImplicitPrelude #-}
--
-- <http://en.wikipedia.org/wiki/Boolean_satisfiability_problem>
--
-- In complexity theory, the satisfiability problem (SAT) is a decision
-- problem, whose instance is a Boolean expression written using only
-- AND, OR, NOT, variables, and parentheses. The question is: given the
-- expression, is there some assignment of TRUE and FALSE values to the
-- variables that will make the entire expression true? A formula of
-- propositional logic is said to be satisfiable if logical values can
@pbrisbin
pbrisbin / dlgmaker.sh
Created June 2, 2011 19:14
Dialog maker
#!/bin/bash
#
# makes dialog related methods for X++
#
###
message() { echo './dlgmaker.sh type=variable type=variable ...'; exit 1; }
[[ "$1" =~ -h|--help ]] && message
@pbrisbin
pbrisbin / person.c
Created June 7, 2011 21:30
malloc?
#include <stdlib.h>
#include <stdio.h>
struct person_t {
char *name;
int age;
};
int main() {
struct person_t *person;
@pbrisbin
pbrisbin / scanner.c
Created June 26, 2011 00:26
simple port scanner
/* Original author: Vikraman (vh4x0r @ Freenode) <vikraman.choudhury@gmail.com> */
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <netdb.h>