Two Approaches to Concurrent-Write Safety in Django

Sometimes when dealing with Django models accessed by multiple people, you want a way to make sure two requests don’t perform writes at the same time.

For example, lets say you run a poker site, and you have 3 users playing a poker game together in the browser.

poker_game

You want only one active player to be able to perform game actions, and you want only one action accepted at a time.  Imagine the catastrophe if your active player could open the game in 2 tabs, fold his hand in one, and bet in the other simultaneously! Continue reading “Two Approaches to Concurrent-Write Safety in Django”

Sharing state between Redux reducers

When writing an app using Redux and React, you may run into the common problem of having to share state between multiple components in your app.

Don’t worry, you aren’t the first to have this problem, here are some resources to help you out.

Your options:

  • don’t use combineReducers (write your own that shares state/selector between two components)
  • use thunk middleware
  • pass selectors on global store through all your actions
  • call window.store.getState().myreducer.myvalue directly to get the state (worst option)

On Managing state hierarchy in general:

Specifically on sharing state between reducers:

Related Documentation:

Taking iTunes a step further

In recent years, iTunes has become more of a money-making machine for Apple than it ever has been, so of course they’ve invested lots of dev time into making the storefront and payed portions of it beautiful user experiences.

Unfortunately for power-users, the energy they’ve diverted into Apple Music has left the song-management and iCloud syncing riddled with bugs that have had surprising longevity over several major versions.

For example:

Renaming an album or artist in iTunes prompts suggestions to fill in the box as you type. Unfortunately, there was no way to NOT choose the auto-suggested item by backspacing or clicking out.   This lead to having to add spaces after artist names in order to get ‘Cher ‘ without being forced to accept ‘Cherish’ by the autoprompt.   This issue was in iTunes for over 20 months before being fixed in the latest release (12.2.3).

Screen Shot 2016-01-13 at 8.03.27 PM

So what’s next?

For a long time I’ve been thinking about writing a replacement to iTunes.  It’s surely a mammoth task, but at heart it’s just a database interface with a media player built in.  It involves dealing with lots of tabular data, and providing a way to edit and organize it, comparable to a SQL frontend like phpMyAdmin.  In other ways it’s similar to Gmail, where you have some content with metadata that you sort out of a central pool using labels and stars.

We can learn from the strengths of iTunes:

  1. Add arbitrary SQL-style queries to search (a la smart playlists)
  2. Songs that act like normal ones but are stored in the cloud (a la Apple Music)
  3. Social network features like sharing music (a la iTunes Pulse)
  4. Machine learning on your music library to suggest playlists (a la Genius)

But we can add so much more:

  • Add songs from web to library without downloading them (like 1001tracklists.com)
  • Soundcloud-style public feeds of your❤ music (or any other playlist)
  • Songkick integration to flag your artists that have nearby shows
  • “Inbox” for music that lets you treat music like email, incoming is selected from friends, soundcloud/bandcamp, machine learning, and you can “archive” music to your library/playlists, or delete it to never see it again (~10 new songs/day)
  • Automatic word2vec trained on your genres to make playlists along certain moods
  • Machine-learning analysis on your skips and plays for “smart shuffle”
  • Like and dislikes that have timestamps showing when you liked them
  • Shazam-style analysis on songs to correct ID3 tags and album art
  • Ability to “follow” other peoples streams in your library
  • Ability to live-broadcast what you’re playing like a radio channel to mobile users around you
  • Ability to publish your music feed as RSS/embed it in a website
  • Easy labels system for songs (like Gmail)
  • Smart, custom deduplication that will prefer higher quality audio files and merge ID3 fields
  • DJ features that let you mark/flag individual points or sections of songs with tags, and optionally split them into separate files (as references) (also great for hour long radio shows to tag individual songs)
  • Ability to share entire playlists or folders
  • Full play history stored separate from last played & last skipped
  • Easy lyric fetching and display, including inline rap-genius explanations like lots of Chinese music apps

 

How?

This could easily be done as a self-hosted web-app or native app that has access to local files on an HD, along with an internet connection and graceful degradation if one is not available.

The only way to keep it legal is to make it self-hosted, so that no central authority is collecting revenue for played songs, or controlling what sources are used to broadcast music.

It could also theoretically be done using iTunes plugins, a separate app, and a FUSE-like file system to create mock-audio-files for web songs that fetch audio on the fly when opened.

I’ll put it on my rapidly-glowring “next open source project to start but never finish” list.

Augmented Reality Social Networking

For several years now I’ve been designing and thinking out an invention in my head.  It started out as the stereotypical “eureka!” moment in the shower and then moved on to a baby of thought that I nurtured on every subway ride to school.  The reason I think of it the most on subways is because the core market for this idea would be commuters who have to take public transport, although the idea could be extended to private cars.

The idea is: visual-overlay virtual reality social networking

It has been approached many times before, the closest I’ve seen to my idea exactly is a project called Google Glass, and they almost hit my idea on the nail, except for a few key features.  The core idea is that you take a technology that lets you overlay information on your vision, be it glasses or contact lenses (or even a cranial implant), and you hook it up to a network that everyone else is connected to.

 

Offline info: Name, Date of Birth, blood type, house address etc.

Online info (maybe Facebook linked): Friend networks, maps, music, movies

 

Core Features: Flags, Tags, currently playing music for each person, destination, nationality, languages, interests, current website, music management

 

