Skip to content

Instantly share code, notes, and snippets.

View samueljoli's full-sized avatar
🔒
lalilulelo

Samuel Joli samueljoli

🔒
lalilulelo
View GitHub Profile
# ---------------------------------------------------------------------------
#
# Description: This file holds all my BASH configurations and aliases
#
# Sections:
# 1. Environment Configuration
# 2. Make Terminal Better (remapping defaults and adding functionality)
# 3. File and Folder Management
# 4. Searching
# 5. Process Management
sentence = <<-something
Steven likes the movies. Blake likes to ride his bike but hates movies.
Blake is taller than steven. Steven is a great teacher.
something
sentence2 = sentence.gsub('.', '').split(' ')
sentence2 = sentence2.collect { |i| i = i.upcase }
num = 1
word = nil
count = 0
counter = 0
flatiron_school = {:teachers=>[{:name=>"steph"}, {:name=>"uzo"}, {:name=>"blake"}], :students => [{:name => "giancarlo", :grade => 100, :address => "bronx"},{:name => "jamie", :grade => 200, :address => "NJ"}]}
flatiron_school.each do |key, value|
value.each do |names|
puts names[:name]
end
end
# Count words in a sentence
require 'pry-nav'
require "pry"
require 'ap'
paragraph = <<-something
Steven likes the movies. Blake likes to ride his bike but hates movies.
Blake is taller than steven. Steven is a great teacher.
something
@samueljoli
samueljoli / issues_with_modules.md
Last active September 6, 2015 15:35 — forked from ryanb/issues_with_modules.md
Points on how modules can make code difficult to read.

My issues with Modules

In researching topics for RailsCasts I often read code in Rails and other gems. This is a great exercise to do. Not only will you pick up some coding tips, but it can help you better understand what makes code readable.

A common practice to organize code in gems is to divide it into modules. When this is done extensively I find it becomes very difficult to read. Before I explain further, a quick detour on instance_eval.

You can find instance_eval used in many DSLs: from routes to state machines. Here's an example from Thinking Sphinx.

class Article &lt; ActiveRecord::Base
@samueljoli
samueljoli / Inbox, e-mail and menu.markdown
Created November 3, 2015 14:56
Inbox, e-mail and menu
@samueljoli
samueljoli / Assembler_I.js
Created January 30, 2017 17:53
Assembler tricks just for kicks
//javascript
if (matches = line.matches(/qty: (\d+)/))
this.quantity = matches[1];
else if (matches = line.matches(/size: (\d+)x(\d)/)
this.width = matches[1];
this.height = matches[2];
else if ... and so-on
#ruby
case line
when /qty: (\d+)/)
this.quantity = $1
when /size: (\d+)x(\d)/
this.width = $1
this.height = $2
#...
end
//javascript... NOT assembler... that would take too long:
var jumpAddressTable = new Array;
jumpAddressTable[0] = function (){ console.log('I like 0')};
jumpAddressTable[1] = function (){ console.log('This is an arbitrary function')};
jumpAddressTable[2] = function (){ console.log('2 is the smallest non-negative prime number')};
jumpAddressTable[3] = function (){ console.log('One more for the show')};
var switchVal = 2;
jumpAddressTable[switchVal]();
//would print '2 is the smallest non-negative prime number'
/more psuedo-JS... yay!
var switchVal = 2;
switch(switchVal) {
case 0:
console.log('I like 0');
break;
case 1:
console.log('This is an arbitrary function');
break;
case 2: