이데아

테스트 포스트

철학 공부를 가장한 취미 생활 공간입니다.
1/* stringmerge.c -- Given two sorted files of strings, it creates
2 * a sorted file consisting of all their elements.
3 * The names of the files are passed as command
4 * line parameters.
5 */
6
7#include <stdio.h>
8#define MAXBUFFER 128
9
10int getline(FILE * fd, char buff[], int nmax){
11 /* It reads a line from fd and stores up to nmax of
12 * its characters to buff.
13 */
14 char c;
15 int n=0;
16
17 while ((c=getc(fd))!='\n'){
18 if(c==EOF)return EOF;
19 if(n<nmax)
20 buff[n++]=c;
21 }
22 buff[n]='\0';
23 return n;
24}
25
26int stringMerge(char filename1[], char filename2[] , char filename3[]) {
27 /* Given two sorted files of strings, called filename1 and filename2,
28 * it writes their merged sequence to the file filename3.
29 * It returns the total number of strings written to filename3.
30 */
31 FILE *fd1, *fd2, *fd3;
32 char buffer1[MAXBUFFER], buffer2[MAXBUFFER];
33 int ln1, ln2;
34 int n=0;
35
36 if ((fd1=fopen(filename1, "r"))==NULL) {
37 perror("fopen");
38 exit(1);
39 }
40 if ((fd2=fopen(filename2, "r"))==NULL) {
41 perror("fopen");
42 exit(1);
43 }
44 if ((fd3=fopen(filename3, "w"))==NULL) {
45 perror("fopen");
46 exit(1);
47 }
48
49 ln1 = getline(fd1,buffer1,MAXBUFFER-1);
50 ln2 = getline(fd2,buffer2,MAXBUFFER-1);
51
52 while ((ln1!=EOF) && (ln2!=EOF)){
53 if (strcmp(buffer1,buffer2)<=0){
54 fprintf(fd3, "%s\n", buffer1);
55 ln1 = getline(fd1,buffer1,MAXBUFFER-1);
56 }else{
57 fprintf(fd3, "%s\n", buffer2);
58 ln2 = getline(fd2,buffer2,MAXBUFFER-1);
59 }
60 n++;
61 }
62
63 while (ln1!=EOF){
64 fprintf(fd3, "%s\n", buffer1);
65 ln1=getline(fd1,buffer1,MAXBUFFER-1);
66 n++;
67 }
68
69 while (ln2!=EOF){
70 fprintf(fd3, "%s\n", buffer2);
71 ln2=getline(fd2,buffer2,MAXBUFFER-1);
72 n++;
73 }
74
75 fclose(fd1);
76 fclose(fd2);
77 fclose(fd3);
78 return n;
79}
80
81int main(int argc, char *argv[]) {
82 if(argc!=4){
83 printf("Usage: %s sortedfile1 sortedfile2 mergefile\n", argv[0]);
84 exit(0);
85 }
86 printf("We have %d merged records\n",
87 stringMerge(argv[1], argv[2], argv[3]));
88}
#include "ContactsModel.h"
#include "core/IdentityManager.h"
#include "core/ContactsManager.h"
#include <QDebug>

inline bool contactSort(const ContactUser *c1, const ContactUser *c2)
{
    if (c1->status() != c2->status())
        return c1->status() < c2->status();
    return c1->nickname().localeAwareCompare(c2->nickname()) < 0;
}

ContactsModel::ContactsModel(QObject *parent)
    : QAbstractListModel(parent), m_identity(0)
{
}

void ContactsModel::setIdentity(UserIdentity *identity)
{
    if (identity == m_identity)
        return;

    beginResetModel();

    foreach (ContactUser *user, contacts)
        user->disconnect(this);
    contacts.clear();

    if (m_identity) {
        disconnect(m_identity, 0, this, 0);
        disconnect(&m_identity->contacts, 0, this, 0);
    }

    m_identity = identity;

    if (m_identity) {
        connect(&identity->contacts, SIGNAL(contactAdded(ContactUser*)), SLOT(contactAdded(ContactUser*)));

        contacts = identity->contacts.contacts();
        std::sort(contacts.begin(), contacts.end(), contactSort);

        foreach (ContactUser *user, contacts)
            connectSignals(user);
    }

    endResetModel();
    emit identityChanged();
}

QModelIndex ContactsModel::indexOfContact(ContactUser *user) const
{
    int row = contacts.indexOf(user);
    if (row < 0)
        return QModelIndex();
    return index(row, 0);
}

ContactUser *ContactsModel::contact(int row) const
{
    return contacts.value(row);
}

void ContactsModel::updateUser(ContactUser *user)
{
    if (!user)
    {
        user = qobject_cast<ContactUser*>(sender());
        if (!user)
            return;
    }

    int row = contacts.indexOf(user);
    if (row < 0)
    {
        user->disconnect(this);
        return;
    }

    QList<ContactUser*> sorted = contacts;
    std::sort(sorted.begin(), sorted.end(), contactSort);
    int newRow = sorted.indexOf(user);

    if (row != newRow)
    {
        beginMoveRows(QModelIndex(), row, row, QModelIndex(), (newRow > row) ? (newRow+1) : newRow);
        contacts = sorted;
        endMoveRows();
    }
    emit dataChanged(index(newRow, 0), index(newRow, 0));
}

void ContactsModel::connectSignals(ContactUser *user)
{
    connect(user, SIGNAL(statusChanged()), SLOT(updateUser()));
    connect(user, SIGNAL(nicknameChanged()), SLOT(updateUser()));
    connect(user, SIGNAL(contactDeleted(ContactUser*)), SLOT(contactRemoved(ContactUser*)));
}

