spacemacs toggle-transparency

2018-02-26 19:01:21 +0000

Anything added via spacemacs/add-toggle or things available in SPC t and SPC T should be proper toggles. This way, you can toggle them in user-config if you want to change the default state.

Specifically, spacemacs/toggle-transparency (and the related spacemacs/toggle-transparent-frame) both open a micro-state (in addition to toggling the setting). This means, that, if you want to have a transparent frame by default, you cannot just add (spacemacs/toggle-transparency) to your .spacemacs, because it will open the micro-state instead of just toggling transparency.

I’m not sure what other toggles do this, if there are any at all.

Ah, for now, I’m using this code in my user-config as a workaround:

 ;; Transparency by default
  (set-frame-parameter (selected-frame) 'alpha
                       (cons dotspacemacs-active-transparency
                             dotspacemacs-inactive-transparency))

later , spacemas reload config

SPC f e R

if you want load theme

SPC T s and select theme and enter

How to Install Latest Nodejs & NPM on Debian

2018-02-01 11:48:03 +0000

npm installation not working under Debian Stretch

I just tried to install node and npm on Debian Stretch. I installed node like decribed here.

After installing nodejs-legacy too I got the node command working but npm command still won’t be found.

So, I tried to install it manually via apt-get install npm but it just tells me that it can’t find the package. Next I tried the “Fancy Install (Unix)” from npm repository which fails with…

install npm@latest
fetching: https://registry.npmjs.org/npm/-/npm-5.5.1.tgz
module.js:327
    throw err;
    ^

Error: Cannot find module '/tmp/npm.1272/package/bin/read-package-json.js'
    at Function.Module._resolveFilename (module.js:325:15)
    at Function.Module._load (module.js:276:25)
    at Function.Module.runMain (module.js:441:10)
    at startup (node.js:140:18)
    at node.js:1043:3
added 1 package and removed 1 package in 0.45s
/usr/bin/npm -> /usr/lib/node_modules/npm/bin/npm-cli.js
/usr/bin/npx -> /usr/lib/node_modules/npm/bin/npx-cli.js
+ npm@5.5.1
updated 1 package in 1.21s
It worked

later I look this a solution I things so … and saw if install nvm and later install with nvm install npm ??? ok I go

open https://github.com/creationix/nvm install NVM Node Version Manager

Install script To install or update nvm, you can use the install script using cURL:

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash

or Wget

wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash

The script clones the nvm repository to ~/.nvm and adds the source line to your profile (~/.bash_profile, ~/.zshrc, ~/.profile, or ~/.bashrc).

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm

Note: On Linux, after running the install script, if you get nvm: command not found or see no feedback from your terminal after you type:

command -v nvm

or run

nvm --version

later you can run …

nvm install node
Downloading and installing node v9.5.0...
Downloading https://nodejs.org/dist/v9.5.0/node-v9.5.0-linux-x64.tar.xz...
######################################################################## 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v9.5.0 (npm v5.6.0)
Creating default alias: default -> node (-> v9.5.0)
 tinix  ~  node -v
v9.5.0

look this…

 tinix  ~  node -v
v9.5.0

problem solved..!!!

Ruby for Rails: Blocks

2018-01-30 12:06:31 +0000

This post is the first in a series of blog posts about Ruby for Rails beginners. These are specifically for Rails developers who want to solidify their grasp of the Ruby language.

More than a decade ago, I started learning Rails before I knew any Ruby. Rails is written in Ruby of course, so when writing Rails code you are writing Ruby code. But at the beginning, I didn’t fully understand how Ruby worked. And that’s fine. A lot of people started learning Rails and picked up Ruby along the way.

The “Ruby for Rails” series will help you learn Ruby to make you a better Rails programmer.

In this blog post, we’ll talk about blocks. Ruby blocks can be confusing to beginners but it’s important that you learn them because you’ll keep on using them on your Rails application.

One of the first code you’ll see with blocks is with loops.

(1..10).each do |i|
  puts i
end

The block is inside do and end. This code displays the numbers 1 to 10. When you read it, it kind of makes sense. From 1 to 10, for each i, puts i. If you have experience with other programming languages, you might think this is just a more complicated way to do loops.

each isn’t only for numbers. You can also iterate through an array.

["Alice", "Bob", "Eve"].each do |name|
  puts name
end

This code iterates through each element and prints the name. In Rails, you commonly use each when iterating through your model.

Post.all.each do |post|
  puts post.title
end

Say you have a Post model with a title. When you call each on Post.all , you iterate on each of those posts and the value is assigned to **post **which is inside || . Since post is a Post object, you can call post.title inside the block.

