Archive for the ‘Ruby’ Category

Rails: Add data from seeds to db in 1 Line

rake db:seed

Ruby: Define a custom method

We define methods with the word def and close methods with end. In between we write the method body, or the action our method performs.
Let’s look at an example:

def year
 puts "It's 1995!"
end

year

Here our def year method outputs “It’s 1995!”. To run our method, we must call it with year. Otherwise it will not execute.
Methods can use parameters. A parameter is an object we pass to our method, of any type. It works like a variable.

def year(current)
  puts "It's #{current}!"
end

year(2020)

Here our year method takes a numbercurrentas a parameter. It outputs the year 2020 that we pass in.

Source: Codecademy.com

Ruby: Interpolation

Another way of calling a variable is through interpolation.Interpolation allows us to refer to our variable again by placing it between#{}:

hackrspets = ["Precious", "Lindy", "Arctica"]
puts "I have owned three pets in my life: #{pets}"

=> "I have owned three pets in my life: ["Precious", "Lindy", "Arctica"]"

Ruby: Variables

Variables are used to to store objects so we can access them again. We can store any object, including strings, numbers, booleans, arrays, and hashes as a variable.

Source: Codecademy

Ruby: Hashes

shoppinglist = {"spycamera" => 34.00, "invisibleink" => 2.00, "talcumpowder" => 8.00}

We can access any value by naming its key:

shoppinglist["talcumpowder"]
=> 8.00

As you can see, this will return the value, 8.00.
rubylang

Ruby: Objects

Ruby objects: Strings, numbers, booleans, arrays, hashes

Strings are words or numbers between quotes. “apple” and “Atlantic Ocean” are strings.
Numbers are well, numbers! Ruby has two types, floats and integers. Floats are decimals like 3.14. Integers are positive or negative whole numbers like 75 or -10.

Booleans are true or false statements:
1 == 1 is a true statement.
1 == 5 is a false statement.

Arrays are lists of objects. They are another information type in Ruby, and are also objects themselves! We create an array by declaring the array name and listing the objects between brackets.

Hashes help us store information. They are another information type in Ruby, and are also objects. They are similar to arrays except objects are stored as a pair known as a key and a value. We list the pairs, and enclose the hash in curly braces.

Ruby: Array elements are zero-anchored

puts hackrtopics[0]
=> "datasci"

puts hackrtopics[1]
=> "hpc"

puts hackrtopics[2]
=> "econometrics"

rubylang

White & Black box Debuggers, Intelligent Debugging, and Dynamic Analysis

Debugging is a common task for data scientists, programmers, and security experts alike. In good ole RStudio we have a nice, simple built-in white-box debugger. For many analysis-oriented coders, the basic debugging functionality of an IDE like RStudio is all they know and it may be a surprise that debugging is a bigger, much sexier, topic. Below I define and describe key topics in debugging and dynamic analysis, as well as provide links to the most cutting edge free debuggers I use.

Dynamic Analysis: Runtime tracing of a process, usually performed using a debugger. Dynamic Analysis is critical for exploit development, fuzzer assistance, and malware inspection.

Debugger: a program that is used to test and troubleshoot other programs.Intelligent Debugger: a scriptable debugger that supports extended features such as call hooking, such as Immunity Debugger and PyDbg.

White Box Debugger: Debuggers built into IDEs and other dev platforms, which enable developers to trace through source code with a high degree of control, as to aide in the troubleshooting of functions and other code breakages.
Black Box Debugger: Used by bug hunters and reverse engineers, black box debuggers operate on compiled programs when the source code is not available and the only information is available in a disassembled format. There are two broad subclasses of black box debuggers, which are user mode (i.e. ring 3) and kernel mode (i.e. ring 0).
User mode black box debugger: a processor mode under which your applications run, usually with the least amount of privilege (e.g. double clicking PuTTY.exe launches a user-mode process).
Kernel mode black box debugger: a processor mode where the core of the OS runs using the highest amount of privilege (e.g. capturing packets with a network adapter that is in passive mode).
User-mode Debuggers Commonly used among Reverse Engineers
WinDbg by Microsoft
OllyDbg by Oleh Yuschuk, a F.O.S.S. debugger
GNU Debugger (gdb), a F.O.S.S. Linux debugger by the community
Script_Debugger

Ruby: How to Install Rails

http://rubyonrails.org/download/

gem install rails
install devkit (google for install commands)
Create your application skeleton and start the server:

rails new path/to/your/new/application
cd path/to/your/new/application

rails server

You’re running Ruby on Rails! Follow the instructions on  http://localhost:3000

Ruby: Download with curl in 1 Line

ruby -e “$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)”