Skip to content

Instantly share code, notes, and snippets.

@alyssais
alyssais / baddom.js
Created November 10, 2012 16:03
Loads of bad DOM.
// There's this…
$(function() {
$('#add-entry').attr('id', 'add-member').click(function() {
$('#edit').remove();
$(this).after(
$('<input>', {
type: 'submit',
name: 'add',
@alyssais
alyssais / twitter.php
Last active December 14, 2015 12:38
Uses the built-in dictionary in a *nix system to run through every word in the dictionary from shortest to longest and find available Twitter usernames. Usage: `php -f path/to/twitter.php`.
<?php
// Made by Ross Penman (@PenmanRoss, rosspenman.com)
ob_implicit_flush();
$words = trim(file_get_contents("/usr/share/dict/words"));
$words = explode("\n", $words);
$sorted_words = array();
@alyssais
alyssais / RAPQueueManager.h
Last active December 16, 2015 14:09
This is a queue manager I quickly threw together last night. Basically just manages some dispatch_queue_t objects and organises them based on arbitrary integer keys you pass. Will automatically create queues when requested.
#import <Foundation/Foundation.h>
@interface RAPQueueManager : NSObject
{
NSMutableDictionary *queues;
}
@property (retain) NSString *label;
- (id)initWithLabel:(NSString *)label;
@alyssais
alyssais / SWRevealViewController.podspec
Created May 6, 2013 11:19
Podspec for latest commit of SWRevealViewController
Pod::Spec.new do |s|
s.name = "SWRevealViewController"
s.version = "0.0.2" # totally arbitrary.
s.summary = "A UIViewController subclass for presenting two view controllers inspired in the FaceBook app, done right."
s.homepage = "https://github.com/John-Lluch/SWRevealViewController"
s.license = "BSD"
s.author = { "John Lluch Zorrilla" => "joan.lluch@sweetwilliamsl.com" }
s.source = { :git => "https://github.com/John-Lluch/SWRevealViewController.git", :commit => "e82eb22a4c3a0d134b1ea317b904e042605544e2" }
@alyssais
alyssais / UIBarButtonItem+CustomButton.h
Created May 11, 2013 10:19
Makes it easier to use custom UIButtons for the crappy UIBarButtonItems in a bar.
//
// UIBarButtonItem+CustomButton.h
//
// Created by Ross Penman on 11/05/2013.
// Copyright (c) 2013 Ross Penman. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface UIBarButtonItem (CustomButton)
@alyssais
alyssais / iTunes.rb
Created May 15, 2013 20:12
Calculates the time that Apple will reach 50 billion apps.
require 'net/http'
require 'json'
puts ""
MAX = 50 * 10 ** 9 # 50 billion
# Get the URL of the JSON in case Apple changes it.
url = URI.parse 'http://images.apple.com/v/itunes/shared/counter/a/scripts/counter.js'
req = Net::HTTP::Get.new url.path
@alyssais
alyssais / TVC.m
Created September 22, 2013 14:48
My (probably wrong) way of doing dynamic height UITableViewCells.
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
CGFloat TEXT_VIEW_MARGIN_X = 14; // gap between edge of cell and edge of text view
CGFloat TEXT_VIEW_INSET_X = 5; // gap between edge of text view and text inside
CGFloat TEXT_VIEW_INSET_Y = 9; // gap between top/bottom of text view and text inside
NSString *text = [self lorem];
CGSize constraint = CGSizeMake(tableView.bounds.size.width - (TEXT_VIEW_MARGIN_X + TEXT_VIEW_INSET_X) * 2, CGFLOAT_MAX);
CGSize size = [text boundingRectWithSize:constraint options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:17]} context:nil].size;
@alyssais
alyssais / randomusers.js
Created October 1, 2013 12:57
Gets lots of users from randomiser.me.
var request = require("request");
var _ = require("underscore");
var fs = require("fs");
var usernames = [];
var REQS = 100;
for (var i = 0; i < REQS; i++) {
request("http://api.randomuser.me?results=5", function(response, error, body) {
@alyssais
alyssais / gist:7398998
Created November 10, 2013 14:35
HELLO!
THIS IS FUN
@alyssais
alyssais / leaderboard.js
Last active April 19, 2024 02:26
A script to calculate a leaderboard for Node Knockout 2013.
var async = require("async"),
request = require("request"),
_ = require("lodash"),
cheerio = require("cheerio");
var get = function(url, callback) {
request(url, function(error, response, body) {
if (error) {
console.error(error);
return;