Skip to content

Instantly share code, notes, and snippets.

View tamasd's full-sized avatar

Tamás Demeter-Haludka tamasd

  • Lufthansa Systems Hungaria
  • Szeged
View GitHub Profile
@tamasd
tamasd / kextstat.go
Created June 2, 2014 22:00
A bit more readable kextstat command for Mac OS X.
package main
import (
"bytes"
"fmt"
"io/ioutil"
"log"
"os/exec"
"regexp"
"sort"
package main
import (
"runtime"
"sync"
)
func main() {
runtime.GOMAXPROCS(runtime.NumCPU())
var wg sync.WaitGroup
import Prelude
fizzbuzz :: (Eq a, Num a) => a -> a -> [Char] -> [Char]
fizzbuzz 0 0 _ = "FizzBuzz"
fizzbuzz 0 _ _ = "Fizz"
fizzbuzz _ 0 _ = "Buzz"
fizzbuzz _ _ x = x
checkfb :: (Show a, Integral a) => a -> [Char]
checkfb n = fizzbuzz (n `rem` 3) (n `rem` 5) (show n)
<?php
define('KEXT_DELIMITER', " \t\n");
class KEXT {
public $index;
public $refs;
public $size;
public $wired;
public $name;
func updateNode(nid string, title string, body BodyField, cookie *http.Cookie) {
body.value = editBody(body.value)
postdata := fmt.Sprintf("title=%s&body[und][0][summary]=&body[und][0][value]=%s&body[und][0][format]=%s", url.QueryEscape(title), url.QueryEscape(body.Value), url.QueryEscape(body.Format))
resp := post("node/" + nid, postdata, cookie, "PUT")
if resp.StatusCode != http.StatusOK {
log.Fatal(resp.Status)
}
}
func editBody(original string) string {
tmpfile, err := ioutil.TempFile(os.TempDir(), "myapp")
if err != nil {
log.Fatal(err)
}
name := tmpfile.Name()
tmpfile.WriteString(msg)
tmpfile.Sync()
tmpfile.Close()
func getNode(nid string, cookie *http.Cookie) (title String, body BodyField) {
resp := get("node/" + nid, cookie)
rawbody := getBody(resp)
var node Node
if err := json.Unmarshal(rawbody, &node); err != nil {
log.Fatal(err)
}
if len(node.Body[node.Language]) > 0 {
return node.Title, node.Body[node.Language][0]
type BodyField struct {
Format string
Value string
}
type Node struct {
Title string
Body map[string][]BodyField
Language string
}
func getBody(resp *http.Response) []bytes {
respbody, _ := ioutil.ReadAll(resp.Body)
defer resp.Body.Close()
return respbody
}
func login(username, password string) *http.Cookie {
resp := post("user/login", fmt.Sprintf("username=%s&password=%s", url.QueryEscape(username), url.QueryEscape(password)), nil)
if resp.StatusCode != http.StatusCodeOK {
log.Fatal(resp.Status)
}
jsondata := getBody(resp)
var lr LoginResponse
if err := json.Unmarshal(jsondata, &lr); err != nil {
log.Fatal(err)