Skip to content

Instantly share code, notes, and snippets.

View bih's full-sized avatar
😄

Bilawal Hameed bih

😄
View GitHub Profile
@bih
bih / test_data.json
Created December 23, 2013 00:56
Test data for iPhone app
[{"longitude":-82.965972900391,"latitude":35.090648651123,"title":"Rainbow Falls","subtitle":"Nantahala National Forest"},{"longitude":-82.966093558105,"latitude":35.092520895652,"title":"Turtleback Falls","subtitle":"Nantahala National Forest"},{"longitude":-82.95916,"latitude":35.07496,"title":"Windy Falls"}]
@bih
bih / MergeSort.markdown
Last active December 31, 2022 14:20
MergeSort Example in Ruby

MergeSort Algorithm in Ruby

When learning about sorting algorithms, I wanted to implement them to help me understand them better. This algorithm was originally invented by John von Neumann in 1948.

The Ruby script attached explains in real code what is going on. Play about with it.

How does the algorithm work?

Step by step:

  • Pass through an array of unsorted numbers (i.e. [4, 3, 2, 10])
@bih
bih / palindromic.rb
Last active August 29, 2015 13:57
Palindromic numbers in Ruby
class Fixnum
def is_palindromic?
self.to_s == self.to_s.reverse
end
end
100.is_palindromic? # => false
2002.is_palindromic? # => true
@bih
bih / Gemfile.markdown
Created March 28, 2014 15:45
Parse yo' Gemfile

Parse yo' Gemfile

Want to parse a Gemfile? This finely does it. How you may ask? This file replicates the entire Gemfile functions (aka source, gem and group) and then executes the Gemfile in Ruby.

Security

As it executes the Gemfile, it can potentially contain malicious Ruby code. This could import your project and perform commands and I would recommend executing it in a safe/sandbox environment. An example would be through an external server and use an API. This way it is very easy to replicate your software and it is totally harmless.

<3 Have fun.

Example

Example Gemfile:

@bih
bih / 2048.js
Created March 30, 2014 14:15
Instant win of Gabriele's 2048 game.
# Need a way to kill the addictiveness of the 2048 game? Paste this into yo' console.
# http://gabrielecirulli.github.io/2048/
var t;(t=new GameManager(4,KeyboardInputManager,HTMLActuator,LocalStorageManager));t.startTiles=0;t.setup();while(t.grid.cellsAvailable()){t.grid.insertTile(new Tile(t.grid.randomAvailableCell(), 1024));};t.actuate();
@bih
bih / thesummit.js
Created April 11, 2014 20:41
Find out the largest ranked nominees for The Summit Kilimanjaro Climb
// Quickly analyse the results from The Summit's Kilimanjro Climb. Thought it'd be nice to share after using it myself.
// Works on: http://thesummit.co/kilimanjaro/nominees-alpha
// Works on: http://thesummit.co/kilimanjaro/nominees-individual
var v,n,s={}; $('ul.video-grid li').each(function(){ n=$(this).find('.video-grid-details h5').text(); v=parseInt($(this).find('.video-grid-details p em').text()) || 0; s[n] = v; }); s;
@bih
bih / irb.rb
Created June 12, 2014 09:19
Build your own interactive shell in Ruby
require "irb"
require "irb/completion"
def hi
"World"
end
IRB.start
# ruby app.rb
@bih
bih / iphone.rb
Last active June 6, 2022 12:39
Get all of your iPhone data via USB (relies on libimobiledevice - https://github.com/libimobiledevice/libimobiledevice)
require "json"
class IOS
def self.get
q = `ideviceinfo`
IOS.new(q.split("\n").map{ |item| k, v = item.split(": ", 2); { k.strip.to_sym => v.strip }})
rescue
nil
end
@bih
bih / jquery.matchHeightWith.js
Last active August 29, 2015 14:22
jQuery.matchHeightWith.js - Match two divs heights together.
/**
* jQuery function to match two div heights. Disables for mobiles so the experience is better.
*/
$.fn.matchHeightWith = function(jqSelector) {
if(/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
return;
}
var match_a = $(this).height();
//
// BHSwipeButton.swift
// HelloHub
//
// Created by Bilawal Hameed on 09/08/2015.
// Copyright (c) 2015 HelloHub. All rights reserved.
//
import Foundation
import UIKit