Here are a couple functions I recently added to my .emacs file that I figured I’d share in case they’re useful to someone.
new-scratch-buffer: Creates a brand new scratch buffer, without you giving it a name.
A lot of times I will want to quickly take notes on something. Thinking of a file name and creating a file is cumbersome. Switching to a buffer named *scratch22*, for example, is cumbersome as well. Thus, I wanted a single command to create a new buffer with an automatically-picked name, that I can type into. new-scratch-buffer is working well for this, so far.
Here’s the code:
(defun new-scratch-buffer () "Creates and switches to a new scratch buffer" (interactive) (switch-to-buffer (concat "*scratch " (current-time-string) "*")))
avg: Gets a rough average of a list of numbers
This one’s probably about as basic as it gets, but I found it useful when processing a bit of data.
It’s used like this:
(avg 0 5 10 15 20 25) ... should return 12 (it should ignore remainders)
(defun avg (&rest number-list) "Averages a list of numbers" (setq sum (apply '+ number-list)) (/ sum (length number-list)))
A lot of people say they’ve “lost their faith in humanity” when another person/group does something particularly unagreeable. Here’s a thought to counteract the notion that humans are beyond the point of hope as a species, or that the species is doomed to harm the world/themselves for eternity.
When humans first evolved from other organisms (over a long period of time, yes), there was no civlization. No towns, no roads, no electricity, no mathematicians, no artists, etc, etc. Over time, these things developed and are now commonplace. Each of these professions/advances make the world better for humans to live in.
If there was something fundamentally wrong with humans (read: humans really only end up destroying the world/each other), one would think the world would look a lot different. Instead of a gigantic civilization with a majority people working to better themselves and the world, everyone would be robbing every other person/making the world worse. This does not seem to be the case.
My argument boils down to: If humans are fundamentally “bad”, why does the vast majority of humanity spend the vast majority of their time doing things that are “good”? Learning, entertaining themselves, socializing, improving in a discipline, etc. If humans were fundamentally “bad”, you would expect to see the majority of people stealing from other people, damaging the infrastructure set up by others, and making the world a less friendly place for humans to live in.
The reason to have faith in humanity then, is that if humans overall try to make the world a better place more often than not, over time the world should become a better place to live in for humans.
One technique I’ve used quite a bit for determining if a proposition is absurd or not is to place myself in the mindset of a peasant living in the Middle Ages. I do not claim this is a new technique, but it seems like a technique that’s useful for analyzing claims.
For example, I was recently reading a few peoples’ takes on the recommendation that people follow their dreams. The question is whether or not the recommendation for people to follow their dreams at all costs is good advice or not. How would a Medieval peasant respond to you if you asked them to follow their dream of becoming the most famous bard in their country (yes, I’m relying on tropes big-time)?
If the proposition sounds absurd when proposed to a hypothetical peasant, that might indicate that the proposition is faulty.
Just a quick note for anyone that has this same problem in the future:
While making a game in MonoGame, I had problems playing SoundEffects. Basically, I would:
- create a SoundEffect variable
- do a Content.Load<SoundEffect>(“EffectFileName”)
- Later call soundEffect.Play() to try to play the sound
The above sequence ended up in silence – no exceptions, no indication that something went wrong. To fix this, I found a post here: https://monogame.codeplex.com/discussions/397588 mentioning to use Song rather than SoundEffect. So, I followed the instructions at here: http://rbwhitaker.wikidot.com/another-way-to-do-audio-in-xna to play the sound effect as a Song instead, and it’s worked so far.
FYI in case this helps someone out.
An (in my mind) interesting question I’ve thought about before is when humans will run out of new music to create. By that I mean, when will we reach a point where (within certain parameters) every possible combination of music has been tried? Let’s try to figure that out.
For the purpose of this post, I’m going to make some very conservative initial assumptions.
1) We’re only interested in discussing orchestral music. Thus, a rough upper bound on the length of the pieces produced will be ~40 minutes.
2) Since we’re only discussing orchestral music, we’ll only focus on a standard set of orchestral instruments. To keep things small, we’ll use Wikipedia’s definition of a Classical orchestra:
- 2 Flutes
- 2 Oboes
- 2 Clarinets
- 2 Bassoons
- 2 French Horns
- 2 Trumpets
- 2 Timpani
- 10 Violin 1s
- 8 Violin 2s
- 6 Violas
- 4 Cellos
- 2 Double basses
3) For further simplification, we’ll assume that each above instrument of the same type will be playing the same notes. That is, Cello 1 plays the same notes as Cello 2, as Cello 3, etc. So this means we have 12 “instruments” to choose from.
4) We assume that each instrument only plays the standard notes found on a piano (A through G, plus sharps/flats). No special effects (ie pizzicatto, rim shots on a snare drum, etc) are allowed.
Now, our orchestra is made of 12 instruments. Let’s break time into a series of discrete points at which either a note can be played or not played by all of the 12 instruments. So, at any point in time, each instrument can play 13 possible notes (the 12 of the scale, or play nothing).
By this token, at any point in time, there are
13 * 13 * 13 * 13 * 13 * 13 * 13 * 13 * 13 * 13 * 13 * 13 = 13^12 combinations of notes that could be played. This is 23,298,085,122,481 (> 23 trillion!) possible note combinations.
How about the number of notes that could be played in two consecutive time slots? That would result in 13^12 * 13^12 = 13^24 possible notes. This is ~542 septillion note combinations.
Now, you might say, certain combinations of notes are very displeasing, and it’s unlikely that a composer would pick a certain combination of notes on multiple instruments at the same time.
If that’s the case, we’ll assume that each instrument can play only a single “good” note, or nothing, at any given time. So, at any time, there are 2*2*2*2*2*2*2*2*2*2*2*2 = 2^12 = 4096 notes possible.
In this case, after 4 time slots, we will have 2^12 * 2^12 * 2^12 * 2^12 = 2^(12*4) = 2^48 = ~281 trillion possible note combinations. Consider that, if we only let the orchestra play in units of 16th notes, we would have 281 trillion musical possibilities in a fourth of a single measure.
One sees that the number of note combinations that we have to work with grows extremely quickly with the length of music being played. And keep in mind that this is with somewhat conservative initial assumptions. If we wanted to let loose, we could use Wikipedia’s definition of a “Modern orchestra”, which would include 128 instruments (counting each instrument of each type individually). Which would mean there are 13^128 notes at any given time that the orchestra could play. And of course, this does not consider non-orchestral instruments, special effects on instruments, electronic music, etc etc.
So in regards to running out of new music, I think we’re safe for awhile.
Note: I’m a Computer Science student, not a mathematician. Please correct me if there’s a flaw in the above
reasoning! This is what we’re discussing in a Discrete Mathematics course.
I’ve recently started my first job where I’m getting to do some software development (yay!) and one tool that I’ve picked up and come to love is the debugger.
Before working at this job, I had always wanted to pick up the debugger for my personal projects, as I’d read that it’s a very powerful tool. However, a lot of the documentation I read about the debugger didn’t make it clear exactly what benefit I would get out of learning to use it. Or rather, I was not excited about the idea of just being able to look at variable values.
I would like to add an extra reason for learning the debugger, in the hopes that it will entice some people to pick up this powerful tool.
One of the coolest things about using the debugger I’ve found is that it basically gives me interactive API documentation for what I’m working with. If I’m looking for a certain method, one option is to look up the API documentation for the library you’re using and search for a method that matches what you want. This works, but it makes us switch from our development environment to a web browser, which takes time, can be distracting, etc. Not ideal.
This is an image of a Visual Studio feature called the Watch Window:
This feature’s also available with most other debuggers I think, so you’re not limited to Visual Studio. The Watch Window lets you enter variables that are used in your program and look at their values while the program is running. In the above image, the “Name” column tells you the names of the variables you’re looking at. Value tells you the value of those variables. And Type is the type of the variable. Simple enough.
The cool part though, I think, is what’s happening in the Name column. “current” is a struct in this program, and it has the fields “time”, “port”, and “analog”. “analog” is an array, and by clicking the +/- sign by its name, you can look at the values in the array while the program is paused.
Not only that, but if analog was an array of objects, and those objects had fields, you could look at the fields of each object in the array.
The best part of this feature, I think, is that if you are working with unfamiliar code (say you’re using a library), you can look at the objects and their fields in this same way to explore the objects that make up your program.
You can do the same thing by browsing through API documentation, but doing this process through a debugger is so much more convenient that I think it’s definitely worth learning to do, at least if you work with unfamiliar code somewhat often.
Also, the first 2.5 minutes of the following video provides a good demonstration of the Watch Window in action: https://www.youtube.com/watch?v=3t8QUlp5kcs
Just went to my first Aikido session. I have been quite out of shape for the last while, which definitely showed through as I was practicing. I’m currently very confused – we ran over around 8 or 10 moves and I did not feel like I truly got the hang of any of them, although I did make some good progress with a few of them. My homework for this Friday: learning to properly fall and get back up. Confusing but very fun so far. Looking forward to getting over the initial learning curve and feeling comfortable executing moves. For now though, lots and lots of simple falling exercises.