recentpopularlog in

kme : ruby   279

« earlier  
aanand/git-up: NOT MAINTAINED
git pull has two problems:

* It merges upstream changes by default, when it's really more polite to rebase over them, unless your collaborators enjoy a commit graph that looks like bedhead.

* It only updates the branch you're currently on, which means git push will shout at you for being behind on branches you don't particularly care about right now.
git  helperscript  devel  workflow  ruby  rubygem 
june 2019 by kme
kamilhism/creek: A Ruby library for parsing large Excel files. | https://github.com/
A Ruby library for parsing large Excel files. Contribute to kamilhism/creek development by creating an account on GitHub.
ruby  excel  parsing  spreadsheet  library 
april 2019 by kme
busyloop/lolcat: Rainbows and unicorns! | https://github.com/
Rainbows and unicorns! Contribute to busyloop/lolcat development by creating an account on GitHub.
ruby  gem  terminal  color  lolcat  rainbow  fun 
march 2019 by kme
ruby on rails - How can I remove a default gem? ! want to uninstall a gem 1.7.7 version of json - Stack Overflow | https://stackoverflow.com/
I had to remove the (duplicate) '<ruby_install_dir>/lib/ruby/gems/<ruby_major_ver>/specifications/default/json-x.y.z.gemspec' file from my specifications/default directory.

The top-rated answer was confusingly verbose, but it did contain the solution in there, somewhere.
ruby  rubygems  errormessage  annoyance  solution 
march 2019 by kme
Error installing json 1.8.3 with ruby 2.4 - Stack Overflow | https://stackoverflow.com/
I did <code class="language-bash">gem install -v 1.8.6 json</code> and it worked.
I ran into the same issue recently as well, try and see if there's a newer version of whatever gem you're using that depends on json 1.8.3. This is happening because Ruby 2.4 unified Fixnum and Bignum into Integer. If you're able to upgrade to json 1.8.5 or higher, it should help fix your problems.
ruby  annoyance  errormessage  rubygems  gem  solution 
march 2019 by kme
riseuplabs / crabgrass · GitLab | https://0xacab.org/
Crabgrass is a web application designed for activist groups to be better able to collaborate online. Mostly, it is a glorified wiki with fine-grain control over access rights.
ruby  rails  wiki  collaboration  activism  webapp  samplecode  webdevel 
february 2019 by kme
How do I compile Readline support into Ruby - Stack Overflow | https://stackoverflow.com/
This is *NOT* work for me. I ended up using 'libedit' instead, after much exasperation, trials, and tribulations.
ruby  readline  compiler  build  toolchain  fromsource  headache  workaround  solution 
november 2018 by kme
Bug #8762: CFLAGS and LDFLAGS are not set properly in Makefile when they are already set as environment variables - Ruby trunk - Ruby Issue Tracking System | https://bugs.ruby-lang.org/
I thought I had this problem, but I think it turned out that the CFLAGS *were* actually being fed to the compiler. They just weren't being reported in the './configure' summary.
ruby  fromsource  compiler  build  toolchain  maybebug  makefile 
november 2018 by kme
transform hash key from string into symbol - Ruby Forum | https://www.ruby-forum.com/
This was handy, but I found a different way by just iterating over the array and returning another (two-element) array inside a 'map' or a 'each_key' or something, then passing this to the Hash#[] constructor.

<code class="language-ruby">class Hash
def symbolize_keys
replace(inject({}) { |h,(k,v)| h[k.to_sym] = v; h })
end
end</code>
ruby  arrays  hashes  map  fp  idiom  newbie  syntax  solution 
may 2018 by kme
ruby - Difference Between map and each - Stack Overflow | https://stackoverflow.com/

each simply iterates over the given enumerable, running the block for each value. It discards the return value of the block, and each simply returns the original object it was called on:
<code class="language-ruby">[1, 2, 3].each do |i|
i + 1
end # => [1, 2, 3]
</code>

This is simply a nicer, more universal way of doing a traditional iterating for loop, and each is much preferred over for loops in Ruby (in fact, I don't think I've ever used a for loop in Ruby).

map, however, iterates over each element, using the return value of the block to populate a new array at each respective index and return that new array:
<code class="language-ruby">[1, 2, 3].map do |i|
i + 1
end # => [2, 3, 4]</code>

