Skip to content

Instantly share code, notes, and snippets.

View audionerd's full-sized avatar

Eric Skogen audionerd

View GitHub Profile
@audionerd
audionerd / .block
Last active February 26, 2017 07:10
Oscar Ballot Bingo 2017
We couldn’t find that file to show.
@audionerd
audionerd / react-native-widont.js
Created May 27, 2016 18:29
Widon’t for React Native
//
//
// Widon’t for React Native
// Simply uses Unicode \u00a0 instead of  
//
// via http://webservices.blog.gustavus.edu/2007/03/20/shaun-inmans-widont-ported-to-javascript/
export const widont = (text) => text.replace(/([^\s])\s+([^\s]+)\s*$/, '$1\u00a0$2')
// A script to click each download button on this page: https://soundcloud.com/user48736353001/sets/all
// run it in the Developer Console in Chrome with the page open.
// Worked for me! ¯\_(ツ)_/¯
// I still can't figure out how Metal Beat was recorded. It's INSANE.
list = document.getElementsByClassName('sc-button-download')
[].forEach.call(list, function(el) {
var evt = document.createEvent("MouseEvents")
evt.initMouseEvent("click", true, true, window, 1, 0, 0, 0, 0, false, false, false, false, 0, null)
el.dispatchEvent(evt)
})
@audionerd
audionerd / gist:4703b4ed3ddad82999f7
Created October 24, 2014 21:47
Replacing Paperclip file basename with UUID on upload (is there a better way?)
# replace file basename with a UUID when uploaded
# e.g.: avatar.jpg becomes 41bf830f-80cf-4efe-ad90-3b29bc6708b5.jpg
# but don't regenerate a UUID each time file url is accessed
class User < ActiveRecord::Base
has_attached_file :avatar, path: ":basename.:extension"
before_validation { set_avatar_file_name }
def set_avatar_file_name
# replace any NEW filename with a UUID
@audionerd
audionerd / rails-and-imgix.md
Last active September 1, 2015 17:24
Configure Rails to serve image files via Imgix

Configure Rails to serve image files via Imgix

Once you have Imgix setup to pull in images from your server, you'll want to tell Rails which assets to serve via Imgix and which to serve directly.

Something like the following in config/environments/production.rb will help:

config.action_controller.asset_host = Proc.new { |source|
  if source.ends_with?('.jpg') || source.ends_with?('.gif') || source.ends_with?('.png')
 # the image host
@audionerd
audionerd / cool-nand-bames.md
Last active June 8, 2019 19:22
Celebrity Spoonerism Band Names

A spoonerism is “an error in speech or deliberate play on words in which corresponding consonants, vowels, or morphemes are switched (see metathesis) between two words in a phrase”.

Please help me compile a list of actual artists (e.g.: released music, maybe even toured) whose names are permutations of the names of other artists or celebrities.

  • Berry Weight
  • Bupsin Jieber
  • Com Truise
  • Edit Murphy
  • Gnarls Barkley
  • Hoodie Allen
@audionerd
audionerd / Forwarding ports from a docker container with Vagrant 1.6.md
Last active June 25, 2019 20:45
Forwarding ports from a docker container with Vagrant 1.6

Forwarding ports from a docker container with Vagrant 1.6

Vagrant 1.6 has a really nice feature which allows you to run a docker environment from any machine that can run Vagrant (even a Mac)

Behind the scenes, Vagrant creates a host VM which runs the docker containers.

The "gotcha" is: Vagrant won't automatically forward ports all the way back from the container->vagrant host VM->your mac. You have to do that step manually, by configuring your own host VM for Vagrant to use for hosting docker containers with. That host VM is told what ports to open.

Here's how I set up a local Wordpress development testing container.

@audionerd
audionerd / getLineIntersection.coffee
Last active August 29, 2015 14:03
Line Segment Intersection
# via http://stackoverflow.com/questions/563198/how-do-you-detect-where-two-line-segments-intersect
# http://mathworld.wolfram.com/Line-LineIntersection.html
getLineIntersection = (x1, y1, x2, y2, x3, y3, x4, y4) ->
s1_x = x2 - x1
s1_y = y2 - y1
s2_x = x4 - x3
s2_y = y4 - y3
s = (-s1_y * (x1 - x3) + s1_x * (y1 - y3)) / (-s2_x * s1_y + s1_x * s2_y)
t = (s2_x * (y1 - y3) - s2_y * (x1 - x3)) / (-s2_x * s1_y + s1_x * s2_y)
@audionerd
audionerd / upload-to-docker-container-from-host.md
Last active August 29, 2015 13:56
Upload a file from a host filesystem to a running Docker container

Upload a file from a host filesystem to a running Docker container

The best way to do this is probably via docker volumes. For dokku, check out dokku-persistent-storage

But here's a quick hack using netcat anyway.

Assuming we've found the container ID (e.g.: via docker ps):

$ CID=f7a29d6dc8e4
@audionerd
audionerd / token.rb
Last active December 17, 2015 07:58
A minimal re-usable module for "token" slugs on ActiveRecord models (AKA shortcodes, tiny urls)
# token.rb
# A minimal re-usable module for "token" slugs on ActiveRecord models (AKA shortcodes, tiny urls)
#
# USAGE
#
# class Project < ActiveRecord::Base
# include Token
# end
#
# see also: