from os import makedirs, walk, sep, remove
from os.path import join, dirname, basename, exists
from shutil import rmtree, copy, rmtree
from itertools import chain
from zipfile import ZipFile

import py2exe

from Setup import Setup

class SetupWin(Setup):

    def __init__(self):
        Setup.__init__(self)
        self.replace_isSystemDLL()

    def replace_isSystemDLL(self):
        origIsSystemDLL = py2exe.build_exe.isSystemDLL
        def isSystemDLL(pathname):
            if basename(pathname).lower() in ("libogg-0.dll", "sdl_ttf.dll"):
                return 0
            return origIsSystemDLL(pathname)
        py2exe.build_exe.isSystemDLL = isSystemDLL

    def setup(self):
        config = self.config.get_section("setup")
	windows = [{}]
	if config["init-script"]:
	    windows[0]["script"] = config["init-script"]
	if config["windows-icon-path"]:
	    windows[0]["icon-resources"] = [(1, config["windows-icon-path"])]
        Setup.setup(self, windows,
                    {"py2exe": {"packages": self.build_package_list(),
                                "dist_dir": config["windows-dist-path"]}})
        rmtree("build")
        self.copy_data_files()
        self.create_archive()

    def copy_data_files(self):
	root = self.config.get("setup", "windows-dist-path")
        for path in chain(*zip(*self.build_data_map())[1]):
            dest = join(root, dirname(path))
            if not exists(dest):
                makedirs(dest)
            copy(path, dest)
	self.include_readme(root)

    def include_readme(self, root):
	name = "README"
	if exists(name):
	    readme = open(name, "r")
	    reformatted = open(join(root, name + ".txt"), "w")
	    for line in open(name, "r"):
	    	reformatted.write(line.rstrip() + "\r\n")

    def create_archive(self):
        config = self.config.get_section("setup")
        title = self.translate_title() + "-" + config["version"] + "-win"
        archive_name = title + ".zip"
        archive = ZipFile(archive_name, "w")
        destination = config["windows-dist-path"]
        for root, dirs, names in walk(destination):
            for name in names:
                path = join(root, name)
                archive.write(path, path.replace(destination, title + sep))
        archive.close()
        copy(archive_name, "dist")
        remove(archive_name)
        rmtree(destination)
from random import randint
from math import sin, log, pi
from array import array

from pygame.mixer import Sound, get_init

class Samples(Sound):

    def __init__(self):
        self.set_amplitude()
        Sound.__init__(self, self.build())
        # samples = array('h')
        # for x in xrange(44100):
        #     samples.append(randint(-128 * 256, 127 * 256))
        # Sound.__init__(self, samples)

    def set_amplitude(self):
        self.amplitude = (1 << (self.get_sample_width() * 8 - 1)) - 1

    def get_sample_width(self):
        return abs(get_init()[1] / 8)

    def build(self):
        pass

    def get_empty_array(self, length):
        return array(self.get_array_typecode(), [0] * length)

    def get_array_typecode(self):
        return [None, "b", "h"][self.get_sample_width()]


