Showing posts with label programming. Show all posts
Showing posts with label programming. Show all posts

Tutorial: Run Swift on Windows 10 the Easy Way (Using Linux Subsystem)

Posted: Wednesday, 7 September 2016

Running Apple's Swift programming language on Windows 10 is as simple as 1, 2 and 3.
  1. Setup the Linux Subsystem for Windows 10 Anniversary Edition
  2. Run sudo apt-get install build-essential (and optionally sudo apt-get install clang)
  3. Download, and Run swift!
  4. Note: for each of these links you can click or scroll down for more
Alternatively, the video below demonstrates the steps in motion...
https://www.youtube.com/embed/Z0PZc7WqPtE


And that's it.

Just note that both technologies are unstable as of September 2016
  • Swift is a fairly immature programming language
    • Due to the absence tools like a beautifier - though third-party tools such as Haaakon's SwiftFormat https://github.com/haaakon/SwiftFormat does the trick
    • Due to missing tangible desires such as bug reports & support from fellow Windows users of Swift (of which there is none)
    • And with breaking changes each major version of Swift (which might be why the Swift 1.0 code you found won't work on Swift 2.2 or even Swift 3.0 beta).
  • And the Windows Subsystem for Linux (WSL) is still in beta, with normally trivial tasks, such as interacting with the subsystem programmatically, almost impossible: https://github.com/Microsoft/BashOnWindows/issues/


Setting up WSL

To set up the Windows subsystem for Linux, an official guide can be followed here: https://msdn.microsoft.com/en-us/commandline/wsl/install_guide
Here's a summary:
  • Start Menu -> Search "Turn Windows features on or off"
  • Scroll Down to "Windows Subsystem for Linux (Beta)", and click the checkbox
  • Restart your computer, it should display a screen along the lines of "Configuring Windows", similar to a Windows Update
  • Once your computer has restarted, launch a normal Windows Command Prompt: Start Menu -> Search "Command Prompt" (or alternatively, cmd)
  • Type the command "bash", and press enter
  • Accept the T&C (or not, skipping this section and booting into Ubuntu is effectively the same)
  • Wait for the ~200MB Ubuntu Subsystem Image to Download, Extract and Install

And that's it! A mini non-Linux environment within Windows. Similar to how OS X does it, only 10 years behind.

Takes around 30 minutes.

Those Linux commands


With how administrative/root privileges work in WSL, you don't need "su/sudo" to run what are normally root commands (if you've skipped setting up the root user).
apt-get install build-essential should work on its own.
The build-essential package is required to run Swift. Without it, Swift would just fail in executing scripts. Unfortunately, this is quite a large package on Ubuntu, and even on Windows its no exception.
So run the command and wait it out, a tip to speed up the process of downloading packages is shown in the video.
Running apt-get install clang allows for Swift code compilation support in Windows via swiftc (swiftc with build-essentials alone does not work). Interestingly the resulting binary that swiftc compiles is a native Linux/Ubuntu ELF instead of a Windows exe.

Takes around 30 minutes.

Swift

Download Swift from here: https://swift.org/download/, note that you'd want the Ubuntu 14.04 version, if still offered.
Extract the archive just like you would on Ubuntu (or extract it using the Windows method, whichever you prefer), and run /usr/bin/swift through bash.

Takes around 10 minutes.


And that's it! Swift (the programming language) running on Windows 10 using the Windows Subsystem for Linux!

Although REPL doesn't really work, and you're not exactly working with native Windows goodness.




Better Python Standard Library Autocompletion for Notepad++

Posted: Thursday, 7 July 2016

Download: http://static.extramaster.net/python.xml.zip (476kb download - 3,367kb extracted)
Note that there's 13,563 definitions included, so any application that attempts to parse XML structure will have a bad time.

Before:


After:




Using the Notepad++ "python.xml" generator at: https://sourceforge.net/projects/npp-python/, in conjunction with a script that imports all Python modules: http://stackoverflow.com/questions/1206832/importing-the-entire-python-standard-library, on a computer with a fresh Python install, nabs a "python.xml" file with definitions and autocomplete entries for all Python Standard Library modules.


Download: http://static.extramaster.net/python.xml.zip
Or if github gists are your thing: https://gist.github.com/extramaster/9d0b7eba99a9708eb3f71ae95bcd42b5

The "python.xml" file should be placed in "C:\Program Files (x86)\Notepad++\plugins\APIs" or "C:\Program Files\Notepad++\plugins\APIs", overwriting the pre-installed copy.

In case you want to revert back to the pre-installed "python.xml" file, here's a copy: http://static.extramaster.net/python_original.xml.zip

