Skip to content

Instantly share code, notes, and snippets.

View joshmn's full-sized avatar
🔒
@ FCI Thompson

joshmn joshmn

🔒
@ FCI Thompson
View GitHub Profile
@joshmn
joshmn / gist:f4eb8797939da1dadfb1
Created June 5, 2014 21:11
MLB Draft 2014: If teams were comprised solely of players they drafted (results of each team)
require 'httparty'
require 'nokogiri'
page = HTTParty.get('http://www.brewcrewball.com/2014/6/5/5328814/mlb-draft-players-roster-construction-brewers-yankees-red-sox-dodgers')
doc = Nokogiri::HTML(page.body)
i = 0
doc.css('#article-body h3').each do |t|
next if t.text.empty?
team = t.text
@joshmn
joshmn / gist:c5f05792a7afb654c52f
Created June 5, 2015 21:12
simple up/down/remove/add for select
<div class="row">
<div class="col-sm-4">
<input type="text" placeholder="Item To Add" class="form-control arrayable_item">
</div>
<div class="col-sm-8">
<a class="create btn btn-info add_to_arrayable" href="#"><i class="icon-plus icon-white"></i> Add To List</a>
</div>
</div>
<div class="row">
@joshmn
joshmn / _form.html.erb
Created June 9, 2015 00:49
Multiple specific cropped positions a single Paperclip record
<!-- to your form partial. yes, you could do this more dynamically, but for illustrative purposes. -->
<select id="style_select">
<option></option>
<option value="cover" data-style-options='{"option": "setCropBoxData", "data": {"width": 1200, "height": 628}}'>Cover</option>
<option value="medium" data-style-options='{"option": "setCropBoxData", "data": {"width": 628, "height": 840}}'>Medium</option>
<option value="small_sq" data-style-options='{"option": "setCropBoxData", "data": {"width": 470, "height": 470}}'>Small Square</option>
<option value="thumb" data-style-options='{"option": "setCropBoxData", "data": {"width": 128, "height": 128}}'>Thumb</option>
</select>
<% %w{cover large medium medium_sq small small_sq thumb}.each do |w| %>
<%=w%>: <input class="form-control style_data" data-style-for="<%=w%>" type="text" name="image[crop][<%=w%>]" placeholder=""><br/>
@joshmn
joshmn / spotify.rb
Created June 29, 2015 17:45
Import Artists from List to Spotify
require 'rspotify'
RSpotify::authenticate("key", "secret")
artists_list = ["12th Planet", "3LAU", "4B", "A-lusion", "Aaron Jackson", "Above & Beyond", "AC Slater", "Adrenalize", "Adventure Club", "Afrojack", "Alesso", "Alex Kidd", "Alison Wonderland", "Aly & Fila", "Amine Edge & DANCE", "Andrew Rayel", "Andy C", "Armanni Reign", "Armin van Buuren", "Art Department", "Arterial", "Arty", "Astrix", "Astronomar", "ATB", "Audien", "Audiotricz", "Avicii", "AWE", "Baggi Begovic", "Barrels", "Bassnectar", "Baumer", "Benny Benassi", "Bingo Players", "Bixel Boys", "Black Sun Empire", "Blaise James", "Blasterjaxx", "Bones", "Brandon Elliot", "Breach", "Breathe Carolina", "Brennan Heart", "Brillz", "Burn Unit", "Calvin Harris", "Camo & Krooked", "Carl Cox", "Carnage", "Chevy Chase", "Chris Liebing", "Chris Lorenzo", "Chuckie", "Chus & Ceballos", "Cookie Monsta", "Coone", "Cosmic Gate", "Crisis Era", "Crizzly", "CSTNZA", "D-Block & S-te-Fan", "Da Tweekaz", "Dada Life", "Dannic", "Danny Avila", "Darksiderz", "Darren Styl
@joshmn
joshmn / seed data
Created July 30, 2015 20:36
seed dat
require 'json'
namespace :seed_data do
task products: :environment do
file = File.new("#{Rails.root}/products.json")
json_array = JSON.parse(File.read(file))
json_array.each_with_index do |json_product, index|
break if index >= 100
# hack of the year
require 'json'
class String
def string_between_markers marker1, marker2
self[/#{Regexp.escape(marker1)}(.*?)#{Regexp.escape(marker2)}/m, 1]
end
end
file = File.read('schema.rb')
@joshmn
joshmn / Readme
Last active September 18, 2015 18:59
ActiveAdmin Logs
Inspired by Gitlab's Admin Logs (app/controllers/admin/logs_controller.rb)
Probably should put things in lib. Put in one file for breviety.
@joshmn
joshmn / gist:220fe03bc162118e23da
Created November 27, 2015 22:59
mediawiki backup to s3
# backup
echo Performing Mediawiki backup...
# Perform MySQL dump
echo Performing MySQL dump...
mysqldump <database_name> -h<database_host> -u<database_username> -p<database_password> > /opt/backup/data/mysql.bck
# Create mediawiki tarball
echo Creating mediawiki tarball...
cd /opt/mediawiki/
@joshmn
joshmn / gist:6831378
Created October 4, 2013 19:30
Accept non-GET AJAX via jQ while Authenticated inside a Ruby on Rails application (devise, simpleauth)
$(document).ajaxSend(function (_, xhr) {
xhr.setRequestHeader('X-CSRF-Token', $('meta[name="csrf-token"]').attr('content'));
});
@joshmn
joshmn / powerball.json
Created January 13, 2016 21:18
Powerball winners
[{
"date": "2016-01-09",
"winners": [16, 19, 32, 34, 57],
"powerball": 13
}, {
"date": "2016-01-06",
"winners": [2, 11, 47, 62, 63],
"powerball": 17
}, {
"date": "2016-01-02",