Technologies required: display: [lcd contact lenses/retinal projection glasses/HUD glasses], energy storage: [induction coupling, batteries], processing power, human interface: [bone conduction for humming commands, jaw movement racking, eye tracking, finger movement, phone linking, computer syncing, control jewelry], audio output: [headphones, implant], networking radios: [wifi, 4G, whisper net, bluetooth], cameras, audio input, environment tracking: [face recognition, distance measurement, compass, GPS, possibly synced with phone]

Lucid Dream Goggles

Based on: http://hackaday.com/2012/04/19/do-anything-with-the-help-of-lucid-dreaming-goggles/

http://www.gocs1.com/gocs1/Psionics/Lucid-Dream-Goggles.htm

I built these simple Lucid Dream goggles to achieve what I’ve been trying for months now, to have a solid dream that I am aware of, and able to control.  I’ve been fascinated with the science of Lucid Dreaming, and being able to invent and explore infinite environments while sleeping.  It finally makes those 8 hours of the night (more like 5) seem less of a waste to me.

Arduino after the break.

Continue reading “Lucid Dream Goggles”

Thermite

Also an explanation before I ignite it here: http://www.youtube.com/watch?v=WFFTTS2VoDY

Thermite is an exothermic redox reaction involving the trading of oxygen atoms between the Iron (III) oxide and the Aluminum.  This is the ignition of the thermite mixture I created out of 1/8 magnesium powder, 4/8 Iron (III) oxide, and 3/8 Aluminum powder. Ignited with a magnesium strip and some magnesium powder dusted on top. The metal bowl is placed on top of an aluminum computer heatsink.

This slideshow requires JavaScript.

Scary How Accurate This Is:

Personality Type Report for Nick Sweeting, full MBTI assessment also carried out.

EXTROVERT

You are social and outgoing. You are most comfortable when with other people and experiencing the world first hand. Interaction with others and first hand experiences energize you. It is not unlike you to start conversations with strangers. You have a preference for the outer world: people, activities, and things. Other people provide you with a mirror, sounding board to help you develop ideas and plans. Being alone may sap your energies. Your concept of the world is derived from experiencing it firsthand and then drawing conclusions.

INTUITIVE 

While you do process information through your senses you add a twist to your processing by relying on intuition and serendipity. You look for undercurrents of meaning and abstractions in what you experience physically. You do not just see things just as they are, but as what they could be. While you may rely on common sense at times, you trust inspiration far more.

PERCEIVING

You like to have as much information as possible before making a decision. Putting off a final decision until the last moment does not make you uncomfortable. Indeed once a decision is made, a course plotted, you may feel a bit uneasy, because you feel bound to a certain course of action. You would much prefer to wait and see what happens. You enjoy the opportunity to improvise. Commitments are not etched in stone to you, and are changeable.

THINKING 

You evaluate data and reach conclusions by using your ability to apply logical, objective analysis to the information before you. Your thinking process values consistency and fairness over the affect your decisions will have on others. You compare courses of action logically and make your choices based upon what consequences you see them as having. If there is something wrong with a plan, you are the one to ferret it out. It is important to remember that this does not mean you are cold and unfeeling, but that your thinking process is analytical.

Your Personality Type

Extrovert/Intuitive/Thinking/Perceiving

You are outspoken and love a challenge or debate. Social by nature, you are very charming and witty. You value your freedom. You can be very creative and resourceful, spontaneous and impulsive. You are a risk-taker who is aware of all the possibilities your actions will create. You are curious about almost everything.

In relationships you are charismatic, quick-witted, and can keep up your end of any conversation. Instead of judging your friends and loved ones, you use your energies to understand the motivations behind their behavior. You are intellectually and spiritually growth oriented, and do well with a partner that shares these qualities. You also have a bit of the adventurer in you and do well in the company of like-minded people. Like all of life’s experiences, you want your relationships to be full of excitement and adventure.

Famous People of Your Type:

John Adams, James A. Garfield, Rutherford B. Hayes, Theodore “Teddy” Roosevelt, Thomas Edison, Lewis Carrol, Suzanne Pleshette, George Carlin, Valerie Harper, John Candy, John Sununu, Weird Al Yankovick, Alfred Hitchcock, Tom Hanks.

Occupations Suited to Your Type Include:

Actor, advertising director, lawyer, programmer, engineer, entrepreneur, inventor, marketer, doctor, psychologist, social scientist, professor, and writer

Guess What Element I am…

I am a useful element with many practical applications, however I am not found readily and many silly humans trade me for money.  I am a transition metal that can be easily mixed with other metals to form useful alloys that conduct electricity and heat extremely well.  On my own, no other metal can rival my electrical conductivity.  My contact resistance is also the lowest in the periodic table, meaning if you brushed two of me together, sparks would fly (technically they wouldn’t, sparks=high resistance)! If you used me to make your house’s electrical wiring, you’d be broke, but your lights would be slightly brighter.  Like copper, I have natural disinfectant properties and can be used as an antiseptic when compounded with other elements.  My thermal conductivity is higher than all other elements in the periodic table!  I am commonly used for my stain and tarnish-resistant properties and am occasionally used to coat silverware. Apart from the ultraviolet spectrum, I am an excellent reflector of light and can be used to make thin shiny coatings for applications in photography.  My halide form can even absorb light in such a way that it records patterns and retains them for short periods of time!  I am slightly harder than my oft-coveted counterpart used to back the federal reserve, however we are both used to make Olympic medals.  Strangely enough, I am sometimes used in a special type of food coloring, but it’s not approved by the FDA so don’t ingest me!  Controversially, the iodide form of me was used several times in China to control the weather, most notably around the 2008 Olympics to prevent it from raining in the city area.