So it "maps" each element to a new one using the block given, hence the name "map". Note that neither each nor map themselves modify the original collection.
ruby  arrays  fp  map  syntax  newbie  reference  solution 
may 2018 by kme
syntax - What do the different brackets in Ruby mean? - Stack Overflow | https://stackoverflow.com/
[] can be overridden as a custom method, and is generally used to fetch things from hashes (the standard library sets up [] as a method on hashes which is the same as fetch)
There is also a convention that it is used as a class method in the same way you might use a static Create method in C# or Java. e.g.
<code class="language-ruby">
a = {1 => 2} # create a hash for example
puts a[1] # same as a.fetch(1), will print 2

Hash[1,2,3,4] # this is a custom class method which creates a new hash</code>
ruby  syntax  brackets  braces  idiom  arrays  hashes  annoyance  solution 
may 2018 by kme
ruby - Secure Password Generation With Random Chars - Stack Overflow | https://stackoverflow.com/
You can use SecureRandom (docs):
<code class="language-ruby">
require 'securerandom'

password = SecureRandom.base64(15)
# => "vkVuWvPUWSMcZf9nn/dO"
</code>
ruby  passwordgenerator  password  solution 
may 2018 by kme
Wirble: Tab-Completion and Syntax Coloring for irb | http://www.rubyinside.com/
If you haven't got tab-completion and syntax coloring in your irb, you owe it to yourself to follow these instructions right away (should work for Linux, OS X, and Cygwin users). First, install the Wirble gem:
<code class="language-bash">sudo gem install -y wirble</code>

Next, create or edit a file called .irbrc in your home folder (~/.irbrc), and make sure these lines are included there:
<code class="language-ruby">require 'rubygems'
require 'wirble'
Wirble.init
Wirble.colorize</code>
ruby  repl  irb  syntaxhighlighting  fuckina  solution 
may 2018 by kme
nagative aurument in converter.rb:417 · Issue #12 · ttscoff/mdless | https://github.com/
I got this error without having 'pygmentize' installed:

