Skip to content

Instantly share code, notes, and snippets.

@astopo
astopo / sort.rb
Created July 9, 2014 00:13 — forked from aspyct/sort.rb
# Sample implementation of quicksort and mergesort in ruby
# Both algorithm sort in O(n * lg(n)) time
# Quicksort works inplace, where mergesort works in a new array
def quicksort(array, from=0, to=nil)
if to == nil
# Sort the whole array, by default
to = array.count - 1
end
def maximum(numbers)
largest = numbers.first
index = 0
# keep looping over every element in the array
while index < numbers.size
# check to see if current number is larger than the largest one so far
@astopo
astopo / self.md
Created July 14, 2014 20:14
self in Ruby

The self keyword allows for access to the current object.

When you call a method on an object, such as object.method, the object receives a method message. The object will respond to the method if there is a method defined for it. Inside that method, you have access to the object via the keyword self.

When you call a method without an explicit receiving object, it just calls it on self.

If you are inside an instance method but need access to a class method, you would use self.class.method_you_want

@astopo
astopo / 0_reuse_code.js
Last active August 29, 2015 14:09
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@astopo
astopo / simple-js-hash.md
Created November 15, 2014 17:56
Simple non-secure Javascript Hashing #js #hashing #hash
String.prototype.hashCode = function() {
  var hash = 0, i, chr, len;
  if (this.length == 0) return hash;
  for (i = 0, len = this.length; i < len; i++) {
    chr   = this.charCodeAt(i);
    hash  = ((hash << 5) - hash) + chr;
    hash |= 0; // Convert to 32bit integer
  }
 return hash;
@astopo
astopo / angular-calling-order.md
Created June 3, 2015 16:05
Angular Calling Order
  1. .config()
  2. .run()
  3. directive compile functions
  4. controllers
  5. directive link functions
@astopo
astopo / psql.md
Created July 27, 2015 02:16
Postgres psql - export and import database

Export a database to .sql file

pg_dump -U username dbname > outfile.sql

Importing a db.sql file

psql -U username dbname < db.sql

Importing to Heroku

@astopo
astopo / show-timestamp.md
Created March 29, 2017 17:24
Get commit timestamp

git show -s --format=%ci COMMIT

@astopo
astopo / cordova-select-ios-target-device.md
Created April 24, 2017 16:33
Cordova - select iOS target device

List available devices:

cordova emulate ios --list

Examples of how to select target:

cordova emulate ios --target="iPhone-4s, 9.3"
cordova emulate ios --target="iPad-Air-2, 9.3"
cordova emulate ios --target="iPhone-6s, 9.3"
@astopo
astopo / flatten-array.js
Created July 2, 2019 14:08
Flatten an array of arbitrarily nested arrays of integers into a flat array of integers.
module.exports = flattenArray
/**
* Flatten a multi-dimensional array.
*
* @param {Number[]} array
*/
function flattenArray(array) {
return array.reduce((result, el) => {
// If the element is an array, continue to flatten it.