Here's a list of all of the Python Standard Libraries used in the creation of the autocomplete file:
import _bsddb
import _ctypes
import _ctypes_test
import _elementtree
import _hashlib
import _msi
import _multiprocessing
import _socket
import _sqlite3
import _ssl
import _testcapi
import _tkinter
import bz2
import pyexpat
import select
import unicodedata
import winsound
import BaseHTTPServer
import Bastion
import CGIHTTPServer
import ConfigParser
import Cookie
import DocXMLRPCServer
import HTMLParser
import MimeWriter
import Queue
import SimpleHTTPServer
import SimpleXMLRPCServer
import SocketServer
import StringIO
import UserDict
import UserList
import UserString
import __future__
import _abcoll
import _osx_support
import _pyio
import _strptime
import _threading_local
import _weakrefset
import abc
import aifc
import antigravity
import anydbm
import argparse
import ast
import asynchat
import asyncore
import atexit
import audiodev
import base64
import bdb
import binhex
import bisect
import bsddb
import cProfile
import calendar
import cgi
import cgitb
import chunk
import cmd
import code
import codecs
import codeop
import collections
import colorsys
import commands
import compileall
import compiler
import contextlib
import cookielib
import copy
import copy_reg
import csv
import ctypes
import dbhash
import decimal
import difflib
import dircache
import dis
import distutils
import doctest
import dumbdbm
import dummy_thread
import dummy_threading
import email
import encodings
import filecmp
import fileinput
import fnmatch
import formatter
import fpformat
import fractions
import ftplib
import functools
import genericpath
import getopt
import getpass
import gettext
import glob
import gzip
import hashlib
import heapq
import hmac
import hotshot
import htmlentitydefs
import htmllib
import httplib
import idlelib
import ihooks
import imaplib
import imghdr
import importlib
import imputil
import inspect
import io
import json
import keyword
import lib2to3
import linecache
import locale
import logging
import macpath
import macurl2path
import mailbox
import mailcap
import markupbase
import md5
import mhlib
import mimetools
import mimetypes
import mimify
import modulefinder
import msilib
import multifile
import multiprocessing
import mutex
import netrc
import new
import nntplib
import ntpath
import nturl2path
import numbers
import opcode
import optparse
import os
import os2emxpath
import pdb
import pickle
import pickletools
import pipes
import pkgutil
import platform
import plistlib
import popen2
import poplib
import posixfile
import posixpath
import pprint
import profile
import pstats
import py_compile
import pyclbr
import pydoc
import pydoc_data
import quopri
import random
import re
import repr
import rexec
import rfc822
import rlcompleter
import robotparser
import runpy
import sched
import sets
import sgmllib
import sha
import shelve
import shlex
import shutil
import site
import smtpd
import smtplib
import sndhdr
import socket
import sqlite3
import sre
import sre_compile
import sre_constants
import sre_parse
import ssl
import stat
import statvfs
import string
import stringold
import stringprep
import struct
import subprocess
import sunau
import sunaudio
import symbol
import symtable
import sysconfig
import tabnanny
import tarfile
import telnetlib
import tempfile
import test
import textwrap
import this
import threading
import timeit
import toaiff
import token
import tokenize
import trace
import traceback
import types
import unittest
import urllib
import urllib2
import urlparse
import user
import uu
import uuid
import warnings
import wave
import weakref
import webbrowser
import whichdb
import wsgiref
import xdrlib
import xml
import xmllib
import xmlrpclib
import zipfile
import Canvas
import Dialog
import FileDialog
import FixTk
import ScrolledText
import SimpleDialog
import Tix
import Tkconstants
import Tkdnd
import Tkinter
import tkColorChooser
import tkCommonDialog
import tkFileDialog
import tkFont
import tkMessageBox
import tkSimpleDialog
import ttk
import turtle

Playing MIDI tracks from an Arduino

Posted: Thursday, 29 October 2015

Link: https://www.extramaster.net/tools/midiToArduino/

Table of Contents (TOC)


^ TOC

So, you just learnt how to control a buzzer using an Arduino, but you want more then just simple beeps and hums - you want to assert your dominance over the sound-waves to show-off how well you can control the buzzer.

Cynical? Well there's no denying that it's a sentiment that we all share once we learn something new, but hey, if you've managed to acquire and get an Arduino working, then that's quite far an accomplishment.

A quick search of "music buzzer arduino" should point you to the right direction, but no-one has the time to individually hand-code and map the midi-tones to the frequency values that the Arduino's Tone function requires, especially if you're working with a long MIDI track.

The solution?

https://www.extramaster.net/tools/midiToArduino/

Circuitry

^ TOC

Wiring the Buzzer is trivial, just place the buzzer on two strips (on a breadboard), connect one strip to Pin 11 on your Arduino, and the other strip to the Ground.

Demo

^ TOC
https://www.youtube.com/watch?v=B1oHQzp1P3w
https://www.youtube.com/watch?v=4FDFpycApP4

Note that this also works with Raspberry Pis.
https://www.youtube.com/watch?v=HOisQF-JaS0


Steps/Instructions

^ TOC
  1. Visit: https://www.extramaster.net/tools/midiToArduino/
  2. Upload a midi file
  3. Choose the track that you want to export
  4. Copy the resulting code to a new Arduino sketch

Sample Exported Arduino Code

^ TOC

Didn't get the midi file to work with the web app? No worries, here are some sample code generated by the web-app

Midi: Fleuron-128 - Heaven - Song: Shaun Frank & KSHMR - Heaven (feat. Delaney Jane)

Midi: Antergy - DB15 - Song: Atmozfears - DB15

Midi: Kevin Fishburne - Terra's Theme - Song: Final Fantasy VI - Terra's Theme

https://www.extramaster.net/tools/midiToArduino/

Final Notes

^ TOC Oh, and by the way, it appears that you can leave the Piezo buzzer running on loop for an extensive amount of time (24 hours+), so if you want to play a midi indefinitely, you can use an Arduino to do so.

Unfortunately, you can only have one tone running at a time, so if your midi track has multiple keys being played simultaneously, expect some wacky results. (here - try this: http://www.forelise.com/midi - "Track 2: Acoustic Grand Piano - Piano - Fr Elise")
If you attempt some protothreads hack, then expect only one Piezo buzzer to work (at a time). But if you're game, and want to give using protothreads a try:





https://www.extramaster.net/tools/midiToArduino/