The examples so far show that blocks can be used to iterate through some objects. But the iteration is a by product of the each method. Blocks aren’t just for iteration. Here’s another common code in Rails.

<%= form_with Post.new do |form| %>
  <%= form.text_field :title %>
  <%= form.text_area :body %>
<% end %>
We use <%%> because this code appears on ERB templates. form_with is used to display an HTML form. Here, we call the form_with method and passes the Post.new parameter. form_with yields an object which we assign to form. You can use any variable inside   . We could have used f here instead of form.

In the examples above that used each, we yield each of the objects we’re iterating through. In form_with, we yield exactly one object which is the FormBuilder associated with the model. Inside the block you can use FormBuilder’s methods to generate fields like text_field, text_area, check_box, button, etc.

All the fields inside the block are captured and displayed inside the HTML form element.

These are just a few examples of blocks. You’ll see more when writing Rails code. So don’t get blocked out when coding!

I’d like this… original post by https://www.engineyard.com/blog/ruby-for-rails-blocks

What is attr_accessor in Rails?

2018-01-29 20:15:02 +0000

attr_accessor is used to define an attribute for object of Model which is not mapped with any column in database. This answers question - What is attr_accessor in Rails.

1. attr_accessor Methods

attr_accessor creates two methods i.e. getter method and setter method.

**getter method **- it is used to retrieve value of the attribute

setter method - it is used to set value to the attribute

When to use attr_accessor in Rails?

Whenever you want to show certain attribute for particular form but you do not want to store it’s value in the database then you use attr_accessor for that model as follows,

Suppose we have a Model called user in out database with following fields,

  • id
  • name
  • age
  • city
  • profession

And we define attr_accessor :type_of_user as follows,

Class User < ActiveRecord::Base
   attr_accessor :type_of_user
end

Now, whenever you create a object of the class User then you can assign a value to it’s attr_accessor.

new_user = User.new(:name => 'Albert', :age => 23, :city => 'Ports S.')

This will create new object of class User and assign given attribute values. You can assign value to attr_accessor variable as follows,

ew_user.type_of_user = 'middle-aged'

This assigns ‘middle-aged’ value to the attribute type_of_user attr_accessor.

getter and setter in Action For attribute type_of_user getter and setter methods are created as follows,

# getter
def type_of_user
  @type_of_user
end

# setter
def type_of_user=(val)
  @type_of_user = val
end

And these are used whenever we assign or retrieve values from the attr_accessor.

  1. Usage in Classes Whenever changing value of the attr_accessor variables, we need to use self.variable_name = to assign new value to the variable. Otherwise, it will consider it as a local variable resulting into incorrect values.

For example,

class SimpleService

  attr_accessor :name

  def initialize(name)
    @name = name
  end

  def process
    if false # some condition met
      name = 'Akshay'
    end
    name
  end
end

Here, it the above service class we have defined name as the attr_accessor. We need to change it’s value based on some condition. And we return it’s value from process method.

When we execute this class as,

SimpleService.new('John Doe').process
=> nil

We can see that process method has returned nil.

Explaination

In the block,

def process
  if false # some condition met
    name = 'Akshay'
  end
  name
end

As the if condition is false, and value of name is returned from the process method, name is considered as the local variable. Local variable name does not have any value. Thus, it returns nil.

Correction

To correct the above service class, we need to use explicity self when assigning value to the attr_accessor variable as given below,

class SimpleService

  attr_accessor :name

  def initialize(name)
    @name = name
  end

  def process
    if false # some condition met
      self.name = 'Akshay'
    end
    name
  end
end

Now if we execute this class, we will get expected result as given below.

SimpleService.new('John Doe').process
=> "John Doe"
  1. Lifetime of attr_accessor attr_accessor is accessible throughout object’s lifecycle. When object is saved using any of ActiveRecord method, save, update etc. all attributes of Model other than attr_accessor are saved in the database.

How to Access Throughout lifecycle of object, you can access the value of attribute accessor as follows,

new_user.type_of_user
  1. Conclusion We learned what is attr_accessor in Rails and how to use it with Rails .

What's new in Ruby 2.5?

2017-10-12 09:27:58 +0000

Ruby 2.5.0-preview1 Released

useful image

We are pleased to announce the release of Ruby 2.5.0-preview1.

Ruby 2.5.0-preview1 is the first preview release toward Ruby 2.5.0. It introduces some new features and performance improvements, for example:

After installing the beta version through rvm …

 tinix   rvm install 2.5.0-preview1
