Skip to content

Instantly share code, notes, and snippets.

@nateroling
nateroling / deploy.addendum.rb
Last active July 15, 2016 07:11
Roots Bedrock: Copy production assets for Roots theme
# The Roots theme by default does not check production assets into Git, so
# they are not deployed by Capistrano when using the Bedrock stack. The
# following will compile and deploy those assets. Copy this to the bottom of
# your config/deploy.rb file.
# Based on information from this thread:
# http://discourse.roots.io/t/capistrano-run-grunt-locally-and-upload-files/2062/7
# and specifically this gist from christhesoul:
# https://gist.github.com/christhesoul/3c38053971a7b786eff2
@nateroling
nateroling / gist:6161980
Last active December 20, 2015 16:29
Doing some decidedly advanced and ruby-specific things here, don't worry if they don't make sense yet. Let me know what you have questions on.
require 'net/http'
require 'json'
# Q:
# I kind of understand how this works. Each class is like a user made method
# (or function as I would call it). So whenever you call the player class it
# will run the parameters through. I read something about you can use that to
# make it more manageable. And you can mage gems out of it (or something - not
# quite sure on that part).
require 'net/http'
require 'json'
names=%w{ ututtza publicstaticmainvoid netscrape getus }
# Use a different method of string interpolation/templating.
# This way I can define the URL template once here, and then insert different
# names into it later.
# See: http://www.ruby-doc.org/core-1.9.3/String.html#method-i-25
uri_template = "http://census.soe.com/json/get/ps2-beta/character/?name.first_lower=%{name}&c:show=name,online_status%%20&c:resolve=online_status"
require 'net/http'
names=%w{ ututtza publicstaticmainvoid netscrape getus }
on_off = {0=>"OFFline", 1=>"ONline"} #hash for when printing out if online
names.each do |name|
uri = URI("http://census.soe.com/xml/get/ps2-beta/character/?name.first_lower=#{name}&c:show=name,online_status%20&c:resolve=online_status") #using planetside 2 API to get character information just need online_status value
status= Net::HTTP.get(uri)
first_junk=status.split #initial split of string to get online or offline
onlinestatus=first_junk.at(9).split('"') #second split which returns 0 when offline and 10 when online in the (1) index of the array
@nateroling
nateroling / gist:6042612
Created July 19, 2013 21:53
After some struggling, this is the pattern I came up with for mapping JSON data to nested custom classes.
function Parent(data) {
// Let constructor work or without new.
// http://ejohn.org/blog/simple-class-instantiation/
// This makes it easier to use _.map below.
if (!(this instanceof Parent)) {
return new Parent(data);
}
// Use JSON data passed in, or set defaults values.