Skip to content

Instantly share code, notes, and snippets.

@smathy
smathy / repo.ex
Last active October 13, 2018 00:24
defmodule Snug.Repo do
alias Snug.Neo
@var "n"
def all mod do
Neo.query!("""
MATCH (#{@var}:#{class_name mod})
RETURN #{@var}
""")
## Doesn't work
<?php
declare(ticks = 1);
function sig_handler($s) {
die("Caught ALARM\n");
}
[2] pry(main)> require "uri"
=> true
[3] pry(main)> URI "foo:3000"
=> #<URI::Generic foo:3000>
[4] pry(main)>
module Cancelerizer
def cancel arg
Sidekiq::ScheduledSet.new.each do |job|
(klass, method, args) = YAML.load job.args.first
if self == klass and args.first == arg
job.delete
end
end
end
end
@smathy
smathy / -
Created April 26, 2016 17:07
~/work git clone https://github.com/vdaubry/youtube-multiple-dl.git 11:05:02
Cloning into 'youtube-multiple-dl'...
remote: Counting objects: 175, done.
remote: Total 175 (delta 0), reused 0 (delta 0), pack-reused 175
Receiving objects: 100% (175/175), 127.51 KiB | 0 bytes/s, done.
Resolving deltas: 100% (74/74), done.
Checking connectivity... done.
~/work cd youtube-multiple-dl 11:05:10
~/work/youtube-multiple-dl rbenv local 2.2.0 master 11:05:13
~/work/youtube-multiple-dl curl https://yt
[10:32:07] smathy: shibly, but you can't reliably use the old gems with the new ruby.
[10:32:24] shibly: smathy, Why not? What's wrong?
[10:33:15] smathy: shibly, some gems have native (compiled) components, they won't work across different ruby versions. This all is why version managers (and bundler) were invented.
[10:37:00] smathy: shibly, chruby/rbenv and their install helpers: ruby-install or ruby-build
[10:37:23] shibly: smathy, If i use rvm, then will i be able to use older gem with newer ruby?
[10:37:52] smathy: shibly, no, you will never be able to do that for any gem that has a compiled component.
[10:40:00] shibly: smathy, If i use chruby/rbenv then will i be able to use older gems with newer ruby?
module Flattener
def flatten element, result=[]
if element.is_a? Array
element.each do |e|
flatten e, result
end
else
result << element
end
result
[7] pry(main)> rand(1.year)
NoMethodError: undefined method `begin' for 31557600.0:Float
from /Users/jk/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/activesupport-4.1.6/lib/active_support/duration.rb:115:in `method_missing'
[8] pry(main)> 1.year
=> 31557600.0
[9] pry(main)> 31557600.0.class
=> Float
[10] pry(main)> rand(31557600.0)
=> 22083830
[11] pry(main)>
User # autoload
class User
class Twin
class Authentication < ::Disposable::Twin
include Sync
include Save
property :state
property :password_digest
[25] pry(main)> itemStr = "../../lib/images/background/background.jpg"
=> "../../lib/images/background/background.jpg"
[26] pry(main)> itemStr.scan(/\.[0-9a-z]+$/i)
=> [".jpg"]
[27] pry(main)>