void ContactsModel::contactAdded(ContactUser *user)
{
    Q_ASSERT(!indexOfContact(user).isValid());

    connectSignals(user);

    QList<ContactUser*>::Iterator lp = qLowerBound(contacts.begin(), contacts.end(), user, contactSort);
    int row = lp - contacts.begin();

    beginInsertRows(QModelIndex(), row, row);
    contacts.insert(lp, user);
    endInsertRows();
}

void ContactsModel::contactRemoved(ContactUser *user)
{
    if (!user && !(user = qobject_cast<ContactUser*>(sender())))
        return;

    int row = contacts.indexOf(user);
    beginRemoveRows(QModelIndex(), row, row);
    contacts.removeAt(row);
    endRemoveRows();

    disconnect(user, 0, this, 0);
}

QHash<int,QByteArray> ContactsModel::roleNames() const
{
    QHash<int, QByteArray> roles;
    roles[Qt::DisplayRole] = "name";
    roles[PointerRole] = "contact";
    roles[StatusRole] = "status";
    return roles;
}

int ContactsModel::rowCount(const QModelIndex &parent) const
{
    if (parent.isValid())
        return 0;
    return contacts.size();
}

QVariant ContactsModel::data(const QModelIndex &index, int role) const
{
    if (!index.isValid() || index.row() >= contacts.size())
        return QVariant();

    ContactUser *user = contacts[index.row()];

    switch (role)
    {
    case Qt::DisplayRole:
    case Qt::EditRole:
        return user->nickname();
    case PointerRole:
        return QVariant::fromValue(user);
    case StatusRole:
        return user->status();
    }

    return QVariant();
}
1using System.Collections.Generic;
2using System.Linq;
3using Abp.Domain.Entities;
4using Abp.Domain.Repositories;
5
6namespace Abp.MemoryDb.Repositories
7{
8 //TODO: Implement thread-safety..?
9 public class MemoryRepository<TEntity, TPrimaryKey> : AbpRepositoryBase<TEntity, TPrimaryKey>
10 where TEntity : class, IEntity<TPrimaryKey>
11 {
12 private readonly IMemoryDatabaseProvider _databaseProvider;
13 protected MemoryDatabase Database { get { return _databaseProvider.Database; } }
14
15 protected List<TEntity> Table { get { return Database.Set<TEntity>(); } }
16
17 private readonly MemoryPrimaryKeyGenerator<TPrimaryKey> _primaryKeyGenerator;
18
19 public MemoryRepository(IMemoryDatabaseProvider databaseProvider)
20 {
21 _databaseProvider = databaseProvider;
22 _primaryKeyGenerator = new MemoryPrimaryKeyGenerator<TPrimaryKey>();
23 }
24
25 public override IQueryable<TEntity> GetAll()
26 {
27 return Table.AsQueryable();
28 }
29
30 public override TEntity Insert(TEntity entity)
31 {
32 if (entity.IsTransient())
33 {
34 entity.Id = _primaryKeyGenerator.GetNext();
35 }
36
37 Table.Add(entity);
38 return entity;
39 }
40
41 public override TEntity Update(TEntity entity)
42 {
43 var index = Table.FindIndex(e => EqualityComparer<TPrimaryKey>.Default.Equals(e.Id, entity.Id));
44 if (index >= 0)
45 {
46 Table[index] = entity;
47 }
48
49 return entity;
50 }
51
52 public override void Delete(TEntity entity)
53 {
54 Delete(entity.Id);
55 }
56
57 public override void Delete(TPrimaryKey id)
58 {
59 var index = Table.FindIndex(e => EqualityComparer<TPrimaryKey>.Default.Equals(e.Id, id));
60 if (index >= 0)
61 {
62 Table.RemoveAt(index);
63 }
64 }
65 }
66}
body {
  font-family: arial;
}

h1, p, table {
  background-color:#CCC;
  border: 1px solid;
  color:#39F;
  text-align: center;
  width: 100%;
}

.addon-store .pagehead h1 { display: inline-block }
.addon-store .addon-summary:after { clear: both }

#addon-store .pagehead .electrocat-small {
    bottom: -7px;
    position: absolute;
    right: 0;
}

.addon-store .addons-nav a.selected {
    border-bottom-color: #d26911;
    color: #333;
    font-weight: bold;
    padding: 0 0 14px;
}

.addon-store .addon-icon {
    background: #fff;
    border: 1px solid #ddd;
    box-shadow: 0 1px 2px rgba(0,0,0,0.15);
    float: left;
    height: 80px;
    margin-right: 14px;
    width: 80px;
}