Searching for binary rubies, this might take some time.
No binary rubies available for: debian/9/x86_64/ruby-2.5.0-preview1.
Continuing with compilation. Please read 'rvm help mount' to get more information on binary rubies.
Checking requirements for debian.
Requirements installation successful.
Installing Ruby from source to: /home/tinix/.rvm/rubies/ruby-2.5.0-preview1, this may take a while depending on your cpu(s)...
ruby-2.5.0-preview1 - #downloading ruby-2.5.0-preview1, this may take a while depending on your connection...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 13.4M  100 13.4M    0     0  1693k      0  0:00:08  0:00:08 --:--:-- 2192k
No checksum for downloaded archive, recording checksum in user configuration.
ruby-2.5.0-preview1 - #extracting ruby-2.5.0-preview1 to /home/tinix/.rvm/src/ruby-2.5.0-preview1....
ruby-2.5.0-preview1 - #configuring.............................................|
ruby-2.5.0-preview1 - #post-configuration..
ruby-2.5.0-preview1 - #compiling.........................................................................|
ruby-2.5.0-preview1 - #installing..............
ruby-2.5.0-preview1 - #making binaries executable..
Rubygems 2.6.14 already available in installed ruby, skipping installation, use --force to reinstall.
ruby-2.5.0-preview1 - #gemset created /home/tinix/.rvm/gems/ruby-2.5.0-preview1@global
ruby-2.5.0-preview1 - #importing gemset /home/tinix/.rvm/gemsets/global.gems.............................|
ruby-2.5.0-preview1 - #generating global wrappers........
ruby-2.5.0-preview1 - #gemset created /home/tinix/.rvm/gems/ruby-2.5.0-preview1
ruby-2.5.0-preview1 - #importing gemsetfile /home/tinix/.rvm/gemsets/default.gems evaluated to empty gem list
ruby-2.5.0-preview1 - #generating default wrappers........
ruby-2.5.0-preview1 - #adjusting #shebangs for (gem irb erb ri rdoc testrb rake).
Install of ruby-2.5.0-preview1 - #complete
Ruby was built without documentation, to build it run: rvm docs generate-ri
 tinix  
 

The 2.5.0-preview1Ruby language version has just been released. Because it is not a stable version, its use is not yet recommended .

** Inverse backtrace**

The backtrace (list of methods that were run before an error happened) will start to be displayed in reverse order. Using the following code as an example:

#file test.rb

def a
   b
end

def b
   c
end

def c
   raise 'error'
end

a

if the same file is run in ruby 2.4 you get…

$ ruby test.rb
test.rb:10:in `c': error (RuntimeError)
    from test.rb:6:in `b'
    from test.rb:2:in `a'
    from test.rb:13:in `<main>'
	Rescue / else / ensure will be allowed inside of / end blocks

Running with Ruby 2.4:

Currently we can only capture exceptions within methods or blocks begin/ end, ie:

begin
  raise 'boom'
rescue Exception => e
  puts "Error caught: #{e.message}"
end

: Output Error caught: boom

def my_method
  raise boom
  rescue Exception => and
  puts "Error caught: # {e.message}"
end

: Output Error caught: boom.

But the code below doesn’t work:

[1, 2, 3].map do |i|
  raise 'boom'
  rescue Exception => e
  puts "Error caught: #{e.message}"
end
syntax error, unexpected keyword_rescue, expecting keyword_end
rescue Exception => e

Running with Ruby 2.5:

In the version that is about to be released, this is possible. The output of the above code will be:

Captured error: boom
Captured error: boom
Captured error: boom

New method yield_self

According to the official documentation Ruby 2.5

  • Yields self to the block and returns the result of the block.

Although very similar to the tapclass method Object(which is very useful, by the way), your returns are different.

While with the method tapyou open a block and at the end the object itself is returned, with the yield_self, the result of the block is returned.

Example:

object.tap {| obj | obj.save} # => object

The save method was called, but object is returned

object.yield_self {| obj | obj.save} # => true
#The last block execution will be returned.
#That is, assuming that the `save` method returns` true`,
#the return of this entire line will be `true` too

I could not think of a practical case to use it, but certainly had a reason to have been added :)

Other changes

The new version will also bring other new features, such as support for Unicode version 10, which includes 56 emojis created this year . You can see a complete list with all the news in this document .

To install Ruby 2.5 (though not yet recommended for not being a stable release) through RVM, simply run:

rvm install 2.5.0-preview1

for more information visit Ruby 2.5.0-preview1 Released

Yes!!! Enjoy Ruby 2.5.0-preview1 Released


« Prev 1 2 3 4 Next »


subscribe via RSS