Skip to content

Instantly share code, notes, and snippets.

@DefV
DefV / bench.rb
Created September 9, 2014 10:17
Bench
require 'benchmark'
n = 100_000_000
Benchmark.bm do |x|
x.report do
result = []
row = nil
n.times do |i|
row = i * 5
result << row
# -*- mode: ruby -*-
# vi: set ft=ruby :
# This is a Vagrant configuration file. It can be used to set up and manage
# virtual machines on your local system or in the cloud. See http://downloads.vagrantup.com/
# for downloads and installation instructions, and see http://docs.vagrantup.com/v2/
# for more information and configuring and using Vagrant.
Vagrant.configure("2") do |config|
# Omnibus for chef install
config.omnibus.chef_version = :latest
12:42 :: guinsly:: I'm trying to retrieve a content from another class. But it outputs nil :: https://gist.github.com/guinslym/06bb6bc108c9331e1ff0
12:42 :: jhass:: guinsly: is that your real code? or an example that reproduces? because class foo is invalid
12:43 :: shevy:: arup_r, http://stackoverflow.com/questions/543774/undef-why-would-you-want-to-undefine-a-method-in-ruby - but it seems as if people rarely need it
12:43 :: jhass:: also note that the @firstname outside a def is a different @firstname
12:43 :: jhass:: guinsly: ^
12:43 :: shevy:: I never needed undef, I did need undef_method (or actually... remove_method it was...)
12:43 :: guinsly:: jhass, this the realcode except class foo is name LoadFile
12:43 :: jhass:: why did you change it?
12:44 :: jhass:: but your issue is probably what I just said
12:44 :: apeiros:: weird indent. tabs mixed with spaces? o0
def icon_link_to(name, link, options = {})
link_to link, options do
content_tag(:span, name) + content_tag(:i, '', class: "fa fa-#{options[:icon]}"
end
end
### Keybase proof
I hereby claim:
* I am DefV on github.
* I am defv (https://keybase.io/defv) on keybase.
* I have a public key whose fingerprint is CF6C 837A FC61 A672 EB88 B14A 8C49 44CF C9C3 6768
To claim this, I am signing this object:
### Keybase proof
I hereby claim:
* I am DefV on github.
* I am defv (https://keybase.io/defv) on keybase.
* I have a public key whose fingerprint is CF6C 837A FC61 A672 EB88 B14A 8C49 44CF C9C3 6768
To claim this, I am signing this object:
class Artist < ActiveRecord::Base
has_many :tracks
accepts_nested_attributes_for :tracks
end
class Track < ActiveRecord::Base
before_destroy :check_track
def check_track
return false if created_at > 1.week.ago
@DefV
DefV / scrollTo
Last active December 11, 2015 11:38 — forked from tijsverkoyen/scrollTo
$(document).on('click', 'a[href*="#"]', function(e) {
var $anchor = $(this),
hash = $anchor.attr('href'),
url = hash.substr(0, hash.indexOf('#')),
$hash = $(hash.substr(hash.indexOf('#')));
if(url.indexOf(document.location.pathname) >= 0 && $hash.length > 0)
{
e.preventDefault();
[[MyClass alloc] initWithItem:self.item]
@implementation MyClass
- (void) speak
{
NSLog(@"%@ costs %@", self.item.title, self.item.price);
}
// OR
@DefV
DefV / gist:1018547
Created June 10, 2011 09:35
ruby 1.9.2-p180 patched zip failure
ruby-1.9.2-p180-patched :001 > (1..2).zip(1..2)
(irb):1: [BUG] Bus Error
ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-darwin10.7.0]
-- control frame ----------
c:0027 p:---- s:0092 b:0092 l:000460 d:000460 CFUNC :next
c:0026 p:---- s:0090 b:0090 l:000085 d:000089 IFUNC
c:0025 p:---- s:0088 b:0088 l:000087 d:000087 CFUNC :each
c:0024 p:---- s:0086 b:0086 l:000085 d:000085 CFUNC :zip
c:0023 p:0014 s:0082 b:0082 l:001d18 d:000081 EVAL (irb):1