background preloader

Write cross-platform native apps in Ruby

Write cross-platform native apps in Ruby
Related:  Ruby

Class: Logger (Ruby 2.6.2) Description¶ ↑ The Logger class provides a simple but sophisticated logging utility that you can use to output messages. The messages have associated levels, such as INFO or ERROR that indicate their importance. The levels are: An unknown message that should always be logged. An unhandleable error that results in a program crash. A handleable error condition. A warning. Generic (useful) information about system operation. Low-level information for developers. For instance, in a production system, you may have your Logger set to INFO or even WARN. Note: Logger does not escape or sanitize any messages passed to it. logger.info("User-input: #{input.dump}") logger.info("User-input: %p" % input) You can use formatter= for escaping all data. original_formatter = Logger::Formatter.newlogger.formatter = proc { |severity, datetime, progname, msg| original_formatter.call(severity, datetime, progname, msg.dump) } logger.info(input) Example¶ ↑ Features¶ ↑ HOWTOs¶ ↑ How to create a logger¶ ↑ logger.close Format¶ ↑

Really useful libraries So these have been on my github for a while now, but I've never made a post about them yet. I use these in each project I make, and they _really_ help me out. Library name + short description: Non-gosu libraries: lib_misc.rb - Just my personal library of semi-useful methods, might be useful to someone. lib.rb - Intended to be a "library loader library", but I lost interest in making it do that, it's now just a very small collection of methods. lib_encrypt.rb - Very useful collection of encryption / compression methods, and their counterparts. Gosu libraries (The really useful ones): lib_alphabet.rb - An amazing font system; Make sure to grab alphabet.png or make your own if you plan on using it. lib_lighting.rb - A lighting system I made a couple years ago, this one already has a post. lib_medialoader.rb - Here's the best one, the crème de la crème. lib_misc_gosu.rb - Another small one with a few gosu related methods. Repo link:

rmagick/rmagick Understanding how Ruby stores objects in memory - the Ruby Heap - The Irish Penguin Ruby has it's own heap management which actually consists of several 'Ruby Heaps' to manage objects created during the execution of a Ruby program; this is separate from the System Heap for your Operating System. Each individual Ruby Heap contains Slots, with each Slot able to one reference one object. The entire space that an object takes up in memory is not stored inside the Slot. Rather each Slot is a small fixed size space which can be thought of as the Ruby interpreter's handle a location in memory. Here's an example. Ruby starts of with a minimal set of Ruby Heaps. There is a problem with this last statement however - if a Ruby Heap contains mostly Free Slots and one Filled Slot then it will not be freed. References How the Ruby Heap is Implemented Phusion Passenger's Hong Lai gives a great explanation of the Ruby Heap - the banner may not be quite suitable for work.

Module: Benchmark (Ruby 2.6.3) benchmark(caption = "", label_width = nil, format = nil, *labels) click to toggle source Invokes the block with a Benchmark::Report object, which may be used to collect and report on the results of individual benchmark tests. Reserves label_width leading spaces for labels on each line. If the block returns an array of Benchmark::Tms objects, these will be used to format additional lines of output. Note: Other methods provide a simpler interface to this one, and are suitable for nearly all benchmarking requirements. Example: Generates: user system total real for: 0.970000 0.000000 0.970000 ( 0.970493) times: 0.990000 0.000000 0.990000 ( 0.989542) upto: 0.970000 0.000000 0.970000 ( 0.972854) >total: 2.930000 0.000000 2.930000 ( 2.932889) >avg: 0.976667 0.000000 0.976667 ( 0.977630)

Metrics Documentation & Statistics - The Ruby Toolbox Today I'm happy to introduce a new metrics documentation & statistics section. As part of the ongoing effort of making the site more beginner-friendly all project metrics now link to a dedicated page that explains the purpose of the metric and gives guidance on how it can help choose a library. To make those pages more appealing to all visitors the pages also feature statistics around the Ruby ecosystem, including charts that display the distribution of this metric's values as well as top project rankings. This addition continues the recently started effort of bringing more documentation and guidance to the site by making documentation a dedicated site section and bringing a sidebar navigation, enabling the easy addition and discovery of upcoming content. As usual if you'd like to give feedback or have suggestions for improvements on this a great place for that is the Pull Request of the feature. Best,Christoph

Ruby, Sudoku challenge and How to tackle problems – Gavin Yap Sudoku Challenge Believed it or not but this challenge is being asked by Apple and Uber. Well, I do know many of the hi-tech companies employs brilliant engineers/coders, probably the bests in the market. But really, to solve Sudoku??? Requirements The requirements of the challenge is to check if that a given Sudoku grid puzzle is valid or not. The first few problems I encounter before even attempting to solve this problem are: I have no knowledge of sudoku rulesI am not a reader. So all these problems are fallen dominoes over the main problem. The Path to Solution First, I read the instructions carefully again. Second, I studied the rules. the x-axis of the positionthe y-axis of the positionwithin the block So for the below diagram, in the position of x, x shall not have a duplicate in the yellow area. I then began working on the algorithm to solve this problem. My pseudo algorithm then goes about like this: My first issue and what I want to do is by solving this problem by recursion.

Build an API with the Jets Ruby Serverless Framework - BoltOps Blog In this blog post, I’ll cover how to build a simple API service on AWS Lambda with the Jets Ruby Serverless Framework. Jets New API Mode The jets new command has a few different modes: html, api, and job. We’ll use the handy api mode for this tutorial to create a starter project designed for APIs. jets new demo --mode api cd demo We’ve successfully generated a starter Jets project. We are ready to now add some API code. Scaffold We’ll use a scaffold to generate some basic CRUD. jets generate scaffold Post title:string vim .env.development # adjust to your local database creds jets db:create db:migrate Local Testing Let’s seed some data by creating a db/seeds.rb: 3.times do |i| Post.create(title: "Title #{i+1}")endputs "Seeding data completed" Here’s the command to load the db/seeds.rb data: Now let’s do some quick local testing with jets console. $ jets console >> item = Post.find(1) >> item.title = "Title 1 Edit" >> item.save! We can also test with a local server with jets server: Deploy Testing It

Related: