Skip to content

Instantly share code, notes, and snippets.

View armandocanals's full-sized avatar
👾
0_0

Armando Canals armandocanals

👾
0_0
View GitHub Profile
@armandocanals
armandocanals / slideRuler.m
Last active August 29, 2015 13:59
Slide Ruler UIView
UIScrollView* timer = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 120, 700, 60)];
timer.backgroundColor = [UIColor whiteColor];
timer.delegate = self;
timer.scrollEnabled = YES;
timer.contentSize = CGSizeMake(_createView.frame.size.width+700, 60);
[self addTopBorder:timer];
for (int i = 55; i > 0; i--) {
UIView *tine = [[UIView alloc] initWithFrame:CGRectMake((i*12), 1, 1, 7)];
@armandocanals
armandocanals / Character_Frequency.rb
Last active December 28, 2015 09:29
Most frequent letters, in order, occurring in the 1000 most common words (http://www.giwersworld.org/computers/linux/common-words.phtml)
# This is a dump of the word list
text = File.read ARGV[0]
words = text.split("\n")
hash = {}
words.each do |word|
word.each_char do |l|
hash[l] ||= 0
if hash.keys.include?(l)
hash[l] += 1
@armandocanals
armandocanals / getElementsByClassName.js
Last active July 27, 2017 15:30
Recursive method to find elements by class name
function getElementsByClassName(className) {
var elements = document.body,
matches = [];
function traverse(node) {
for(var i = 0; i < node.childNodes.length; i++) {
if(node.childNodes[i].childNodes.length > 0) {
traverse(node.childNodes[i]);
}
@armandocanals
armandocanals / anagram.rb
Last active December 14, 2015 12:18
Group all words that are anagrams of one another
#!/usr/bin/ruby
# Group all words that are anagrams of one another
# example:
# sample set of words
# dict = %w[cat tar war store core orb bro rat]
# $ ruby anagram.rb
# expect
# {
# "act"=>["cat"],
class Node
attr_accessor :next, :data
def push(str)
new_node= Node.new
new_node.data = str
node = self
while node.next
@armandocanals
armandocanals / retina_detect
Created March 20, 2012 02:07
Detect retina asset in DOM using javascript
function retina(selector) {
var element = document.querySelector(selector);
var images = Array.prototype.slice.apply(element.getElementsByTagName("img"));
var extension = "_2x";
if (window.devicePixelRatio === 2) {
images.forEach(function(img, idx) {
var src = img.getAttribute('src');
img.setAttribute('src', src.replace(/(\.jpg|\.png|\.gif)$/, extension + '$&'));
img.onerror = function(evt) {
img.setAttribute('src', src);
@armandocanals
armandocanals / gist:939961
Created April 24, 2011 23:06
SMS Blast using Twilio
require 'rubygems'
require 'open-uri'
require 'csv'
require 'rest_client'
csv = open("path/to/file.csv") # I choose csv, you can choose whatever file you want to loop through
arr = []
CSV.parse(csv) do |row|
cell_num = row[2] #row for cell number
home_num = row[3] #row for home_num