chore: code samples, update editor related files
This commit is contained in:
parent
57a1123b41
commit
c827d88763
28
.editorconfig
Normal file
28
.editorconfig
Normal file
@ -0,0 +1,28 @@
|
||||
# EditorConfig is awesome: https://EditorConfig.org
|
||||
|
||||
# top-most EditorConfig file
|
||||
root = true
|
||||
|
||||
# Unix-style newlines with a newline ending every file
|
||||
[*]
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
|
||||
# Matches multiple files with brace expansion notation
|
||||
# Set default charset
|
||||
[*.{js,py}]
|
||||
charset = utf-8
|
||||
|
||||
# 2 space indentation
|
||||
[*.js]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
|
||||
# Tab indentation (no size specified)
|
||||
[Makefile]
|
||||
indent_style = tab
|
||||
|
||||
# Matches the exact files either package.json or .travis.yml
|
||||
[{package.json,.travis.yml}]
|
||||
indent_style = space
|
||||
indent_size = 2
|
197
.gitignore
vendored
197
.gitignore
vendored
@ -1,3 +1,6 @@
|
||||
### Custom ###
|
||||
*.vsix
|
||||
|
||||
### macOS ###
|
||||
# General
|
||||
.DS_Store
|
||||
@ -67,60 +70,10 @@ $RECYCLE.BIN/
|
||||
# Windows shortcuts
|
||||
*.lnk
|
||||
|
||||
### Emacs ###
|
||||
# -*- mode: gitignore; -*-
|
||||
*~
|
||||
\#*\#
|
||||
/.emacs.desktop
|
||||
/.emacs.desktop.lock
|
||||
*.elc
|
||||
auto-save-list
|
||||
tramp
|
||||
.\#*
|
||||
|
||||
# Org-mode
|
||||
.org-id-locations
|
||||
*_archive
|
||||
|
||||
# flymake-mode
|
||||
*_flymake.*
|
||||
|
||||
# eshell files
|
||||
/eshell/history
|
||||
/eshell/lastdir
|
||||
|
||||
# elpa packages
|
||||
/elpa/
|
||||
|
||||
# reftex files
|
||||
*.rel
|
||||
|
||||
# AUCTeX auto folder
|
||||
/auto/
|
||||
|
||||
# cask packages
|
||||
.cask/
|
||||
dist/
|
||||
|
||||
# Flycheck
|
||||
flycheck_*.el
|
||||
|
||||
# server auth directory
|
||||
/server/
|
||||
|
||||
# projectiles files
|
||||
.projectile
|
||||
|
||||
# directory configuration
|
||||
.dir-locals.el
|
||||
|
||||
# network security
|
||||
/network-security.data
|
||||
|
||||
|
||||
### Vim ###
|
||||
# Swap
|
||||
[._]*.s[a-v][a-z]
|
||||
!*.svg # comment out if you don't need vector files
|
||||
[._]*.sw[a-p]
|
||||
[._]s[a-rt-v][a-z]
|
||||
[._]ss[a-gi-z]
|
||||
@ -133,26 +86,148 @@ Sessionx.vim
|
||||
# Temporary
|
||||
.netrwhist
|
||||
*~
|
||||
|
||||
# Auto-generated tag files
|
||||
tags
|
||||
|
||||
# Persistent undo
|
||||
[._]*.un~
|
||||
|
||||
# Coc configuration directory
|
||||
.vim
|
||||
|
||||
### VisualStudioCode ###
|
||||
.vscode/*
|
||||
!.vscode/settings.json
|
||||
!.vscode/tasks.json
|
||||
# !.vscode/launch.json
|
||||
!.vscode/extensions.json
|
||||
!.vscode/launch.json
|
||||
*.code-workspace
|
||||
|
||||
### VisualStudioCode Patch ###
|
||||
# Ignore all local history of files
|
||||
.history
|
||||
.ionide
|
||||
|
||||
### dotenv ###
|
||||
.env
|
||||
|
||||
### Node ###
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
lerna-debug.log*
|
||||
|
||||
# Diagnostic reports (https://nodejs.org/api/report.html)
|
||||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
*.pid.lock
|
||||
|
||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||
lib-cov
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
coverage
|
||||
*.lcov
|
||||
|
||||
# nyc test coverage
|
||||
.nyc_output
|
||||
|
||||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
|
||||
.grunt
|
||||
|
||||
# Bower dependency directory (https://bower.io/)
|
||||
bower_components
|
||||
|
||||
# node-waf configuration
|
||||
.lock-wscript
|
||||
|
||||
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
||||
build/Release
|
||||
|
||||
# Dependency directories
|
||||
node_modules/
|
||||
jspm_packages/
|
||||
|
||||
# TypeScript v1 declaration files
|
||||
typings/
|
||||
|
||||
# TypeScript cache
|
||||
*.tsbuildinfo
|
||||
|
||||
# Optional npm cache directory
|
||||
.npm
|
||||
|
||||
# Optional eslint cache
|
||||
.eslintcache
|
||||
|
||||
# Optional stylelint cache
|
||||
.stylelintcache
|
||||
|
||||
# Microbundle cache
|
||||
.rpt2_cache/
|
||||
.rts2_cache_cjs/
|
||||
.rts2_cache_es/
|
||||
.rts2_cache_umd/
|
||||
|
||||
# Optional REPL history
|
||||
.node_repl_history
|
||||
|
||||
# Output of 'npm pack'
|
||||
*.tgz
|
||||
|
||||
# Yarn Integrity file
|
||||
.yarn-integrity
|
||||
|
||||
# dotenv environment variables file
|
||||
.env
|
||||
.env.test
|
||||
.env*.local
|
||||
|
||||
# parcel-bundler cache (https://parceljs.org/)
|
||||
.cache
|
||||
.parcel-cache
|
||||
|
||||
# Next.js build output
|
||||
.next
|
||||
|
||||
# Nuxt.js build / generate output
|
||||
.nuxt
|
||||
dist
|
||||
|
||||
# Storybook build outputs
|
||||
.out
|
||||
.storybook-out
|
||||
storybook-static
|
||||
|
||||
# rollup.js default build output
|
||||
dist/
|
||||
|
||||
# Gatsby files
|
||||
.cache/
|
||||
# Comment in the public line in if your project uses Gatsby and not Next.js
|
||||
# https://nextjs.org/blog/next-9-1#public-directory-support
|
||||
# public
|
||||
|
||||
# vuepress build output
|
||||
.vuepress/dist
|
||||
|
||||
# Serverless directories
|
||||
.serverless/
|
||||
|
||||
# FuseBox cache
|
||||
.fusebox/
|
||||
|
||||
# DynamoDB Local files
|
||||
.dynamodb/
|
||||
|
||||
# TernJS port file
|
||||
.tern-port
|
||||
|
||||
# Stores VSCode versions used for testing VSCode extensions
|
||||
.vscode-test
|
||||
|
||||
# Temporary folders
|
||||
tmp/
|
||||
temp/
|
||||
|
||||
### Custom ###
|
||||
*.vsix
|
||||
|
59
.markdownlint.jsonc
Normal file
59
.markdownlint.jsonc
Normal file
@ -0,0 +1,59 @@
|
||||
{
|
||||
// vim: ft=jsonc foldlevel=0 sw=2 ts=2 sts=2 et
|
||||
// Conf(current file) is not recognized when commented outside root {}
|
||||
// npm rc standards only recognizes json, ini
|
||||
// Ref
|
||||
// - https://www.npmjs.com/package/rc#standards
|
||||
// - https://github.com/igorshubovych/markdownlint-cli
|
||||
// - https://github.com/DavidAnson/markdownlint
|
||||
// - https://github.com/DavidAnson/markdownlint/blob/main/schema/.markdownlint.jsonc
|
||||
// - https://github.com/DavidAnson/markdownlint/blob/main/doc/Rules.md
|
||||
// Plugins for other editors
|
||||
// - https://marketplace.visualstudio.com/items?itemName=DavidAnson.vscode-markdownlint
|
||||
|
||||
// Default state for all rules
|
||||
"default": true,
|
||||
// Path to configuration file to extend
|
||||
"extends": null,
|
||||
// MD007/ul-indent - Unordered list indentation
|
||||
"MD007": {
|
||||
// Why indent size defaults to 2?
|
||||
// https://github.com/DavidAnson/markdownlint/issues/141
|
||||
// 2 spaces indent has compatibility issues:
|
||||
// - multi-markdown parsers require 4-space indents
|
||||
// - vim sleuth, polyglot have no support for 2 space auto indent with o
|
||||
"indent": 2
|
||||
},
|
||||
// MD010/no-hard-tabs - Hard tabs
|
||||
"MD010": {
|
||||
"code_blocks": false
|
||||
},
|
||||
// MD013/line-length - Line length
|
||||
// VSCode plugin disable this check by default
|
||||
"MD013": false,
|
||||
// "MD013": {
|
||||
// "line_length": 80,
|
||||
// "heading_line_length": 80,
|
||||
// "code_block_line_length": 80,
|
||||
// "code_blocks": false,
|
||||
// "tables": false,
|
||||
// "headings": true,
|
||||
// "strict": false
|
||||
// // "stern": false
|
||||
// },
|
||||
// MD024/no-duplicate-heading/no-duplicate-header - Multiple headings with the same content
|
||||
"MD024": {
|
||||
// Only check sibling headings
|
||||
"siblings_only": true
|
||||
// allow_different_nesting, an alternative
|
||||
},
|
||||
// MD033/no-inline-html - Inline HTML
|
||||
"MD033": {
|
||||
"allowed_elements": [
|
||||
"details", "summary",
|
||||
"kbd"
|
||||
]
|
||||
},
|
||||
// MD034/no-bare-urls - Bare URL used
|
||||
"MD034": false
|
||||
}
|
6
.vscodeignore
Normal file
6
.vscodeignore
Normal file
@ -0,0 +1,6 @@
|
||||
.vscode/**
|
||||
.vscode-test/**
|
||||
.gitignore
|
||||
.editorconfig
|
||||
.markdownlint.jsonc
|
||||
samples/
|
@ -17,5 +17,5 @@ Althought this them defines light ansi colors for terminal, it's designed to be
|
||||
- [VSCode Color Theme Reference](https://code.visualstudio.com/api/references/theme-color)
|
||||
- [One Light tmTheme](https://github.com/akamud/vscode-theme-onelight/blob/master/themes/OneLight.old.tmTheme)
|
||||
- [One Half Light tmTheme](https://tmtheme-editor.herokuapp.com/#!/editor/theme/One%20Half%20Light)
|
||||
- [atom one-light-syntax](https://github.com/atom/atom/tree/master/packages/one-light-syntax)
|
||||
- [GitHub's VS Code themes](https://marketplace.visualstudio.com/items?itemName=GitHub.github-vscode-theme)
|
||||
- [atom one-light-syntax](https://github.com/atom/atom/tree/master/packages/one-light-syntax)
|
||||
|
16
package.json
16
package.json
@ -22,15 +22,16 @@
|
||||
"atom"
|
||||
],
|
||||
"contributes": {
|
||||
"themes": [{
|
||||
"label": "Atom One Half Light",
|
||||
"uiTheme": "vs",
|
||||
"path": "./themes/one-half-light.json"
|
||||
},
|
||||
"themes": [
|
||||
{
|
||||
"label": "Atom One Light",
|
||||
"uiTheme": "vs",
|
||||
"path": "./themes/one-light.json"
|
||||
},
|
||||
{
|
||||
"label": "Atom One Half Light",
|
||||
"uiTheme": "vs",
|
||||
"path": "./themes/one-half-light.json"
|
||||
}
|
||||
]
|
||||
},
|
||||
@ -38,5 +39,10 @@
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/laggardkernel/vscode-theme-onelight"
|
||||
},
|
||||
"__metadata": {
|
||||
"id": "0c29914e-b847-45ea-a032-6ce3ae71e4a9",
|
||||
"publisherDisplayName": "laggardkernel",
|
||||
"publisherId": "df70ce67-198f-4322-843a-96da0feb9b55"
|
||||
}
|
||||
}
|
||||
|
161
samples/c++.cpp
Normal file
161
samples/c++.cpp
Normal file
@ -0,0 +1,161 @@
|
||||
#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();
|
||||
}
|
66
samples/c-sharp.cs
Normal file
66
samples/c-sharp.cs
Normal file
@ -0,0 +1,66 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Abp.Domain.Entities;
|
||||
using Abp.Domain.Repositories;
|
||||
|
||||
namespace Abp.MemoryDb.Repositories
|
||||
{
|
||||
//TODO: Implement thread-safety..?
|
||||
public class MemoryRepository<TEntity, TPrimaryKey> : AbpRepositoryBase<TEntity, TPrimaryKey>
|
||||
where TEntity : class, IEntity<TPrimaryKey>
|
||||
{
|
||||
private readonly IMemoryDatabaseProvider _databaseProvider;
|
||||
protected MemoryDatabase Database { get { return _databaseProvider.Database; } }
|
||||
|
||||
protected List<TEntity> Table { get { return Database.Set<TEntity>(); } }
|
||||
|
||||
private readonly MemoryPrimaryKeyGenerator<TPrimaryKey> _primaryKeyGenerator;
|
||||
|
||||
public MemoryRepository(IMemoryDatabaseProvider databaseProvider)
|
||||
{
|
||||
_databaseProvider = databaseProvider;
|
||||
_primaryKeyGenerator = new MemoryPrimaryKeyGenerator<TPrimaryKey>();
|
||||
}
|
||||
|
||||
public override IQueryable<TEntity> GetAll()
|
||||
{
|
||||
return Table.AsQueryable();
|
||||
}
|
||||
|
||||
public override TEntity Insert(TEntity entity)
|
||||
{
|
||||
if (entity.IsTransient())
|
||||
{
|
||||
entity.Id = _primaryKeyGenerator.GetNext();
|
||||
}
|
||||
|
||||
Table.Add(entity);
|
||||
return entity;
|
||||
}
|
||||
|
||||
public override TEntity Update(TEntity entity)
|
||||
{
|
||||
var index = Table.FindIndex(e => EqualityComparer<TPrimaryKey>.Default.Equals(e.Id, entity.Id));
|
||||
if (index >= 0)
|
||||
{
|
||||
Table[index] = entity;
|
||||
}
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
||||
public override void Delete(TEntity entity)
|
||||
{
|
||||
Delete(entity.Id);
|
||||
}
|
||||
|
||||
public override void Delete(TPrimaryKey id)
|
||||
{
|
||||
var index = Table.FindIndex(e => EqualityComparer<TPrimaryKey>.Default.Equals(e.Id, id));
|
||||
if (index >= 0)
|
||||
{
|
||||
Table.RemoveAt(index);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
88
samples/c.c
Normal file
88
samples/c.c
Normal file
@ -0,0 +1,88 @@
|
||||
/* stringmerge.c -- Given two sorted files of strings, it creates
|
||||
* a sorted file consisting of all their elements.
|
||||
* The names of the files are passed as command
|
||||
* line parameters.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#define MAXBUFFER 128
|
||||
|
||||
int getline(FILE * fd, char buff[], int nmax){
|
||||
/* It reads a line from fd and stores up to nmax of
|
||||
* its characters to buff.
|
||||
*/
|
||||
char c;
|
||||
int n=0;
|
||||
|
||||
while ((c=getc(fd))!='\n'){
|
||||
if(c==EOF)return EOF;
|
||||
if(n<nmax)
|
||||
buff[n++]=c;
|
||||
}
|
||||
buff[n]='\0';
|
||||
return n;
|
||||
}
|
||||
|
||||
int stringMerge(char filename1[], char filename2[] , char filename3[]) {
|
||||
/* Given two sorted files of strings, called filename1 and filename2,
|
||||
* it writes their merged sequence to the file filename3.
|
||||
* It returns the total number of strings written to filename3.
|
||||
*/
|
||||
FILE *fd1, *fd2, *fd3;
|
||||
char buffer1[MAXBUFFER], buffer2[MAXBUFFER];
|
||||
int ln1, ln2;
|
||||
int n=0;
|
||||
|
||||
if ((fd1=fopen(filename1, "r"))==NULL) {
|
||||
perror("fopen");
|
||||
exit(1);
|
||||
}
|
||||
if ((fd2=fopen(filename2, "r"))==NULL) {
|
||||
perror("fopen");
|
||||
exit(1);
|
||||
}
|
||||
if ((fd3=fopen(filename3, "w"))==NULL) {
|
||||
perror("fopen");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
ln1 = getline(fd1,buffer1,MAXBUFFER-1);
|
||||
ln2 = getline(fd2,buffer2,MAXBUFFER-1);
|
||||
|
||||
while ((ln1!=EOF) && (ln2!=EOF)){
|
||||
if (strcmp(buffer1,buffer2)<=0){
|
||||
fprintf(fd3, "%s\n", buffer1);
|
||||
ln1 = getline(fd1,buffer1,MAXBUFFER-1);
|
||||
}else{
|
||||
fprintf(fd3, "%s\n", buffer2);
|
||||
ln2 = getline(fd2,buffer2,MAXBUFFER-1);
|
||||
}
|
||||
n++;
|
||||
}
|
||||
|
||||
while (ln1!=EOF){
|
||||
fprintf(fd3, "%s\n", buffer1);
|
||||
ln1=getline(fd1,buffer1,MAXBUFFER-1);
|
||||
n++;
|
||||
}
|
||||
|
||||
while (ln2!=EOF){
|
||||
fprintf(fd3, "%s\n", buffer2);
|
||||
ln2=getline(fd2,buffer2,MAXBUFFER-1);
|
||||
n++;
|
||||
}
|
||||
|
||||
fclose(fd1);
|
||||
fclose(fd2);
|
||||
fclose(fd3);
|
||||
return n;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
if(argc!=4){
|
||||
printf("Usage: %s sortedfile1 sortedfile2 mergefile\n", argv[0]);
|
||||
exit(0);
|
||||
}
|
||||
printf("We have %d merged records\n",
|
||||
stringMerge(argv[1], argv[2], argv[3]));
|
||||
}
|
71
samples/coffee.coffee
Normal file
71
samples/coffee.coffee
Normal file
@ -0,0 +1,71 @@
|
||||
Application.directive "scopeBar", [], ->
|
||||
replace: true
|
||||
templateUrl: 'partials/scope_bar'
|
||||
|
||||
link: (scope, element, attr) ->
|
||||
preview = element.prev()
|
||||
preview.bind "mouseover", (event) ->
|
||||
active = {}
|
||||
active.scope = event.target.dataset.entityScope
|
||||
|
||||
if active.scope
|
||||
active_scope_rule = getScopeSettings(active.scope)
|
||||
active.name = active_scope_rule.name if active_scope_rule
|
||||
|
||||
scope.$apply ->
|
||||
# Highlight in sidebar
|
||||
scope.$parent.hovered_rule = active_scope_rule
|
||||
|
||||
preview.bind "mouseout", (event) ->
|
||||
# Unhighlight in sidebar
|
||||
scope.$parent.hovered_rule = null
|
||||
|
||||
preview.bind "dblclick", (event) ->
|
||||
active = {}
|
||||
active.scope = event.target.dataset.entityScope
|
||||
|
||||
if active.scope
|
||||
active_scope_rule = getScopeSettings(active.scope)
|
||||
showPopover active_scope_rule, event
|
||||
|
||||
|
||||
|
||||
showPopover = (rule, event) ->
|
||||
scope.$apply ->
|
||||
scope.$parent.new_popover_visible = false
|
||||
scope.$parent.popover_rule = rule
|
||||
scope.$parent.edit_popover_visible = true
|
||||
|
||||
popover = $("#edit-popover")
|
||||
|
||||
if popover.is('.slide')
|
||||
left_offset = $("#gallery").width()
|
||||
else
|
||||
left_offset = 0
|
||||
|
||||
offset =
|
||||
left: (popover.width() / 2) + 10 + left_offset
|
||||
top: 24
|
||||
|
||||
popover.css({
|
||||
"left": event.pageX - offset.left
|
||||
"top": event.pageY + offset.top
|
||||
}).addClass("on-bottom")
|
||||
|
||||
|
||||
getScopeSettings = (active_scope) ->
|
||||
return unless scope.$parent.jsonTheme.settings
|
||||
|
||||
return scope.$parent.jsonTheme.settings.find (item) ->
|
||||
return unless item.scope
|
||||
|
||||
item_scopes = item.scope.split(', ')
|
||||
|
||||
match = item_scopes.filter (item_scope) ->
|
||||
item_scopes_arr = item_scope.split('.')
|
||||
active_scope_arr = active_scope.split('.')
|
||||
|
||||
return (item_scopes_arr.subtract active_scope_arr).length < 1
|
||||
|
||||
return item if match.length
|
||||
|
77
samples/css.css
Normal file
77
samples/css.css
Normal file
@ -0,0 +1,77 @@
|
||||
body {
|
||||
font-family: arial;
|
||||
}
|
||||
|
||||
h1, p, table {
|
||||
background-color:#CCC;
|
||||
border: 1px solid;
|
||||
color:#39F;
|
||||
text-align: center;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
/* Bootstrap snipit */
|
||||
@media (min-width: 992px) and (max-width: 1199px) {
|
||||
.hidden-md,
|
||||
tr.hidden-md,
|
||||
th.hidden-md,
|
||||
td.hidden-md {
|
||||
display: none !important;
|
||||
}
|
||||
}
|
||||
|
||||
/* originally authored by Nick Pettit - https://github.com/nickpettit/glide */
|
||||
@-webkit-keyframes pulse {
|
||||
50% {
|
||||
-webkit-transform: scale(1.1);
|
||||
transform: scale(1.1);
|
||||
}
|
||||
}
|
||||
@keyframes pulse {
|
||||
50% {
|
||||
-webkit-transform: scale(1.1);
|
||||
-ms-transform: scale(1.1);
|
||||
transform: scale(1.1);
|
||||
}
|
||||
}
|
||||
.pulse {
|
||||
-webkit-animation-name: pulse;
|
||||
animation-name: pulse;
|
||||
}
|
||||
|
||||
.addon-store .pagehead h1 { display: inline-block }
|
||||
.addon-store .addon-summary:after { clear: both }
|
||||
|
||||
.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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
99
samples/erlang.erl
Normal file
99
samples/erlang.erl
Normal file
@ -0,0 +1,99 @@
|
||||
-module(cowboy_protocol).
|
||||
|
||||
%% API.
|
||||
-export([start_link/4]).
|
||||
|
||||
%% Internal.
|
||||
-export([init/4]).
|
||||
-export([parse_request/3]).
|
||||
-export([resume/6]).
|
||||
|
||||
-type opts() :: [{compress, boolean()}
|
||||
| {env, cowboy_middleware:env()}
|
||||
| {max_empty_lines, non_neg_integer()}
|
||||
| {max_header_name_length, non_neg_integer()}
|
||||
| {max_header_value_length, non_neg_integer()}
|
||||
| {max_headers, non_neg_integer()}
|
||||
| {max_keepalive, non_neg_integer()}
|
||||
| {max_request_line_length, non_neg_integer()}
|
||||
| {middlewares, [module()]}
|
||||
| {onresponse, cowboy:onresponse_fun()}
|
||||
| {timeout, timeout()}].
|
||||
-export_type([opts/0]).
|
||||
|
||||
-record(state, {
|
||||
socket :: inet:socket(),
|
||||
transport :: module(),
|
||||
middlewares :: [module()],
|
||||
compress :: boolean(),
|
||||
env :: cowboy_middleware:env(),
|
||||
onresponse = undefined :: undefined | cowboy:onresponse_fun(),
|
||||
max_empty_lines :: non_neg_integer(),
|
||||
req_keepalive = 1 :: non_neg_integer(),
|
||||
max_keepalive :: non_neg_integer(),
|
||||
max_request_line_length :: non_neg_integer(),
|
||||
max_header_name_length :: non_neg_integer(),
|
||||
max_header_value_length :: non_neg_integer(),
|
||||
max_headers :: non_neg_integer(),
|
||||
timeout :: timeout(),
|
||||
until :: non_neg_integer() | infinity
|
||||
}).
|
||||
|
||||
-include_lib("cowlib/include/cow_inline.hrl").
|
||||
-include_lib("cowlib/include/cow_parse.hrl").
|
||||
|
||||
%% API.
|
||||
|
||||
-spec start_link(ranch:ref(), inet:socket(), module(), opts()) -> {ok, pid()}.
|
||||
start_link(Ref, Socket, Transport, Opts) ->
|
||||
Pid = spawn_link(?MODULE, init, [Ref, Socket, Transport, Opts]),
|
||||
{ok, Pid}.
|
||||
|
||||
%% Internal.
|
||||
|
||||
%% Faster alternative to proplists:get_value/3.
|
||||
get_value(Key, Opts, Default) ->
|
||||
case lists:keyfind(Key, 1, Opts) of
|
||||
{_, Value} -> Value;
|
||||
_ -> Default
|
||||
end.
|
||||
|
||||
-spec init(ranch:ref(), inet:socket(), module(), opts()) -> ok.
|
||||
init(Ref, Socket, Transport, Opts) ->
|
||||
ok = ranch:accept_ack(Ref),
|
||||
Timeout = get_value(timeout, Opts, 5000),
|
||||
Until = until(Timeout),
|
||||
case recv(Socket, Transport, Until) of
|
||||
{ok, Data} ->
|
||||
OnFirstRequest = get_value(onfirstrequest, Opts, undefined),
|
||||
case OnFirstRequest of
|
||||
undefined -> ok;
|
||||
_ -> OnFirstRequest(Ref, Socket, Transport, Opts)
|
||||
end,
|
||||
Compress = get_value(compress, Opts, false),
|
||||
MaxEmptyLines = get_value(max_empty_lines, Opts, 5),
|
||||
MaxHeaderNameLength = get_value(max_header_name_length, Opts, 64),
|
||||
MaxHeaderValueLength = get_value(max_header_value_length, Opts, 4096),
|
||||
MaxHeaders = get_value(max_headers, Opts, 100),
|
||||
MaxKeepalive = get_value(max_keepalive, Opts, 100),
|
||||
MaxRequestLineLength = get_value(max_request_line_length, Opts, 4096),
|
||||
Middlewares = get_value(middlewares, Opts, [cowboy_router, cowboy_handler]),
|
||||
Env = [{listener, Ref}|get_value(env, Opts, [])],
|
||||
OnResponse = get_value(onresponse, Opts, undefined),
|
||||
parse_request(Data, #state{socket=Socket, transport=Transport,
|
||||
middlewares=Middlewares, compress=Compress, env=Env,
|
||||
max_empty_lines=MaxEmptyLines, max_keepalive=MaxKeepalive,
|
||||
max_request_line_length=MaxRequestLineLength,
|
||||
max_header_name_length=MaxHeaderNameLength,
|
||||
max_header_value_length=MaxHeaderValueLength, max_headers=MaxHeaders,
|
||||
onresponse=OnResponse, timeout=Timeout, until=Until}, 0);
|
||||
{error, _} ->
|
||||
terminate(#state{socket=Socket, transport=Transport}) %% @todo ridiculous
|
||||
end.
|
||||
|
||||
-spec until(timeout()) -> non_neg_integer() | infinity.
|
||||
until(infinity) ->
|
||||
infinity;
|
||||
until(Timeout) ->
|
||||
{Me, S, Mi} = os:timestamp(),
|
||||
Me * 1000000000 + S * 1000 + Mi div 1000 + Timeout.
|
84
samples/go.go
Normal file
84
samples/go.go
Normal file
@ -0,0 +1,84 @@
|
||||
// Reading and writing files are basic tasks needed for
|
||||
// many Go programs. First we'll look at some examples of
|
||||
// reading files.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
)
|
||||
|
||||
// Reading files requires checking most calls for errors.
|
||||
// This helper will streamline our error checks below.
|
||||
func check(e error) {
|
||||
if e != nil {
|
||||
panic(e)
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
||||
// Perhaps the most basic file reading task is
|
||||
// slurping a file's entire contents into memory.
|
||||
dat, err := ioutil.ReadFile("/tmp/dat")
|
||||
check(err)
|
||||
fmt.Print(string(dat))
|
||||
|
||||
// You'll often want more control over how and what
|
||||
// parts of a file are read. For these tasks, start
|
||||
// by `Open`ing a file to obtain an `os.File` value.
|
||||
f, err := os.Open("/tmp/dat")
|
||||
check(err)
|
||||
|
||||
// Read some bytes from the beginning of the file.
|
||||
// Allow up to 5 to be read but also note how many
|
||||
// actually were read.
|
||||
b1 := make([]byte, 5)
|
||||
n1, err := f.Read(b1)
|
||||
check(err)
|
||||
fmt.Printf("%d bytes: %s\n", n1, string(b1))
|
||||
|
||||
// You can also `Seek` to a known location in the file
|
||||
// and `Read` from there.
|
||||
o2, err := f.Seek(6, 0)
|
||||
check(err)
|
||||
b2 := make([]byte, 2)
|
||||
n2, err := f.Read(b2)
|
||||
check(err)
|
||||
fmt.Printf("%d bytes @ %d: %s\n", n2, o2, string(b2))
|
||||
|
||||
// The `io` package provides some functions that may
|
||||
// be helpful for file reading. For example, reads
|
||||
// like the ones above can be more robustly
|
||||
// implemented with `ReadAtLeast`.
|
||||
o3, err := f.Seek(6, 0)
|
||||
check(err)
|
||||
b3 := make([]byte, 2)
|
||||
n3, err := io.ReadAtLeast(f, b3, 2)
|
||||
check(err)
|
||||
fmt.Printf("%d bytes @ %d: %s\n", n3, o3, string(b3))
|
||||
|
||||
// There is no built-in rewind, but `Seek(0, 0)`
|
||||
// accomplishes this.
|
||||
_, err = f.Seek(0, 0)
|
||||
check(err)
|
||||
|
||||
// The `bufio` package implements a buffered
|
||||
// reader that may be useful both for its efficiency
|
||||
// with many small reads and because of the additional
|
||||
// reading methods it provides.
|
||||
r4 := bufio.NewReader(f)
|
||||
b4, err := r4.Peek(5)
|
||||
check(err)
|
||||
fmt.Printf("5 bytes: %s\n", string(b4))
|
||||
|
||||
// Close the file when you're done (usually this would
|
||||
// be scheduled immediately after `Open`ing with
|
||||
// `defer`).
|
||||
f.Close()
|
||||
|
||||
}
|
71
samples/haskell.hs
Normal file
71
samples/haskell.hs
Normal file
@ -0,0 +1,71 @@
|
||||
module Main where
|
||||
|
||||
import Paths_postgrest (version)
|
||||
|
||||
import PostgREST.App
|
||||
import PostgREST.Middleware
|
||||
import PostgREST.Error(errResponse)
|
||||
|
||||
import Control.Monad (unless)
|
||||
import Control.Monad.IO.Class (liftIO)
|
||||
import Data.String.Conversions (cs)
|
||||
import Network.Wai (strictRequestBody)
|
||||
import Network.Wai.Middleware.Cors (cors)
|
||||
import Network.Wai.Handler.Warp hiding (Connection)
|
||||
import Network.Wai.Middleware.Gzip (gzip, def)
|
||||
import Network.Wai.Middleware.Static (staticPolicy, only)
|
||||
import Network.Wai.Middleware.RequestLogger (logStdout)
|
||||
import Data.List (intercalate)
|
||||
import Data.Version (versionBranch)
|
||||
import qualified Hasql as H
|
||||
import qualified Hasql.Postgres as P
|
||||
import Options.Applicative hiding (columns)
|
||||
|
||||
import PostgREST.Config (AppConfig(..), argParser, corsPolicy)
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
let opts = info (helper <*> argParser) $
|
||||
fullDesc
|
||||
<> progDesc (
|
||||
"PostgREST "
|
||||
<> prettyVersion
|
||||
<> " / create a REST API to an existing Postgres database"
|
||||
)
|
||||
parserPrefs = prefs showHelpOnError
|
||||
conf <- customExecParser parserPrefs opts
|
||||
let port = configPort conf
|
||||
|
||||
unless (configSecure conf) $
|
||||
putStrLn "WARNING, running in insecure mode, auth will be in plaintext"
|
||||
unless ("secret" /= configJwtSecret conf) $
|
||||
putStrLn "WARNING, running in insecure mode, JWT secret is the default value"
|
||||
Prelude.putStrLn $ "Listening on port " ++
|
||||
(show $ configPort conf :: String)
|
||||
|
||||
let pgSettings = P.ParamSettings (cs $ configDbHost conf)
|
||||
(fromIntegral $ configDbPort conf)
|
||||
(cs $ configDbUser conf)
|
||||
(cs $ configDbPass conf)
|
||||
(cs $ configDbName conf)
|
||||
appSettings = setPort port
|
||||
. setServerName (cs $ "postgrest/" <> prettyVersion)
|
||||
$ defaultSettings
|
||||
middle = logStdout
|
||||
. (if configSecure conf then redirectInsecure else id)
|
||||
. gzip def . cors corsPolicy
|
||||
. staticPolicy (only [("favicon.ico", "static/favicon.ico")])
|
||||
|
||||
poolSettings <- maybe (fail "Improper session settings") return $
|
||||
H.poolSettings (fromIntegral $ configPool conf) 30
|
||||
pool :: H.Pool P.Postgres
|
||||
<- H.acquirePool pgSettings poolSettings
|
||||
|
||||
runSettings appSettings $ middle $ \req respond -> do
|
||||
body <- strictRequestBody req
|
||||
resOrError <- liftIO $ H.session pool $ H.tx Nothing $
|
||||
authenticated conf (app conf body) req
|
||||
either (respond . errResponse) respond resOrError
|
||||
|
||||
where
|
||||
prettyVersion = intercalate "." $ map show $ versionBranch version
|
71
samples/html.html
Normal file
71
samples/html.html
Normal file
@ -0,0 +1,71 @@
|
||||
<!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>
|
81
samples/java.java
Normal file
81
samples/java.java
Normal file
@ -0,0 +1,81 @@
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
69
samples/js.js
Normal file
69
samples/js.js
Normal file
@ -0,0 +1,69 @@
|
||||
// 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"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
43
samples/latex.tex
Normal file
43
samples/latex.tex
Normal file
@ -0,0 +1,43 @@
|
||||
\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}
|
99
samples/lua.lua
Normal file
99
samples/lua.lua
Normal file
@ -0,0 +1,99 @@
|
||||
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
|
171
samples/objc.m
Normal file
171
samples/objc.m
Normal file
@ -0,0 +1,171 @@
|
||||
#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);
|
||||
}
|
93
samples/ocaml.ml
Normal file
93
samples/ocaml.ml
Normal file
@ -0,0 +1,93 @@
|
||||
open Lexer_flow
|
||||
module Ast = Spider_monkey_ast
|
||||
open Ast
|
||||
module Error = Parse_error
|
||||
module SSet = Set.Make(String)
|
||||
module SMap = Map.Make(String)
|
||||
|
||||
type lex_mode =
|
||||
| NORMAL_LEX
|
||||
| TYPE_LEX
|
||||
| JSX_TAG
|
||||
| JSX_CHILD
|
||||
|
||||
let mode_to_string = function
|
||||
| NORMAL_LEX -> "NORMAL"
|
||||
| TYPE_LEX -> "TYPE"
|
||||
| JSX_TAG -> "JSX TAG"
|
||||
| JSX_CHILD -> "JSX CHILD"
|
||||
|
||||
let lex lex_env = function
|
||||
| NORMAL_LEX -> token lex_env
|
||||
| TYPE_LEX -> type_token lex_env
|
||||
| JSX_TAG -> lex_jsx_tag lex_env
|
||||
| JSX_CHILD -> lex_jsx_child lex_env
|
||||
|
||||
type env = {
|
||||
errors : (Loc.t * Error.t) list ref;
|
||||
comments : Comment.t list ref;
|
||||
labels : SSet.t;
|
||||
lb : Lexing.lexbuf;
|
||||
lookahead : lex_result ref;
|
||||
last : (lex_env * lex_result) option ref;
|
||||
priority : int;
|
||||
strict : bool;
|
||||
in_export : bool;
|
||||
in_loop : bool;
|
||||
in_switch : bool;
|
||||
in_function : bool;
|
||||
no_in : bool;
|
||||
no_call : bool;
|
||||
no_let : bool;
|
||||
allow_yield : bool;
|
||||
(* Use this to indicate that the "()" as in "() => 123" is not allowed in
|
||||
* this expression *)
|
||||
error_callback : (env -> Error.t -> unit) option;
|
||||
lex_mode_stack : lex_mode list ref;
|
||||
lex_env : lex_env ref;
|
||||
}
|
||||
|
||||
(* constructor *)
|
||||
let init_env lb =
|
||||
let lex_env = new_lex_env lb in
|
||||
let lex_env, lookahead = lex lex_env NORMAL_LEX in
|
||||
{
|
||||
errors = ref [];
|
||||
comments = ref [];
|
||||
labels = SSet.empty;
|
||||
lb = lb;
|
||||
lookahead = ref lookahead;
|
||||
last = ref None;
|
||||
priority = 0;
|
||||
strict = false;
|
||||
in_export = false;
|
||||
in_loop = false;
|
||||
in_switch = false;
|
||||
in_function = false;
|
||||
no_in = false;
|
||||
no_call = false;
|
||||
no_let = false;
|
||||
allow_yield = true;
|
||||
error_callback = None;
|
||||
lex_mode_stack = ref [NORMAL_LEX];
|
||||
lex_env = ref lex_env;
|
||||
}
|
||||
|
||||
(* getters: *)
|
||||
let strict env = env.strict
|
||||
let lookahead env = !(env.lookahead)
|
||||
let lb env = env.lb
|
||||
let lex_mode env = List.hd !(env.lex_mode_stack)
|
||||
let lex_env env = !(env.lex_env)
|
||||
let last env = !(env.last)
|
||||
let in_export env = env.in_export
|
||||
let comments env = !(env.comments)
|
||||
let labels env = env.labels
|
||||
let in_loop env = env.in_loop
|
||||
let in_switch env = env.in_switch
|
||||
let in_function env = env.in_function
|
||||
let allow_yield env = env.allow_yield
|
||||
let no_in env = env.no_in
|
||||
let no_call env = env.no_call
|
||||
let no_let env = env.no_let
|
||||
let errors env = !(env.errors)
|
45
samples/perl.pl
Normal file
45
samples/perl.pl
Normal file
@ -0,0 +1,45 @@
|
||||
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;
|
||||
}
|
69
samples/python.py
Normal file
69
samples/python.py
Normal file
@ -0,0 +1,69 @@
|
||||
#!/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)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
121
samples/r.r
Normal file
121
samples/r.r
Normal file
@ -0,0 +1,121 @@
|
||||
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
|
||||
}
|
69
samples/ruby.rb
Normal file
69
samples/ruby.rb
Normal file
@ -0,0 +1,69 @@
|
||||
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'])
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
{
|
||||
"name": "One Half Light Italic",
|
||||
"type": "light",
|
||||
"colors": {
|
||||
"focusBorder": "#0366d6",
|
||||
"foreground": "#24292e",
|
||||
|
@ -1,5 +1,6 @@
|
||||
{
|
||||
"name": "One Light Italic",
|
||||
"type": "light",
|
||||
"colors": {
|
||||
"focusBorder": "#0366d6",
|
||||
"foreground": "#24292e",
|
||||
|
Loading…
Reference in New Issue
Block a user