Skip to content

Instantly share code, notes, and snippets.

@glinesbdev
glinesbdev / gist:0cf6cbfdefb05057104c
Last active August 29, 2015 14:03
File word count
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 July 22, 2014 00:25
Wanted to write some pure JS to mimic a simple jQuery
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";
}
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 August 29, 2015 14:04
Dungeon game
# (*) = methods I added
class Dungeon
attr_accessor :player
def initialize(player_name)
@player = Player.new(player_name)
@rooms = []
end
@glinesbdev
glinesbdev / project.html
Last active August 29, 2015 14:04
idliving
{% 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>
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}
$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;
@glinesbdev
glinesbdev / gist:6c08b8fb403c8ac26c9a
Last active August 29, 2015 14:07
Fucking JS Closure
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 October 21, 2014 04:46
Dynamic object building in JS
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 October 21, 2014 05:08
Craziness with JS objects and arrays
// 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},