Skip to content

Instantly share code, notes, and snippets.

View gist:0cf6cbfdefb05057104c
def word_count(file)
file = File.open(file) { |f| f.read.split }
file = file.reduce(:+)
file = file.each_char.count
end
# or you could do this
def word_count(file)
File.open(file) { |f| f.read.split }
@glinesbdev
glinesbdev / gist:31227a74e39fd9f6251e
Created Jul 22, 2014
Wanted to write some pure JS to mimic a simple jQuery
View gist:31227a74e39fd9f6251e
var hideStuff = function() {
if (#{@platform.platform_type == 'rewards'}) {
var row = document.getElementsByTagName("tr");
for (var i = 0; i < row.length; i++) {
if (row[i].innerHTML.search("Accreditation") != -1) {
row[i].style.display = "none";
} else if (row[i].innerHTML.search("Escrow") != -1) {
row[i].style.display = "none";
}
View gist:754a7327d216a7ddb086
irb(main):023:0> a = Authentication.new(platform_id: 235, user_id: 13036)
=> #<Authentication id: nil, platform_id: 235, user_id: 13036, receive_newsletter: true, roles_mask: nil, created_at: nil, updated_at: nil, mailchimp_registered: false, accepted_terms: nil, accepted_accredited_terms: nil, meta: nil, additional_fields: {}>
irb(main):024:0> a.save
(1.9ms) BEGIN
Platform Load (1.9ms) SELECT "platforms".* FROM "platforms" WHERE "platforms"."id" = 235 LIMIT 1
(1.7ms) ROLLBACK
NoMethodError: undefined method `custom_attributes' for nil:NilClass
@glinesbdev
glinesbdev / Methods
Last active Aug 29, 2015
Dungeon game
View Methods
# (*) = methods I added
class Dungeon
attr_accessor :player
def initialize(player_name)
@player = Player.new(player_name)
@rooms = []
end
View project.html
{% if template.name == 'projects/edit' %}
{{ template.content }}
{% else %}
{% assign author = project.author %}
<div class="content grid_8">
{% authorize edit project %}
{% if warning %}
<div class='box-gray'>
<p>{{ warning }}</p>
View gist:dcafa7ce20c70214147d
def export_orders
authorize! :export_orders, @project
file_name = I18n.transliterate("#{@project.title}_supporters").downcase.gsub(/\s/, '_').gsub(/[^a-z_]/, '')
file_name = file_name.present? ? file_name : 'unknown'
if current_platform.id == 263
csv_pledges = "Name,Email,Adresse,Adresszeile 2,Stadt,Bundesland,PLZ,Land,Beitrag,Projekttitel,Beitragszeit,Kosten des Tauschguts,Tauschgut,Beschreibung,Tauschgut,Versanddatum,\r\n"
else
csv_pledges = "Name,Email,Address,Address Line 2,City,State,Zip Code,Country,Amount,Project Title,Timestamp,Reward Level,Reward Description,Reward Delivery Date\r\n"
end
@project.pledges.confirmed.map{|p| csv_pledges += p.to_csv_with_reward_details}
View gist:d817fa0fa83c6d2f6632
$col-numbers: "1", "2", "3", "4", "5", "6",
"7", "8", "9", "10", "11", "12";
$selector: ();
@each $item in $col-numbers {
$selector: append($selector, unquote('.col-md-#{$item}'), comma);
}
#{$selector} {
padding-right: 0px;
View gist:6c08b8fb403c8ac26c9a
function makeTargetAssigner(sharks, targets) {
return function(shark) {
for (var i = 0; i < sharks.length; i++) {
if (shark == sharks[i]) {
alert("What up, " + shark + "!" + "\n" + "There've been " + targets[i] + " sightings in our 'hood!" + "\n" + "Time for a swim-by lasering, homie!");
}
}
};
}
@glinesbdev
glinesbdev / gist:79e345f8f1f575188a8c
Created Oct 21, 2014
Dynamic object building in JS
View gist:79e345f8f1f575188a8c
var superBlinders = [ ["Firestorm", 4000], ["Solar Death Ray", 6000], ["Supernova", 12000] ];
var lighthouseRock = {
gateClosed: true,
weaponBulbs: superBlinders,
capacity: 30,
secretPassageTo: "Underwater Outpost",
numRangers: 0
};
function addRanger(location, name, skillz, station) {
@glinesbdev
glinesbdev / gist:ff64067ace476eaf58e9
Created Oct 21, 2014
Craziness with JS objects and arrays
View gist:ff64067ace476eaf58e9
// Without running the code in the console, can you tell what this will do?
var superBlinders = [ ["Firestorm", 4000], ["Solar Death Ray", 6000], ["Supernova", 12000] ];
var lighthouseRock = {
gateClosed: true,
weaponBulbs: superBlinders,
capacity: 30,
secretPassageTo: "Underwater Outpost",
numRangers: 3,
ranger1: {name: "Nick Walsh", skillz: "magnification burn", station: 2},
You can’t perform that action at this time.