Skip to content

Instantly share code, notes, and snippets.

View xintron's full-sized avatar

Marcus Carlsson xintron

View GitHub Profile

Keybase proof

I hereby claim:

  • I am xintron on github.
  • I am xintron (https://keybase.io/xintron) on keybase.
  • I have a public key whose fingerprint is C405 076E CEF6 FC4B 0E5B E0BA 0070 8663 08C1 7775

To claim this, I am signing this object:

@xintron
xintron / procdirs.hs
Created March 13, 2014 20:05
Fetch process directories
getProcessDirectories = getDirectoryContents procPath >>=
filterM (doesDirectoryExist . (++) procPath) . filter (all isNumber) >>=
mapM (return . (++) procPath)
where
procPath = "/proc/"
@xintron
xintron / bot.hs
Created February 5, 2014 08:17
Simple IRC-bot written in Haskell
{-# LANGUAGE OverloadedStrings #-}
import Control.Monad (unless)
import Control.Exception (bracket)
import System.Environment (getArgs)
import System.IO (Handle, BufferMode(NoBuffering), hClose, hSetBuffering)
import Data.Time.LocalTime (getZonedTime)
import Network (PortID(PortNumber), connectTo)
import qualified Data.Text as T (Text, append, concat, drop, dropWhile, head,
isPrefixOf, pack, takeWhile, toLower, words)
import qualified Data.Text.IO as TIO (hGetLine, hPutStr, putStrLn)
import qualified Data.Text.Lazy as T (Text, lines, unlines)
import qualified Data.Text.Lazy.IO as TIO (interact)
data Command = Next
| Print
sed :: T.Text -> T.Text
sed t = T.unlines $ concat $ map (runCommands [Print]) $ T.lines t
runCommands :: [Command] -> T.Text -> [T.Text]
func (conn *Conn) Connect(host string) (c net.Conn, err error) {
log.SetFlags(23)
log.Printf("Connecting to host: %s\n", host)
// Wrapp the connection with a secure connection
if conn.SSL {
c, err = tls.Dial("tcp", host, conn.SSLConfig)
} else {
c, err = net.Dial("tcp", host)
}
if err != nil {
@xintron
xintron / loop.php
Created August 16, 2013 10:42
Example showing how inefficient foreach + range are together (thanks to PHP returning the full array instead of doing it like e.g. python which is yielding the current number when looping over a range). Setting range to 1000000 will exhaust 128MB memory in PHP while the for loop has no such limit.
<?php
$s = microtime(true);
$c = 0;
foreach(range(1, 100000) as $i) {
$c++;
}
$e = microtime(true);
printf("Foreach :: Time: %f, count: %d\n", $e-$s, $c);
$s = microtime(true);
#!/bin/bash
# Original: http://frexx.de/xterm-256-notes/
# http://frexx.de/xterm-256-notes/data/colortable16.sh
# Modified by Aaron Griffin
# and further by Kazuo Teramoto
FGNAMES=(' black ' ' red ' ' green ' ' yellow' ' blue ' 'magenta' ' cyan ' ' white ')
BGNAMES=('DFT' 'BLK' 'RED' 'GRN' 'YEL' 'BLU' 'MAG' 'CYN' 'WHT')
echo " ┌──────────────────────────────────────────────────────────────────────────┐"
<?php
class Foo {
public function __construct() {
var_dump(get_object_vars($this));
}
}
class Bar {
public function __construct(Array $args) {
foreach ($args as $key => $value) {
#!/usr/bin/env python3
# encoding: utf-8
import os
import sys
import argparse
def parse_arguments():
parser = argparse.ArgumentParser()
parser.add_argument('file')
location /code/ {
try_files $uri $uri/index.html =404;
}
location ~ /code/(?<uri_path>.*/)(?<page>\d+)$ {
try_files $uri $uri_path/index$page.html =404;
}
location ~ /foo/.*.html {
return 404;