Skip to content

Instantly share code, notes, and snippets.

View armw4's full-sized avatar
🎯
Focusing

Antwan R. Wimberly armw4

🎯
Focusing
  • Stay tuned...
  • Atlanta, GA, USA
View GitHub Profile
@armw4
armw4 / javascript-arguments-semi-demystified.md
Last active December 27, 2015 21:19
Array.prototype.slice is a widely used function in JavaScript. It's typically used when you've got a variable list of arguments (VARARGS...popular in ruby *). The reason you always see slice invoked with 0 is because that's the start index. Think of substring if that makes more sense.

###by Antwan Wimberly###

We'll start with a function that logs the output of calls to Array.prototype.slice; starting from 0 up until n (number of agruments).

function logArgs () {
  var length = arguments.length, args;

  for(var index = 0; index < length; index++) {
 args = Array.prototype.slice.call(arguments, index);
@armw4
armw4 / ruby-instance-variables.md
Last active December 31, 2015 11:28
Setting instance variables in ruby is all about the current value of self. Just because you use @foo = bar...doesn't mean you'll get a new copy of foo for every instance of your class.

###by Antwan Wimberly###

class HiO
  def print_i
    # note...this won't print 12...even though we set
    # this variable in the `toast` method
    puts "my var is #{@var}"

    # and neither will this...failure!!!
@armw4
armw4 / mixins.md
Last active December 31, 2015 14:29
Ruby is such an incredible programming language. One of the cool things I like about it is mixins. You can declaratively add behavior to a class in a very ad-hoc manner. It's so cool....again! One great opportunity I can think of for mixins is when you need to opt out of a base class's functionality in a very DRY (Do No Repeat Yourself...aka...n…

###by Antwan Wimberly###

class Base
  def print_value(value)
    puts value.to_s
  end
end

class DerivedClass < Base; end
@armw4
armw4 / binary-logarithm.md
Last active December 31, 2015 14:29
A little brain teaser for you my dear apprentice...

###by Antwan Wimberly###

Binary logarithm of some number y is some number x, where x is 2 raised to x

2 ^ x = y

x | y
-----
0 | 1
@armw4
armw4 / md5-sha44-sha256-sha384-sha512-python.md
Last active December 31, 2015 18:29
OpenSsl can lead to weird problems with python, brew, and Mac OS X. It all boils down to making sure openssl is pointing to brew's version of openssl, as opposed to your system's version (the default that ships with your OS).

###by Antwan Wimberly###

➜ ~ pip ERROR:root:code for hash md5 was not found. Traceback (most recent call last): File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py", line 139, in globals()[__func_name] = __get_hash(__func_name) File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py", line 91, in __get_builtin_constructor raise ValueError('unsupported hash type ' + name) ValueError: unsupported hash type md5

@armw4
armw4 / Web.config
Last active December 31, 2015 19:19
An experiment with nokogiri. Provides a DSL for ad-hoc element generation similar to how Nokogiri::XML::Builder works. In a separate experiment, I plan to allow composition with builders. You'll be able to heterogeneously mix the builder API with my API.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings />
</configuration>
@armw4
armw4 / dollarz.rb
Last active January 3, 2016 15:59
Well...I've got quite a few nicknames for my dear friend D$...I meant Dollarz...I meant D Dollarz...I meant Danny...uh...yea
DANNY_ALIASES = ["Danny", "D$", "Dollarz", "D Dollarz"]
DANNY_ALIASES.each do |item|
def item.eql? (other)
DANNY_ALIASES.include? other and DANNY_ALIASES.include? self
end
end
DANNY_ALIASES.each_with_index do |item, index|
if next_item = DANNY_ALIASES[index + 1]
@armw4
armw4 / dollarz.js
Last active January 3, 2016 15:59
Well...he wasn't satisfied...wanted to see it in JavaScript...sigh
var DANNY_ALIASES = ['Danny', 'D$', 'Dollarz', 'D Dollarz'];
// hwa? why isn't he using underscore or loadash? #STFUUUUUUU!!!!!
DANNY_ALIASES.include = function(item) {
var include = false;
for(var i = 0; i < this.length; i++) {
if (this[i] == item) {
include = true;
break;
@armw4
armw4 / override-inherited-method-ad-hoc-block.rb
Created January 24, 2014 20:13
I wanted to know if you could arbitrarily pass a block to an overridden method via "super". It seems like an obvious "yes", but my curiosity got the better of me once more. Normally you call "super" with no arguments. Don't recall ever seeing it invoked with a block. So there you have it...
class Base
def deploy(&block)
puts "work"
yield if block_given?
puts "done working"
end
end
class Derived < Base
def deploy
@armw4
armw4 / ruby-array-truthiness.rb
Created January 25, 2014 23:12
Don't sleep on arrays. When looking for a "truthy" value, you need to ensure the array has been initialized (not nil), AND also that it's length is a positive integer.
my_array = []
puts "It's alive" if my_array # truthy...empty array does not return false
puts "It's alive" if my_array.length # truthy again....0 does not return false
# the ultimate truthy test for arrays...finally we get back false..hence no output
puts "It's alive" if my_array && my_array.length > 0