<code>$ mdless --width=80 README.md
/Users/username/.gem/ruby/2.3.0/gems/mdless-0.0.10/lib/mdless/converter.rb:428:in `*': negative argument (ArgumentError)
from /Users/username/.gem/ruby/2.3.0/gems/mdless-0.0.10/lib/mdless/converter.rb:428:in `block (2 levels) in convert_markdown'
from /Users/username/.gem/ruby/2.3.0/gems/mdless-0.0.10/lib/mdless/converter.rb:424:in `map'
from /Users/username/.gem/ruby/2.3.0/gems/mdless-0.0.10/lib/mdless/converter.rb:424:in `block in convert_markdown'
from /Users/username/.gem/ruby/2.3.0/gems/mdless-0.0.10/lib/mdless/converter.rb:404:in `gsub!'
from /Users/username/.gem/ruby/2.3.0/gems/mdless-0.0.10/lib/mdless/converter.rb:404:in `convert_markdown'
from /Users/username/.gem/ruby/2.3.0/gems/mdless-0.0.10/lib/mdless/converter.rb:118:in `block in initialize'
from /Users/username/.gem/ruby/2.3.0/gems/mdless-0.0.10/lib/mdless/converter.rb:106:in `each'
from /Users/username/.gem/ruby/2.3.0/gems/mdless-0.0.10/lib/mdless/converter.rb:106:in `initialize'
from /Users/username/.gem/ruby/2.3.0/gems/mdless-0.0.10/bin/mdless:17:in `new'
from /Users/username/.gem/ruby/2.3.0/gems/mdless-0.0.10/bin/mdless:17:in `<top (required)>'
from /Users/username/.gem/ruby/2.3.0/bin/mdless:23:in `load'
from /Users/username/.gem/ruby/2.3.0/bin/mdless:23:in `<main>'</code>
markdown  viewer  errormessage  ruby  workaround  solution 
march 2018 by kme
ruby - Logging in Sinatra? - Stack Overflow
Sinatra 1.3 will ship with such a logger object, exactly usable as above. You can use edge Sinatra as described in "The Bleeding Edge". Won't be that long until we'll release 1.3, I guess.

To use it with Sinatra 1.2, do something like this:

<code class="language-ruby">
require 'sinatra'
use Rack::Logger

helpers do
def logger
request.logger
end
end
</code>
ruby  sinatra  webdevel  logging  solution 
december 2017 by kme
So did anyone ever figure out what happened to _why (a.k.a - whytheluckystiff) ? : programming
[]astrosmash 54 points 7 years ago

He's writing enterprisey middleware for a small ASP.NET firm in Austin, Texas. His employment contract doesn't allow him to work on outside projects, so he had to halt all of his open source activities.

permalinkembedsave

[]heroofhyr 78 points 7 years ago

Of all the theories, including those involving suicide, you've proposed the most depressing.
ruby  _why  explained 
december 2017 by kme
Ruby-Doc.org: Documenting the Ruby Language
Why isn't this more prominently linked from ruby-lang.org?
ruby  programming  language  reference  newbie  documentation  devel 
december 2017 by kme
How can I find which operating system my Ruby program is running on? - Stack Overflow
Use the RUBY_PLATFORM constant, and optionally wrap it in a module to make it more friendly:

<code class="language-ruby">
module OS
def OS.windows?
(/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil
end

def OS.mac?
(/darwin/ =~ RUBY_PLATFORM) != nil
end

def OS.unix?
!OS.windows?
end

def OS.linux?
OS.unix? and not OS.mac?
end
end
</code>
ruby  os  platform  detection  solution 
december 2017 by kme
ruby - Why can't IRB locate the file to "require"? - Stack Overflow | https://stackoverflow.com/
Try require './test'

I think newer versions of Ruby removed the current directory from the Ruby path.

Edit: Also, check out the answer to "Why isn't current directory on my Ruby path?" for an explanation why require_relative doesn't work in irb.
ruby  irb  repl  library  devel  errormessage  solution 
october 2017 by kme
xml - How to execute XPath one-liners from shell? - Stack Overflow - https://stackoverflow.com/
What on earth do all these options do?
<code class="language-bash">xmlstarlet sel -T -t -m '//element/@attribute' -v '.' -n filename.xml</code>
Nokogiri. If I write this wrapper I could call the wrapper in the way described above:

<code class="language-ruby">
#!/usr/bin/ruby

require 'nokogiri'

Nokogiri::XML(STDIN).xpath(ARGV[0]).each do |row|
puts row
end
XML::XPath. Would work with this wrapper:

#!/usr/bin/perl

use strict;
use warnings;
use XML::XPath;

my $root = XML::XPath->new(ioref => 'STDIN');
for my $node ($root->find($ARGV[0])->get_nodelist) {
print($node->getData, "\n");
}
</code>


Also:
<code class="language-bash">
xmllint --xpath '//element/@attribute' file.xml
xmlstarlet sel -t -v "//element/@attribute" file.xml
saxon-lint --xpath '//element/@attribute' file.xml
</code>

In Python with lxml:
So to do the same for normal Web content—HTML docs that aren’t necessarily well-formed XML:
<code class="language-bash">
echo "<p>foo<div>bar</div><p>baz" | python -c "from sys import stdin; \
from lxml import html; \
print '\n'.join(html.tostring(node) for node in html.parse(stdin).xpath('//p'))"
</code>

And to instead use html5lib (to ensure you get the same parsing behavior as Web browsers—because like browser parsers, html5lib conforms to the parsing requirements in the HTML spec).
<code class="language-bash">
echo "<p>foo<div>bar</div><p>baz" | python -c "from sys import stdin; \
import html5lib; from lxml import html; \
doc = html5lib.parse(stdin, treebuilder='lxml', namespaceHTMLElements=False); \
print '\n'.join(html.tostring(node) for node in doc.xpath('//p'))
</code>
xpath  xml  xslt  parsing  ruby  textprocessing  webdevel  commandline  cli  oneliner  list  recommendation  samplecode 
october 2017 by kme
gitlab-recipes/import/bitbucket at master · gitlabhq/gitlab-recipes | https://github.com/
The whole '@project="group%2Fproject_name"' thing (around line 26 of 'bitbucket2gitlab.rb') didn't work for me, so I looked up the actual project ID with the API and used that instead. Worked OK then.

In other words, https://server/api/v3/projects/group/project_name/issues is a 404, but https://server/api/v3/projects/<group_id>/issues works fine.

Maybe a "group" is not a "namespace"?
gitlab  bitbucket  importexport  sourcecodehosting  ruby  solution 
october 2017 by kme
ruby - How to install RVM system requirements without giving sudo access for RVM user - Stack Overflow
This is indeed a new feature of RVM called autolibs, which automatically installs dependencies.

If you have already installed RVM, and it is asking you for your sudo password, you can disable autolibs:

$ rvm autolibs disable
$ rvm requirements # manually install these
$ rvm install ruby

Otherwise, you can install RVM without autolibs with this command:

$ \curl -L https://get.rvm.io | bash -s -- --autolibs=read-fail

I understand the motivation, but find it rather annoying. I do not want to put my sudo password into RVM, nor for that matter Bundle! Please community, stop doing this.

I prefer this

$ rvm autolibs fail
$ rvm install ruby
Searching for binary rubies, this might take some time.
Found remote file https://rubies.travis-ci.org/ubuntu/12.04/x86_64/ruby-2.1.1.tar.bz2
Checking requirements for ubuntu.
Missing required packages: gawk g++ gcc make libreadline6-dev zlib1g-dev libssl-dev libyaml-dev libsqlite3-dev sqlite3 autoconf libgdbm-dev libncurses5-dev automake libtool bison pkg-config libffi-dev
RVM autolibs is now configured with mode '2' => 'check and stop if missing',
please run `rvm autolibs enable` to let RVM do its job or run and read `rvm autolibs [help]`
or visit https://rvm.io/rvm/autolibs for more information.
Requirements installation failed with status: 1.
ruby  virtualenv  rvm  dependencies  annoyance  solution 
april 2017 by kme
GitHub - guard/guard-livereload: Guard::LiveReload automatically reload your browser when 'view' files are modified.
A minimal Gemfile:
group :development do
gem 'guard'
gem 'guard-livereload'
gem 'terminal-notifier-guard'
end


A minimal Guardfile:
guard 'livereload', notify: true do
watch(%r{index.html})
watch(%r{css/.+\.css})
watch(%r{js/.+\.js})
end
ruby  webdevel  guard  automation  autoreload  autorefresh  solution  alternativeto  livereload 
november 2016 by kme
For a Good Strftime - Easy Skeezy Ruby Date/Time Formatting
The proper ISO8601 format for Python's datetime: %Y-%m-%dT%H:%M:%S.%f (which was originally generated by dt.now().isoformat().

So, in summary:

timestamp = datetime.now().isoformat
dt = datetime.datetime.strptime(timestamp, '%Y-%m-%dT%H:%M:%S.%f')
webapp  generator  strftime  dateandtime  stringformatting  python  ruby  solution 
june 2016 by kme
osx - Why can't Ruby find my Net::SCP? - Stack Overflow
The error message I get from 'veewee' after installing it in the usual way is "LoadError: cannot load such file -- net/scp." Apparently, it did not pull in the 'net-scp' package properly as a dependency.
I chose to install my gem home in my home directory to avoid permissions issue with OXS El Capitan. gem list shows net-scp (1.2.1) – Pierre-Loup Jan 20 at 21:47
veewee  macos  mac  osx  ruby  headache  rubygems  errormessage  solution 
june 2016 by kme
Nokogiri install fails because of missing lzma symbols in self built libxml2 · Issue #1119 · sparklemotion/nokogiri · GitHub
Ran into this problem attempting to install veewee, and something about the libxml2 2.9.4 that comes with Nokogiri (it's bundled "[b]ecause Nokogiri needs to be compiled and dynamically linked against both libxml2 and libxslt, it has gained a reputation for being complicated to install.")
installed the current version of Xcode
$ sudo port install libxml2 libxslt
$ bundle config build.nokogiri --use-system-libraries
ruby  rails  rubyonrails  library  errormessage  libxml2  macos  solution 
june 2016 by kme
How do I create a SHA1 hash in ruby? - Stack Overflow
require 'digest/sha1'
Digest::SHA1.hexdigest 'foo'
ldap  ruby  sha  hashing  library  solution 
may 2016 by kme
« earlier      
per page:    204080120160

Copy this bookmark:





to read