.addon-store .developer-callout {
    background-color: #f1f1f1;
    background-image: -moz-linear-gradient(#fafafa, #f1f1f1);
    background-image: -webkit-linear-gradient(#fafafa, #f1f1f1);
    background-image: linear-gradient(#fafafa, #f1f1f1);
    background-repeat: repeat-x;
    border: 1px solid #ddd;
    border-bottom: 1px solid #ccc;
    border-radius: 3px;
    box-shadow: inset 0 1px 0 #fff, 0 1px 5px #f1f1f1;
    margin-top: 40px;
    text-shadow: 0 1px 0 #fff;
}

.addon-field-editor .addon-field-list, .addon-field-editor .addon-new-field {
    -moz-box-sizing: border-box;
    border-radius: 3px;
    box-sizing: border-box;
    display: inline-block;
    text-align: center;
    width: 595px;
}
<!DOCTYPE html>
<html lang="en">
  <head>
    <!-- Meta, title, CSS, favicons, etc. -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">
    <title>Bootstrap</title>

    <!-- Bootstrap core CSS -->
    <link href="./dist/css/bootstrap.css" rel="stylesheet">

    <!-- Documentation extras -->
    <link href="./assets/css/docs.css" rel="stylesheet">
    <link href="./assets/css/pygments-manni.css" rel="stylesheet">

    <link rel="shortcut icon" href="./assets/ico/favicon.png">
  </head>

  <body class="bs-docs-home">

  <!-- Docs master nav -->
  <div class="navbar navbar-inverse navbar-fixed-top bs-docs-nav">
    <div class="container">
      <a href="./" class="navbar-brand">Bootstrap 3 RC1</a>
      <button class="navbar-toggle" type="button" data-toggle="collapse" data-target=".bs-navbar-collapse">
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <div class="nav-collapse collapse bs-navbar-collapse">
          <ul class="nav navbar-nav">
            <li>
              <a href="./getting-started">Getting started</a>
            </li>
            <li>
              <a href="./css">CSS</a>
            </li>
            <li>
              <a href="./components">Components</a>
            </li>
            <li>
              <a href="./javascript">JavaScript</a>
            </li>
            <li>
              <a href="./customize">Customize</a>
            </li>
          </ul>
      </div>
    </div>
  </div>

  <!-- Page content of course! -->
  <div class="bs-masthead">
    <div class="container">
      <h1>Bootstrap 3</h1>
      <p class="lead">Sleek, intuitive, and powerful mobile-first front-end framework for faster and easier web development.</p>
      <p>
        <a href="http://getbootstrap.com/bs-v3.0.0-rc1-dist.zip" class="btn btn-bs btn-large" onclick="_gaq.push(['_trackEvent', 'Jumbotron actions', 'Download', 'Download 3.0.0 RC1']);">Download Bootstrap</a>
      </p>
    </div>
  </div>

  <script src="./assets/js/jquery.js"></script>
  <script src="./dist/js/bootstrap.js"></script>
  <script src="./assets/js/holder.js"></script>
  <script src="./assets/js/application.js"></script>

</body>
</html>
import java.util.Scanner;

public class Life {
    public static void show(boolean[][] grid){
        String s = "";
        for(boolean[] row : grid){
            for(boolean val : row)
                if(val)
                    s += "*";
                else
                    s += ".";
            s += "\n";
        }
        System.out.println(s);
    }

    public static boolean[][] gen(){
        boolean[][] grid = new boolean[10][10];
        for(int r = 0; r < 10; r++)
            for(int c = 0; c < 10; c++)
                if( Math.random() > 0.7 )
                    grid[r][c] = true;
        return grid;
    }

    public static void main(String[] args){
        boolean[][] world = gen();
        show(world);
        System.out.println();
        world = nextGen(world);
        show(world);
        Scanner s = new Scanner(System.in);
        while(s.nextLine().length() == 0){
            System.out.println();
            world = nextGen(world);
            show(world);

        }
    }

    public static boolean[][] nextGen(boolean[][] world){
        boolean[][] newWorld
            = new boolean[world.length][world[0].length];
        int num;
        for(int r = 0; r < world.length; r++){
            for(int c = 0; c < world[0].length; c++){
                num = numNeighbors(world, r, c);
                if( occupiedNext(num, world[r][c]) )
                    newWorld[r][c] = true;
            }
        }
        return newWorld;
    }

    public static boolean occupiedNext(int numNeighbors, boolean occupied){
        if( occupied && (numNeighbors == 2 || numNeighbors == 3))
            return true;
        else if (!occupied && numNeighbors == 3)
            return true;
        else
            return false;
    }

    private static int numNeighbors(boolean[][] world, int row, int col) {
        int num = world[row][col] ? -1 : 0;
        for(int r = row - 1; r <= row + 1; r++)
            for(int c = col - 1; c <= col + 1; c++)
                if( inbounds(world, r, c) && world[r][c] )
                    num++;

        return num;
    }

    private static boolean inbounds(boolean[][] world, int r, int c) {
        return r >= 0 && r < world.length && c >= 0 &&
        c < world[0].length;
    }
}
// Cross-browser xml parsing
var parseXML = function( data ) {
  var xml, tmp;
  if ( !data || typeof data !== "string" ) {
    return null;
  }
  try {
    if ( window.DOMParser ) { // Standard
      tmp = new DOMParser();
      xml = tmp.parseFromString( data , "text/xml" );
    } else { // IE
      xml = new ActiveXObject( "Microsoft.XMLDOM" );
      xml.async = false;
      xml.loadXML( data );
    }
  } catch( e ) {
    xml = undefined;
  }
  if ( !xml || !xml.documentElement || xml.getElementsByTagName( "parsererror" ).length ) {
    jQuery.error( "Invalid XML: " + data );
  }
  return xml;
};

// Bind a function to a context, optionally partially applying any arguments.
var proxy = function( fn, context ) {
  var tmp, args, proxy;

  if ( typeof context === "string" ) {
    tmp = fn[ context ];
    context = fn;
    fn = tmp;
  }

  // Quick check to determine if target is callable, in the spec
  // this throws a TypeError, but we will just return undefined.
  if ( !jQuery.isFunction( fn ) ) {
    return undefined;
  }

  // Simulated bind
  args = core_slice.call( arguments, 2 );
  proxy = function() {
    return fn.apply( context || this, args.concat( core_slice.call( arguments ) ) );
  };

  // Set the guid of unique handler to the same of original handler, so it can be removed
  proxy.guid = fn.guid = fn.guid || jQuery.guid++;

  return proxy;
};

Sound.play = function() {}
Sound.prototype = { something; }
Sound.prototype.play = function() {}
Sound.prototype.play = myfunc
var parser = document.createElement('a');
parser.href = "http://example.com:3000/pathname/?search=test#hash";
parser.hostname; // => "example.com"
\documentclass[12pt]{article}
% options include 12pt or 11pt or 10pt
% classes include article, report, book, letter, thesis

\title{This is the title}
\author{Author One \\ Author Two}
\date{29 February 2004}

\usepackage{pstricks}
\setlength{\textheight}{12.5cm}
\setlength{\textwidth}{16.0cm}

\newcommand{\cloud}[1]{
 \psset{unit=#1cm}
 \pspicture(2,4)
 \psarc(2,0){1.25}{210}{35}
 \psarc(0,0){1.25}{105}{320}
 \psarc(0.2,.75){.75}{45}{145}
 \psarc(1.8,.5){1.15}{5}{150}%
 \endpspicture
 }

\setlength{\parindent}{0mm}
\setlength{\parskip}{5mm}


\begin{document}
\maketitle

This is the content of this document.

This is the 2nd paragraph.
Here is an inline formula:
$   V = \frac{4 \pi r^3}{3}  $.
And appearing immediately below
is a displayed formula:
$$  V = \frac{4 \pi r^3}{3}  $$

This is a cloud size 0.3: ~ ~ ~ ~ ~ \cloud{0.3}

This is a cloud size 0.9: ~ ~ ~ ~ ~ \cloud{0.9}

\end{document}
local IO = require "kong.tools.io"
local utils = require "kong.tools.utils"
local cache = require "kong.tools.database_cache"
local stringy = require "stringy"
local constants = require "kong.constants"
local responses = require "kong.tools.responses"
local timestamp = require "kong.tools.timestamp"

-- Define the plugins to load here, in the appropriate order
local plugins = {}

local _M = {}

local function load_plugin_conf(api_id, consumer_id, plugin_name)
  local cache_key = cache.plugin_configuration_key(plugin_name, api_id, consumer_id)

  local plugin = cache.get_and_set(cache_key, function()
    local rows, err = dao.plugins_configurations:find_by_keys {
        api_id = api_id,
        consumer_id = consumer_id ~= nil and consumer_id or constants.DATABASE_NULL_ID,
        name = plugin_name
      }
      if err then
        return responses.send_HTTP_INTERNAL_SERVER_ERROR(err)
      end

      if #rows > 0 then
        return table.remove(rows, 1)
      else
        return { null = true }
      end
  end)

  if plugin and not plugin.null and plugin.enabled then
    return plugin
  else
    return nil
  end
end

local function init_plugins()
  configuration.plugins_available = configuration.plugins_available and configuration.plugins_available or {}

  print("Discovering used plugins. Please wait..")
  local db_plugins, err = dao.plugins_configurations:find_distinct()
  if err then
    error(err)
  end

  -- Checking that the plugins in the DB are also enabled
  for _, v in ipairs(db_plugins) do
    if not utils.table_contains(configuration.plugins_available, v) then
      error("You are using a plugin that has not been enabled in the configuration: "..v)
    end
  end

  local unsorted_plugins = {} -- It's a multivalue table: k1 = {v1, v2, v3}, k2 = {...}

  for _, v in ipairs(configuration.plugins_available) do
    local loaded, mod = utils.load_module_if_exists("kong.plugins."..v..".handler")
    if not loaded then
      error("The following plugin has been enabled in the configuration but is not installed on the system: "..v)
    else
      print("Loading plugin: "..v)
      local plugin_handler = mod()
      local priority = plugin_handler.PRIORITY and plugin_handler.PRIORITY or 0

      -- Add plugin to the right priority
      local list = unsorted_plugins[priority]
      if not list then list = {} end -- The list is required in case more plugins share the same priority level
      table.insert(list, {
        name = v,
        handler = plugin_handler
      })
      unsorted_plugins[priority] = list
    end
  end

  local result = {}

  -- Now construct the final ordered plugin list
  -- resolver is always the first plugin as it is the one retrieving any needed information
  table.insert(result, {
    resolver = true,
    name = "resolver",
    handler = require("kong.resolver.handler")()
  })

  -- Add the plugins in a sorted order
  for _, v in utils.sort_table_iter(unsorted_plugins, utils.sort.descending) do -- In descending order
    if v then
      for _, p in ipairs(v) do
        table.insert(result, p)
      end
    end
  end

  return result
end
#import "UIView+Facade.h"

@implementation UIView (Facade)


#pragma mark - Alignment Relative To Superview

#pragma mark - Fill superview

- (void)fillSuperview {
    self.frame = CGRectMake(0, 0, CGRectGetWidth(self.superview.frame), CGRectGetHeight(self.superview.frame));
}

#pragma mark - Corner alignment

- (void)anchorTopLeftWithLeftPadding:(CGFloat)left topPadding:(CGFloat)top width:(CGFloat)width height:(CGFloat)height {
    self.frame = CGRectMake(left, top, width, height);
}

- (void)anchorTopRightWithRightPadding:(CGFloat)right topPadding:(CGFloat)top width:(CGFloat)width height:(CGFloat)height {
    self.frame = CGRectMake(CGRectGetWidth(self.superview.frame) - width - right, top, width, height);
}

- (void)anchorBottomLeftWithLeftPadding:(CGFloat)left bottomPadding:(CGFloat)bottom width:(CGFloat)width height:(CGFloat)height {
    self.frame = CGRectMake(left, CGRectGetHeight(self.superview.frame) - height - bottom, width, height);
}

- (void)anchorBottomRightWithRightPadding:(CGFloat)right bottomPadding:(CGFloat)bottom width:(CGFloat)width height:(CGFloat)height {
    self.frame = CGRectMake(CGRectGetWidth(self.superview.frame) - width - right, CGRectGetHeight(self.superview.frame) - height - bottom, width, height);
}


#pragma mark - Center alignment

- (void)anchorInCenterWithWidth:(CGFloat)width height:(CGFloat)height {
    self.frame = CGRectMake((CGRectGetWidth(self.superview.frame) / 2.0) - (width / 2.0), (CGRectGetHeight(self.superview.frame) / 2.0) - (height / 2.0), width, height);
}

- (void)anchorCenterLeftWithLeftPadding:(CGFloat)left width:(CGFloat)width height:(CGFloat)height {
    self.frame = CGRectMake(left, (CGRectGetHeight(self.superview.frame) / 2.0) - (height / 2.0), width, height);
}

- (void)anchorCenterRightWithRightPadding:(CGFloat)right width:(CGFloat)width height:(CGFloat)height {
    self.frame = CGRectMake(CGRectGetWidth(self.superview.frame) - width - right, (CGRectGetHeight(self.superview.frame) / 2.0) - (height / 2.0), width, height);
}

- (void)anchorTopCenterWithTopPadding:(CGFloat)top width:(CGFloat)width height:(CGFloat)height {
    self.frame = CGRectMake((CGRectGetWidth(self.superview.frame) / 2.0) - (width / 2.0), top, width, height);
}

- (void)anchorBottomCenterWithBottomPadding:(CGFloat)bottom width:(CGFloat)width height:(CGFloat)height {
    self.frame = CGRectMake((CGRectGetWidth(self.superview.frame) / 2.0) - (width / 2.0), CGRectGetHeight(self.superview.frame) - height - bottom, width, height);
}


#pragma mark - Filling width / height

- (void)anchorInCenterFillingWidthAndHeightWithLeftAndRightPadding:(CGFloat)leftAndRight topAndBottomPadding:(CGFloat)topAndBottom {
    self.frame = CGRectMake(leftAndRight, topAndBottom, CGRectGetWidth(self.superview.frame) - (2 * leftAndRight), CGRectGetHeight(self.superview.frame) - (2 * topAndBottom));
}

- (void)anchorTopCenterFillingWidthWithLeftAndRightPadding:(CGFloat)leftAndRight topPadding:(CGFloat)top height:(CGFloat)height {
    self.frame = CGRectMake(leftAndRight, top, CGRectGetWidth(self.superview.frame) - (2 * leftAndRight), height);
}

- (void)anchorBottomCenterFillingWidthWithLeftAndRightPadding:(CGFloat)leftAndRight bottomPadding:(CGFloat)bottom height:(CGFloat)height {
    self.frame = CGRectMake(leftAndRight, CGRectGetHeight(self.superview.frame) - height - bottom, CGRectGetWidth(self.superview.frame) - (2 * leftAndRight), height);
}


#pragma mark - Alignment Relative to Siblings

#pragma mark - To the right

- (void)alignToTheRightOf:(UIView *)view matchingTopWithLeftPadding:(CGFloat)left width:(CGFloat)width height:(CGFloat)height {
    self.frame = CGRectMake(CGRectGetMaxX(view.frame) + left, CGRectGetMinY(view.frame), width, height);
}

- (void)alignToTheRightOf:(UIView *)view matchingTopAndFillingWidthWithLeftAndRightPadding:(CGFloat)leftAndRight height:(CGFloat)height {
    self.frame = CGRectMake(CGRectGetMaxX(view.frame) + leftAndRight, CGRectGetMinY(view.frame), CGRectGetWidth(view.superview.frame) - CGRectGetMaxX(view.frame) - (2 * leftAndRight), height);
}

- (void)alignToTheRightOf:(UIView *)view matchingCenterWithLeftPadding:(CGFloat)left width:(CGFloat)width height:(CGFloat)height {
    self.frame = CGRectMake(CGRectGetMaxX(view.frame) + left, CGRectGetMidY(view.frame) - (height / 2.0), width, height);
}

- (void)alignToTheRightOf:(UIView *)view matchingCenterAndFillingWidthWithLeftAndRightPadding:(CGFloat)leftAndRight height:(CGFloat)height {
    self.frame = CGRectMake(CGRectGetMaxX(view.frame) + leftAndRight, CGRectGetMidY(view.frame) - (height / 2.0), CGRectGetWidth(view.superview.frame) - CGRectGetMaxX(view.frame) - (2 * leftAndRight), height);
}

- (void)alignToTheRightOf:(UIView *)view matchingBottomWithLeftPadding:(CGFloat)left width:(CGFloat)width height:(CGFloat)height {
    self.frame = CGRectMake(CGRectGetMaxX(view.frame) + left, CGRectGetMaxY(view.frame) - height, width, height);
}

- (void)alignToTheRightOf:(UIView *)view matchingBottomAndFillingWidthWithLeftAndRightPadding:(CGFloat)leftAndRight height:(CGFloat)height {
    self.frame = CGRectMake(CGRectGetMaxX(view.frame) + leftAndRight, CGRectGetMaxY(view.frame) - height, CGRectGetWidth(view.superview.frame) - CGRectGetMaxX(view.frame) - (2 * leftAndRight), height);
}


#pragma mark - To the left

- (void)alignToTheLeftOf:(UIView *)view matchingTopWithRightPadding:(CGFloat)right width:(CGFloat)width height:(CGFloat)height {
    self.frame = CGRectMake(CGRectGetMinX(view.frame) - width - right, CGRectGetMinY(view.frame), width, height);
}

- (void)alignToTheLeftOf:(UIView *)view matchingTopAndFillingWidthWithLeftAndRightPadding:(CGFloat)leftAndRight height:(CGFloat)height {
    self.frame = CGRectMake(leftAndRight, CGRectGetMinY(view.frame), CGRectGetMinX(view.frame) - (2 * leftAndRight), height);
}

- (void)alignToTheLeftOf:(UIView *)view matchingCenterWithRightPadding:(CGFloat)right width:(CGFloat)width height:(CGFloat)height {
    self.frame = CGRectMake(CGRectGetMinX(view.frame) - width - right, CGRectGetMidY(view.frame) - (height / 2.0), width, height);
}

- (void)alignToTheLeftOf:(UIView *)view matchingCenterAndFillingWidthWithLeftAndRightPadding:(CGFloat)leftAndRight height:(CGFloat)height {
    self.frame = CGRectMake(leftAndRight, CGRectGetMidY(view.frame) - (height / 2.0), CGRectGetMinX(view.frame) - (2 * leftAndRight), height);
}

- (void)alignToTheLeftOf:(UIView *)view matchingBottomWithRightPadding:(CGFloat)right width:(CGFloat)width height:(CGFloat)height {
    self.frame = CGRectMake(CGRectGetMinX(view.frame) - width - right, CGRectGetMaxY(view.frame) - height, width, height);
}

- (void)alignToTheLeftOf:(UIView *)view matchingBottomAndFillingWidthWithLeftAndRightPadding:(CGFloat)leftAndRight height:(CGFloat)height {
    self.frame = CGRectMake(leftAndRight, CGRectGetMaxY(view.frame) - height, CGRectGetMinX(view.frame) - (2 * leftAndRight), height);
}


#pragma mark - Under

- (void)alignUnder:(UIView *)view withLeftPadding:(CGFloat)left topPadding:(CGFloat)top width:(CGFloat)width height:(CGFloat)height {
    self.frame = CGRectMake(left, CGRectGetMaxY(view.frame) + top, width, height);
}

- (void)alignUnder:(UIView *)view withRightPadding:(CGFloat)right topPadding:(CGFloat)top width:(CGFloat)width height:(CGFloat)height {
    self.frame = CGRectMake(CGRectGetMaxX(self.superview.frame) - width - right, CGRectGetMaxY(view.frame) + top, width, height);
}

- (void)alignUnder:(UIView *)view matchingLeftWithTopPadding:(CGFloat)top width:(CGFloat)width height:(CGFloat)height {
    self.frame = CGRectMake(CGRectGetMinX(view.frame), CGRectGetMaxY(view.frame) + top, width, height);
}

- (void)alignUnder:(UIView *)view matchingLeftAndFillingWidthWithRightPadding:(CGFloat)right topPadding:(CGFloat)top height:(CGFloat)height {
    self.frame = CGRectMake(CGRectGetMinX(view.frame), CGRectGetMaxY(view.frame) + top, CGRectGetWidth(view.superview.frame) - CGRectGetMinX(view.frame) - right, height);
}

- (void)alignUnder:(UIView *)view matchingCenterWithTopPadding:(CGFloat)top width:(CGFloat)width height:(CGFloat)height {
    self.frame = CGRectMake(CGRectGetMidX(view.frame) - (width / 2.0), CGRectGetMaxY(view.frame) + top, width, height);
}

- (void)alignUnder:(UIView *)view centeredFillingWidthWithLeftAndRightPadding:(CGFloat)leftAndRight topPadding:(CGFloat)top height:(CGFloat)height {
    self.frame = CGRectMake(leftAndRight, CGRectGetMaxY(view.frame) + top, CGRectGetWidth(view.superview.frame) - (2 * leftAndRight), height);
}

- (void)alignUnder:(UIView *)view centeredFillingWidthAndHeightWithLeftAndRightPadding:(CGFloat)leftAndRight topAndBottomPadding:(CGFloat)topAndBottom {
    self.frame = CGRectMake(leftAndRight, CGRectGetMaxY(view.frame) + topAndBottom, CGRectGetWidth(view.superview.frame) - (2 * leftAndRight), CGRectGetHeight(self.superview.frame) - CGRectGetMaxY(view.frame) - topAndBottom - topAndBottom);
}

- (void)alignUnder:(UIView *)view matchingRightWithTopPadding:(CGFloat)top width:(CGFloat)width height:(CGFloat)height {
    self.frame = CGRectMake(CGRectGetMaxX(view.frame) - width, CGRectGetMaxY(view.frame) + top, width, height);
}

- (void)alignUnder:(UIView *)view matchingRightAndFillingWidthWithLeftPadding:(CGFloat)left topPadding:(CGFloat)top height:(CGFloat)height {
    self.frame = CGRectMake(left, CGRectGetMaxY(view.frame) + top, CGRectGetMinX(view.frame) + CGRectGetWidth(view.frame) - left, height);
}

- (void)alignUnder:(UIView *)view matchingLeftAndRightFillingHeightWithTopPadding:(CGFloat)top bottomPadding:(CGFloat)bottom {
    self.frame = CGRectMake(CGRectGetMinX(view.frame), CGRectGetMaxY(view.frame) + top, CGRectGetWidth(view.frame), CGRectGetHeight(self.superview.frame) - CGRectGetMaxY(view.frame) - top - bottom);
}

- (void)alignUnder:(UIView *)view matchingLeftFillingWidthAndHeightWithRightPadding:(CGFloat)right topPadding:(CGFloat)top bottomPadding:(CGFloat)bottom {
    self.frame = CGRectMake(CGRectGetMinX(view.frame), CGRectGetMaxY(view.frame) + top, CGRectGetWidth(self.superview.frame) - CGRectGetMinX(view.frame) - right, CGRectGetHeight(self.superview.frame) - CGRectGetMaxY(view.frame) - top - bottom);
}
use strict;

#
# This script also prints the contents of all the listed files, but
# it first scans through the list to check that each file exists and
# is readable.  It will stop if there are any errors.
#

my $bad = 0;
foreach my $fn (@ARGV) {
    if(! -r $fn) {
        # File cannot be read.  See if it exists or not for a better
        # error message.
        if(-e $fn) {
            print STDERR "You do not have permission to read $fn.\n";
        } else {
            print STDERR "File $fn does not exist.\n";
        }

        # One way or the other, it's bad.
        $bad = 1;
    }
}

# If there was a problem, bail out.
if($bad) { exit 2; }

# Copy all the files.
while(my $fn = shift @ARGV) {

    # Open the file.
    if(!open(INFILE, $fn)) {
        # We know the file is readable, but sometimes something else goes
        # wrong.  It's safer to check.
        print STDERR "Cannot open $fn: $!\n";
        next;
    }

    # Copy it.
    while(my $l = <INFILE>) {
        print $l;
    }

    close INFILE;
}
<?php

// base class with member properties and methods
class Vegetable {

   var $edible;
   var $color;

   function Vegetable($edible, $color="green")
   {
       $this->edible = $edible;
       $this->color = $color;
   }

   function is_edible()
   {
       return $this->edible;
   }

   function what_color()
   {
       return $this->color;
   }

} // end of class Vegetable

// extends the base class
class Spinach extends Vegetable {

   var $cooked = false;

   function Spinach()
   {
       $this->Vegetable(true, "green");
   }

   function cook_it()
   {
       $this->cooked = true;
   }

   function is_cooked()
   {
       return $this->cooked;
   }

} // end of class Spinach

?>
#!/usr/bin/python
# -*- coding: utf-8 -*-

import re
import sublime
import sublime_plugin
from datetime import datetime


class SublimeTasksBase(sublime_plugin.TextCommand):
    def run(self, edit):
        self.open_tasks_bullet = self.view.settings().get('open_tasks_bullet')
        self.done_tasks_bullet = self.view.settings().get('done_tasks_bullet')
        self.date_format = self.view.settings().get('date_format')
        if self.view.settings().get('done_tag'):
            self.done_tag = "@done"
        else:
            self.done_tag = ""
        self.runCommand(edit)


class NewCommand(SublimeTasksBase):
    def runCommand(self, edit):
        for region in self.view.sel():
            line = self.view.line(region)
            line_contents = self.view.substr(line).rstrip()
            has_bullet = re.match('^(\s*)[' + re.escape(self.open_tasks_bullet) + re.escape(self.done_tasks_bullet) + ']', self.view.substr(line))
            current_scope = self.view.scope_name(self.view.sel()[0].b)
            if has_bullet:
                grps = has_bullet.groups()
                line_contents = self.view.substr(line) + '\n' + grps[0] + self.open_tasks_bullet + ' '
                self.view.replace(edit, line, line_contents)
            elif 'header' in current_scope:
                header = re.match('^(\s*)\S+', self.view.substr(line))
                if header:
                    grps = header.groups()
                    line_contents = self.view.substr(line) + '\n' + grps[0] + ' ' + self.open_tasks_bullet + ' '
                else:
                    line_contents = ' ' + self.open_tasks_bullet + ' '
                self.view.replace(edit, line, line_contents)
                end = self.view.sel()[0].b
                pt = sublime.Region(end, end)
                self.view.sel().clear()
                self.view.sel().add(pt)
            else:
                has_space = re.match('^(\s+)(.*)', self.view.substr(line))
                if has_space:
                    grps = has_space.groups()
                    spaces = grps[0]
                    line_contents = spaces + self.open_tasks_bullet + ' ' + grps[1]
                    self.view.replace(edit, line, line_contents)
                else:
                    line_contents = ' ' + self.open_tasks_bullet + ' ' + self.view.substr(line)
                    self.view.replace(edit, line, line_contents)
                    end = self.view.sel()[0].b
                    pt = sublime.Region(end, end)
                    self.view.sel().clear()
                    self.view.sel().add(pt)
geom_dotplot <- function (mapping = NULL, data = NULL, stat = "bindot", position = "identity",
na.rm = FALSE, binwidth = NULL, binaxis = "x", method="dotdensity", binpositions = "bygroup", stackdir = "up",
stackratio = 1, dotsize = 1, stackgroups = FALSE, ...) {
  GeomDotplot$new(mapping = mapping, data = data, stat = stat, position = position,
  na.rm = na.rm, binwidth = binwidth, binaxis = binaxis, method = method, binpositions = binpositions,
  stackdir = stackdir, stackratio = stackratio, dotsize = dotsize, stackgroups = stackgroups, ...)
}

GeomDotplot <- proto(Geom, {
  objname <- "dotplot"

  new <- function(., mapping = NULL, data = NULL, stat = NULL, position = NULL, ...){
    # This code is adapted from Layer$new. It's needed to pull out the stat_params
    # and geom_params, then manually add binaxis to both sets of params. Otherwise
    # Layer$new will give binaxis only to the geom.

    stat <- Stat$find(stat)
    match.params <- function(possible, params) {
      if ("..." %in% names(possible)) {
        params
      } else {
        params[match(names(possible), names(params), nomatch = 0)]
      }
    }

    params <- list(...)
    # American names must be changed here so that they'll go to geom_params;
    # otherwise they'll end up in stat_params
    params <- rename_aes(params)

    geom_params <- match.params(.$parameters(), params)
    stat_params <- match.params(stat$parameters(), params)
    stat_params <- stat_params[setdiff(names(stat_params), names(geom_params))]
    # Add back binaxis
    stat_params <- c(stat_params, binaxis=params$binaxis)

    # If identical(position, "stack") or position is position_stack() (the test
    #  is kind of complex), tell them to use stackgroups=TRUE instead. Need to
    #  use identical() instead of ==, because == will fail if object is
    #  position_stack() or position_dodge()
    if (!is.null(position) && (identical(position, "stack") || (is.proto(position) && position$objname == "stack")))
      message("position=\"stack\" doesn't work properly with geom_dotplot. Use stackgroups=TRUE instead.")

    if (params$stackgroups && params$method == "dotdensity" && params$binpositions == "bygroup")
      message('geom_dotplot called with stackgroups=TRUE and method="dotdensity". You probably want to set binpositions="all"')

    do.call("layer", list(mapping = mapping, data = data, stat = stat, geom = ., position = position,
                          geom_params = geom_params, stat_params = stat_params, ...))
  }


  reparameterise <- function(., df, params) {
    df$width <- df$width %||%
      params$width %||% (resolution(df$x, FALSE) * 0.9)

    # Set up the stacking function and range
    if(is.null(params$stackdir) || params$stackdir == "up") {
      stackdots <- function(a)  a - .5
      stackaxismin <- 0
      stackaxismax <- 1
    } else if (params$stackdir == "down") {
      stackdots <- function(a) -a + .5
      stackaxismin <- -1
      stackaxismax <- 0
    } else if (params$stackdir == "center") {
      stackdots <- function(a)  a - 1 - max(a - 1) / 2
      stackaxismin <- -.5
      stackaxismax <- .5
    } else if (params$stackdir == "centerwhole") {
      stackdots <- function(a)  a - 1 - floor(max(a - 1) / 2)
      stackaxismin <- -.5
      stackaxismax <- .5
    }


    # Fill the bins: at a given x (or y), if count=3, make 3 entries at that x
    df <- df[rep(1:nrow(df), df$count), ]

    # Next part will set the position of each dot within each stack
    # If stackgroups=TRUE, split only on x (or y) and panel; if not stacking, also split by group
    plyvars <- params$binaxis %||% "x"
    plyvars <- c(plyvars, "PANEL")
    if (is.null(params$stackgroups) || !params$stackgroups)
      plyvars <- c(plyvars, "group")

    # Within each x, or x+group, set countidx=1,2,3, and set stackpos according to stack function
    df <- ddply(df, plyvars, function(xx) {
            xx$countidx <- 1:nrow(xx)
            xx$stackpos <- stackdots(xx$countidx)
            xx
          })


    # Set the bounding boxes for the dots
    if (is.null(params$binaxis) || params$binaxis == "x") {
      # ymin, ymax, xmin, and xmax define the bounding rectangle for each stack
      # Can't do bounding box per dot, because y position isn't real.
      # After position code is rewritten, each dot should have its own bounding box.
      df$xmin <- df$x - df$binwidth / 2
      df$xmax <- df$x + df$binwidth / 2
      df$ymin <- stackaxismin
      df$ymax <- stackaxismax
      df$y    <- 0

    } else if (params$binaxis == "y") {
      # ymin, ymax, xmin, and xmax define the bounding rectangle for each stack
      # Can't do bounding box per dot, because x position isn't real.
      # xmin and xmax aren't really the x bounds, because of the odd way the grob
      # works. They're just set to the standard x +- width/2 so that dot clusters
      # can be dodged like other geoms.
      # After position code is rewritten, each dot should have its own bounding box.
      df <- ddply(df, .(group), transform,
            ymin = min(y) - binwidth[1] / 2,
            ymax = max(y) + binwidth[1] / 2)

      df$xmin <- df$x + df$width * stackaxismin
      df$xmax <- df$x + df$width * stackaxismax
      # Unlike with y above, don't change x because it will cause problems with dodging
    }
    df
  }
class HTMLProcessor

  # called before parsing anything
  def start_parsing(scope_name)
    @line = ""
    @offset = 0
    @text= []
  end

  # called after parsing everything
  def end_parsing(scope_name)
    @text.each_with_index do |line, index|
      @text[index] = "<span class='l l-#{index+1} #{scope_name.gsub('.',' ')}'>#{line}</span>"
    end
    puts @text.join("")
  end

  # called before processing a line
  def new_line(line_content)
    @offset = 0
    @line = line_content.clone
    @text << @line
  end

  def open_tag(tag_name, position_in_current_line)
    tag = "<s class='#{tag_name.gsub("."," ")}'>"
    @line.insert(position_in_current_line + @offset, tag)
    @offset += tag.size
  end

  def close_tag(tag_name, position_in_current_line)
    tag = "</s>"
    @line.insert(position_in_current_line + @offset, tag)
    @offset += tag.size
  end

end

syntax = Textpow.syntax('ruby') # or 'source.ruby' or 'lib/textpow/syntax/source.ruby.syntax'
processor = HTMLProcessor.new
syntax.parse(text, processor)

require File.expand_path('../boot', __FILE__)

require 'rails/all'

if defined?(Bundler)
  # If you precompile assets before deploying to production, use this line
  Bundler.require(*Rails.groups(:assets => %w(development test)))
  # If you want your assets lazily compiled in production, use this line
  # Bundler.require(:default, :assets, Rails.env)
end

require 'rubygems'

# Set up gems listed in the Gemfile.
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)

require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])