class Note(Samples):

    base_frequency = 440.0
    base_octave = 4
    base_name = "A"
    names = ["C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"]
    SQUARE, TRIANGLE, SAW, SINE, DIRTY = range(5)

    def __init__(self, name=None, octave=4, frequency=None, shape=SQUARE,
                 volume=1.0):
        names = self.names
        self.shape = shape
        if frequency is None:
            self.name = name
            self.octave = octave
            self.set_frequency()
        elif name is None:
            self.frequency = float(frequency)
            self.set_name_and_octave()
        Samples.__init__(self)
        self.set_volume(volume)

    def set_frequency(self):
        name, octave = self.name, self.octave
        names = self.names
        octave_length = len(names)
        offset = (octave - self.base_octave) * octave_length + \
                 names.index(name) - names.index(self.base_name)
        self.frequency = self.base_frequency * 2 ** \
                         (offset / float(octave_length))

    def set_name_and_octave(self):
        names = self.names
        octave_length = len(names)
        offset = int(round(log(self.frequency / self.base_frequency, 2) * \
                           octave_length)) + names.index(self.base_name)
        self.octave = self.base_octave + offset / octave_length
        self.name = names[offset % octave_length]

    def __repr__(self):
        return "%s%i %.2f" % (self.name, self.octave, self.frequency)

    def build(self):
        period = int(round(get_init()[0] / self.frequency))
        samples = self.get_empty_array(period)
        shape = self.shape
        if shape == self.TRIANGLE:
            self.store_triangle_wave(samples, period)
        elif shape == self.SAW:
            self.store_saw_wave(samples, period)
        elif shape == self.SINE:
            self.store_sine_wave(samples, period)
        elif shape == self.DIRTY:
            self.store_dirty_wave(samples)
        else:
            self.store_square_wave(samples, period)
        return samples

    def store_triangle_wave(self, samples, period):
        amplitude = self.amplitude
        coefficient = 4 * amplitude / float(period - 1)
        for time in xrange(int(round(period / 2.0))):
            y = int((coefficient * time) - amplitude)
            samples[time] = y
            samples[-time - 1] = y

    def store_saw_wave(self, samples, period):
        amplitude = self.amplitude
        for time in xrange(period):
            samples[time] = int(2 * amplitude / float(period - 1) * time - \
                              amplitude)

    def store_sine_wave(self, samples, period):
        amplitude = self.amplitude
        for time in xrange(period):
            samples[time] = int(round(sin(time / (period / pi / 2)) * \
                                      amplitude))

    def store_dirty_wave(self, samples):
        amplitude = self.amplitude
        for time in xrange(len(samples)):
            samples[time] = randint(-amplitude, amplitude)

    def store_square_wave(self, samples, period):
        amplitude = self.amplitude
        for time in xrange(period):
            if time < period / 2:
                samples[time] = amplitude
            else:
                samples[time] = -amplitude

    def play(self, maxtime=0, fadeout=None, panning=None, fade_in=0):
        channel = Samples.play(self, -1, maxtime, fade_in)
        if fadeout:
            self.fadeout(fadeout)
        if channel and panning:
            channel.set_volume(*panning)
        return channel
18.220.60.154
18.220.60.154
18.220.60.154
 
July 18, 2022


A new era ‼

Our infrastructure has recently upgraded ‼

Nugget Communications Bureau 👍

You've never emailed like this before ‼

Roundcube

Webmail software for reading and sending email from @nugget.fun and @shampoo.ooo addresses.

Mailman3

Email discussion lists, modernized with likes and emojis. It can be used for announcements and newsletters in addition to discussions. See lists for Picture Processing or Scrapeboard. Nowadays, people use Discord, but you really don't have to!

FreshRSS

With this hidden in plain sight, old technology, even regular people like you and me can start our own newspaper or social media feed.

Nugget Streaming Media 👍

The content you crave ‼

HLS

A live streaming, video format based on M3U playlists that can be played with HTML5.

RTMP

A plugin for Nginx can receive streaming video from ffmpeg or OBS and forward it as an RTMP stream to sites like Youtube and Twitch or directly to VLC.


Professional ‼

Nugget Productivity Suite 👍

Unleash your potential ‼

Kanboard

Virtual index cards you can use to gamify your daily grind.

Gitea

Grab whatever game code you want, share your edits, and report bugs.

Nugget Security 👍

The real Turing test ‼

Fail2ban

Banning is even more fun when it's automated.

Spamassassin

The documentation explains, "an email which mentions rolex watches, Viagra, porn, and debt all in one" will probably be considered spam.

GoAccess

Display HTTP requests in real time, so you can watch bots try to break into WordPress.

Nugget Entertainment Software 👍

The best in gaming entertainment ‼

Emoticon vs. Rainbow

With everything upgraded to the bleeding edge, this HTML4 game is running better than ever.


Zoom ‼

The game engine I've been working on, SPACE BOX, is now able to export to web, so I'm planning on turning nugget.fun into a games portal by releasing my games on it and adding an accounts system. The upgraded server and software will make it easier to create and maintain. I'm also thinking of using advertising and subscriptions to support the portal, so some of these services, like webmail or the RSS reader, may be offered to accounts that upgrade to a paid subscription.