Skip to content

Instantly share code, notes, and snippets.

View dinks's full-sized avatar

Dinesh Vasudevan dinks

View GitHub Profile
@dinks
dinks / test.rb
Created January 19, 2015 17:08
nil? v/s empty? v/s blank?
# Rails
nil.nil? # true
"".empty? # true
[].empty? # true
{}.empty? # true
nil.empty? # NoMethodError
" ".empty? # false
nil.blank? # true
@dinks
dinks / fix_minutes.rb
Created January 19, 2015 10:28
Fix Minutes
# https://blog.engineyard.com/2015/five-ruby-methods-you-should-be-using
def convert_to_hours(minutes)
hours = 0
until (0..60).include? minutes
hours -= (60 <=> minutes)
minutes += 60 * (60 <=> minutes)
end
{
hours: hours,

Mac OS X 10.9 Mavericks

Custom recipe to get OS X 10.9 Mavericks running from scratch, setup applications and developer environment. I use this gist to keep track of the important software and steps required to have a functioning system after a semi-annual fresh install.

Install Software

The software selected is software that is "tried and true" --- software I need after any fresh install. I often install other software not listed here, but is handled in a case-by-case basis.

Install from App Store

@dinks
dinks / wat.cpp
Created January 2, 2015 16:20
Wat in C++
// http://madebyevan.com/obscure-cpp-features/
// ptr[3] is *(ptr + 3) and is therefore 3[ptr]
// Is this:
// 1) A variable of type std::string initialized to a std::string()?
// 2) The declaration of a function that returns a std::string and has one argument,
// which is a pointer to a function with no arguments that returns a std::string?
std::string foo(std::string());
// Is this:
@dinks
dinks / wat.rb
Last active August 29, 2015 14:12
Wat in ruby
nil.to_i.nil? # false
"x".to_i == 0 # true
"12xhdhsjh".to_i == 12 # true
# Rails 4
{surprise: true, 'surprise' => false}.symbolize_keys
# {:surprise => false}
{surprise: true, 'surprise' => false}.symbolize_keys!
# {:surprise => false}
@dinks
dinks / wat.php
Created January 2, 2015 15:59
wat in php
// '0', 0, and 0.0 are false, but '0.0' is true
// If a function returns an Array, you just can not write
$first_element = function_returns_array()[0]; //Syntax ERROR!!
$first_element = ( function_returns_array() )[0]; //This neither!!
//Instead you must write
$a = function_returns_array();
$first_element = $a[0];
@dinks
dinks / pp.js
Created November 20, 2014 09:31
Promise Patterns
// https://remysharp.com/2014/11/19/my-five-promise-patterns
// Clean shallow chains
var writeFile = Promise.denodeify(fs.writeFile);
writeFile(filename, content)
.then(addDBUser)
.then(dns)
.then(configureHeroku)
.then(function () {
console.log('All done');
});
@dinks
dinks / wat.js
Last active August 29, 2015 14:09
WAT
// https://wiki.theory.org/YourLanguageSucks
// + Always does a valueOf and then a toString
// because + could only be done with integers and strings
// Number and String are the code conversions
[] + [] // ""
// Explaination
// ([]).valueOf() returns the same array and then ([]).toString() returns ""
@dinks
dinks / eval.js
Last active August 29, 2015 14:09
Eval Gotcha
var x = 'global';
function indirectEval() {
'use strict';
var x = 'local';
console.log(eval('x')); // Local
// Call eval in a different way
console.log(eval.call(null, 'x')); // global
@dinks
dinks / curry.js
Last active August 29, 2015 14:09
Currying Javascript
function t1(a, b, c) {
console.log(a, b, c);
}
t1(1, 2, 3); // 1 2 3
t2 = t1.bind(undefined, 10);
t2(2, 3); // 10 2 3
t3 = t2.bind(undefined, 20); // t3 = t1.bind(undefined, 10, 20);