Documentation ¶
Index ¶
- Variables
- func AllLanguages() []string
- func CloneStringSlice(a []string) []string
- func Concurrent(funcs ...func())
- func ConcurrentPromise(funcs ...func()) chan bool
- func ConcurrentWithAllErrors(funcs ...func() error) (ok bool, errs []error)
- func ConcurrentWithAnyError(funcs ...func() error) error
- func FilterOut(s []string, forbidden []string) []string
- func FilterStrings(s []string, fn func(string) bool) []string
- func Flatten(s string) string
- func LanguageAutoComplete(fragment string) []string
- func LanguageExtraKeywords(lg string) []string
- func Last(array []string) (result string)
- func MainStreamLanguages() []string
- func MapStrings(str []string, f func(string) string) []string
- func Max(a, b int) int
- func Min(a, b int) int
- func MoreLanguages() []string
- func NoCR(s string) string
- func NormLang(lang string) string
- func NormalizeRunes(str string) string
- func PrintNiceLang(lang string) string
- func PrintNiceLangs(langs []string) []string
- func RemoveEmptyStrings(s []string) []string
- func Sha1hash(s string) string
- func Shorten(s string, n int) string
- func SplitForIndexing(s string, normalize bool) []string
- func SplitForSearching(s string, normalize bool) []string
- func String2Int(str string) int
- func StringSliceContains(hay []string, needle string) bool
- func StringSliceContainsCaseInsensitive(hay []string, needle string) bool
- func StringSliceEquals(a []string, b []string) bool
- func Truncate(s string, maxChars int) string
- func TruncateBytes(s string, maxBytes int) string
- type Idiom
- func (idiom *Idiom) AddRelation(other *Idiom)
- func (idiom *Idiom) ExtractIndexableWords() (w []string, wTitle []string, wLead []string)
- func (idiom *Idiom) FindIdiomOrImplLastEditor() string
- func (idiom *Idiom) FindImplInIdiom(implId int) (int, *Impl, bool)
- func (idiom *Idiom) FindRecentlyUpdatedImpl() *Impl
- func (idiom *Idiom) VariablesComma() string
- type IdiomHistory
- type IdiomRenderingDecoration
- type IdiomVoteLog
- type Impl
- type ImplRenderingDecoration
- type ImplVoteLog
- type LanguageSingleSelector
- type MessageForUser
- type PageMeta
- type Toggles
- type UserProfile
Constants ¶
This section is empty.
Variables ¶
var AllLangs []string
var AllNiceLangs []string
var RegexpDigitsOnly = regexp.MustCompile("^\\d+$")
Functions ¶
func AllLanguages ¶
func AllLanguages() []string
func CloneStringSlice ¶
CloneStringSlice makes a defensive copy of
func Concurrent ¶
func Concurrent(funcs ...func())
Concurrent launches provided funcs, and waits for their completion.
func ConcurrentPromise ¶
func ConcurrentPromise(funcs ...func()) chan bool
Concurrent launches provided funcs, and returns a channel to notify completion.
func ConcurrentWithAllErrors ¶
ConcurrentWithAllErrors launches provided funcs, and gathers errors. If no errors, ok is true and the returned slice contains all nil values.
func ConcurrentWithAnyError ¶
ConcurrentWithAnyErrors launches provided funcs, and returns 1 error if at least 1 error occurred, nil otherwise.
func FilterOut ¶
FilterOut creates a new slice from s, removing any element contained in forbidden. Accept nils and empty lists. Never yields nil, but may yield an empty list.
func FilterStrings ¶
FilterStrings creates a new slice from s, removing any element that doesn't match the predicate fn.
From https://blog.golang.org/go-slices-usage-and-internals
Accept nils and empty lists. Never yields nil, but may yield an empty list.
Items that match the predicate are kept (not thrown away, do not confuse!)
func LanguageAutoComplete ¶
func LanguageExtraKeywords ¶
func MainStreamLanguages ¶
func MainStreamLanguages() []string
Return alpha codes for each language (no encoding problems). See PrintNiceLang to display them more fancy.
func MapStrings ¶
MapStrings applies f to each element of str, and returns a new slice of the same size containing all the results.
func MoreLanguages ¶
func MoreLanguages() []string
func NormalizeRunes ¶
NormalizeRunes discard special characters from a string, for indexing and for searching. Some letters with diacritics are replaced by the same letter without diacritics.
func PrintNiceLang ¶
func PrintNiceLangs ¶
func RemoveEmptyStrings ¶
RemoveEmptyStrings creates a new slice from s, removing all empty elements.
func SplitForIndexing ¶
SplitForIndexing cuts sentences or paragrahs into words. Words of 2 letters of less are discarded.
func SplitForSearching ¶
SplitForSearching cuts an input search string into a slice of search terms.
func String2Int ¶
String2Int is a shorthand to convert a string to an int. It doesn't panic and does'nt return any error, but it may return -1. Thus it should be used only to parse positive integer that are extermely likely to be well-formed.
func StringSliceContains ¶
StringSliceContains determines whether this slice contains this string
func StringSliceContainsCaseInsensitive ¶
StringSliceContainsCaseInsensitive determines whether this slice contains this string, regardless the case
func StringSliceEquals ¶
StringSliceEquals determines whether two string slices are the same. Arbitrary regards nil and []string{} as NOT equal.
func TruncateBytes ¶
Types ¶
type Idiom ¶
type Idiom struct { // Id is auto-incremented 1, 2, 3... // TODO name ID instead Id int // Reserved in case one idiom derived from another // TODO name OrigID instead OrigId int // Title is like the "idiom name" Title string // LeadParagraph is the idiom Description : 1 to 3 lines are fine LeadParagraph string // ExtraKeywords for indexation+search ExtraKeywords string // Author is the name of the original creator of this idiom on this website Author string // CreationDate is the date of creation of this idiom on this site CreationDate time.Time // LastEditor is the name of the last person who modified this idiom LastEditor string // EditSummary is the comment explaining why LastEditor made the edit. // It is not displayed except in history views. EditSummary string // LastEditedImplID is the ID of the only impl modified by // last edit. LastEditedImplID should be 0 if last // edit was on the idiom statement, not on an impl. LastEditedImplID int // Please acknowledge sources (idiom statement, not snippet). OriginalAttributionURL string // Picture representing the concept, if necessary // DEPRECATED Picture string // ImageURL to illustrate this idiom. ImageURL string // ImageWidth, ImageHeight hints for web rendering: avoids FOUC ImageWidth, ImageHeight int // ImageAlt is a description of a picture for accessibility purpose ImageAlt string // Autoincremented at each update 1, 2, 3... Version int // Date of last update VersionDate time.Time // List of implementations of this idiom in specific languages Implementations []Impl // (Denormalized) number of contained implementation, for datastore querying ImplCount int // How many votes for the idiom itself (votes up - votes down) Rating int // Index-like array of important words : those from the title // DEPRECATED: use the new Text Search API instead. WordsTitle []string // Index-like array of words from title, description and implementation contents // DEPRECATED: use the new Text Search API instead. Words []string // Did the admin validate this idiom statement ? Checked bool // Extra calculated data like "Has this idiom been upvoted by this user?" // Ignored by the datastore. Deco IdiomRenderingDecoration `datastore:"-" json:"-"` // Related idioms ids "See also..." RelatedIdiomIds []int // NoSQL-style : store directly some data from other objects RelatedIdiomTitles []string // Protected when "only admin can edit" Protected bool // Variables from the lead paragraph, that we'd like every // impl snippet to contain Variables []string // RelatedURLs as extra pieces of documentation for the idiom statement. RelatedURLs []string // RelatedURLLabels are nice text for Related URLs hyperlinks. RelatedURLLabels []string }
Idiom is the main entity of programming-idioms.org . An Idiom contains its Implementations. It is in theory independent from any framework, but has been used only in Google App Engine so far.
func (*Idiom) AddRelation ¶
AddRelation creates a bidirectional link between 2 related Idioms.
func (*Idiom) ExtractIndexableWords ¶
ExtractIndexableWords compute the list of words contained in an Idiom. First return value is the list of all matchable words. Second return value is the list of matchable words from title only.
func (*Idiom) FindIdiomOrImplLastEditor ¶
FindIdiomOrImplLastEditor returns last user who touched something
func (*Idiom) FindImplInIdiom ¶
FindImplInIdiom is a (unoptimized) iteration to retrieve an Impl by its ID, inside an Idiom.
It returns a pointer to the Impl, not a copy.
func (*Idiom) FindRecentlyUpdatedImpl ¶
FindRecentlyUpdatedImpl is a (unoptimized) iteration to retrieve the most recently updated impl, inside an Idiom.
It returns a pointer to the Impl, not a copy.
func (*Idiom) VariablesComma ¶
VariablesComma e.g. ["x", "result"] -> "x,result"
type IdiomHistory ¶
type IdiomHistory struct { // Just embeds Idiom Idiom // If needed, add specific history fields UpdatedImplId int // TODO: how to get rid properly? // Got `datastore: cannot load field "EditorSummary" into a "pig.IdiomHistory": no such struct field` EditorSummary string `deprecated` // IdiomOrImplLastEditor is redundant storage of most recent impl update's editor, // to be directly indexed and displayed in history list. IdiomOrImplLastEditor string }
IdiomHistory stores all the history: old versions of Idioms.
func (*IdiomHistory) AsIdiomPtr ¶
func (ih *IdiomHistory) AsIdiomPtr() *Idiom
func (*IdiomHistory) ComputeIdiomOrImplLastEditor ¶
func (hist *IdiomHistory) ComputeIdiomOrImplLastEditor()
ComputeIdiomOrImplLastEditor computes IdiomOrImplLastEditor
type IdiomRenderingDecoration ¶
IdiomRenderingDecoration is the "current user" vote on this Idiom, if any. This struct does not contain the Idiom ID, so it must be part of a larger struct.
type IdiomVoteLog ¶
type IdiomVoteLog struct { IdiomId int // Typicaly +1 or -1 Value int // IpHash stored only to prevent abusive multiple votes IpHash string Date time.Time }
IdiomVoteLog is a history trace of an Idiom vote, from a specific user. This struct does not contain the nickname of the voter. However it does contain the Idiom ID. Each vote will have a voting booth as ancestor, specific for the nickname.
type Impl ¶
type Impl struct { // Id is Internal. Not displayed on screen (but present in URL). // TODO name ID instead Id int // OrigId is reserved in case one impl derived from another // TODO name OrigID instead OrigId int // Author is the name of the original creator of this implementation on this site. Author string // CreationDate of this implementation on this website CreationDate time.Time // LastEditor is the name of the last person who modified this impl. LastEditor string // LanguageName is the programming language of this impl. // It is used to visualy identify the impl inside the idiom. // But note that an idiom may have several implementations for same language. LanguageName string // CodeBlock contains the snippet. // It should contain only instructions code, not comments. CodeBlock string // OriginalAttributionURL: please acknowledge sources. OriginalAttributionURL string // DemoURL is an optional link to an online demo DemoURL string // DocumentationURL is an optional link to official doc DocumentationURL string // AuthorComment comments about the CodeBlock. // This comment is always displayed on the right of the code. // TODO rename this to CodeBlockComment. AuthorComment string // Version is incremented at each update 1, 2, 3... Version int // VersionDate of last update VersionDate time.Time // Rating is the votes count for this specific impl (votes up - votes down) Rating int // Checked is true if an admin has validated this implementation. Checked bool // ImplRenderingDecoration is some extra calculated data like "Has this implementation been upvoted by this user?" // Ignored by the datastore. Deco ImplRenderingDecoration `datastore:"-" json:"-"` // ImportsBlock contains the import directives, appart from main code section. ImportsBlock string // PictureURL to illustrate this impl. PictureURL string // Protected when "only admin can edit" Protected bool }
Impl is a specific implementation of one Idiom in one programming language. It is in theory independent from any framework, but has been used only in Google App Engine so far.
func (*Impl) ExtractIndexableWords ¶
ExtractIndexableWords compute the list of words contained in an Impl.
type ImplRenderingDecoration ¶
type ImplRenderingDecoration struct { UpVoted bool DownVoted bool // Matching is set to true if current impl matches user text search query. Matching bool // SearchedLang is set to true if current impl lang is the user typed lang. SearchedLang bool }
ImplRenderingDecoration is the "current user" vote on this Impl, if any. This struct does not contain Impl ID nor Idiom ID, so it must be part of a larger struct.
type ImplVoteLog ¶
type ImplVoteLog struct { IdiomId int ImplId int // Typicaly +1 or -1 Value int // IpHash stored only to prevent abusive multiple votes IpHash string Date time.Time }
ImplVoteLog is a history trace of an Impl vote, from a specific user. This structure does not contain the nickname of the voter. However it does contain the Idiom ID and Impl ID. Each vote will have a voting booth as ancestor, specific for the nickname.
type LanguageSingleSelector ¶
type LanguageSingleSelector struct { // Name of the HTML element FieldName string // Value of the widget: standardized name of a programming language Selected string }
LanguageSingleSelector is used to specify the prefilled value of a programming language selection widget.
type MessageForUser ¶
type PageMeta ¶
type PageMeta struct { // PageTitle is the title of this page PageTitle string // CanonicalURL helps deduplicating pages for SEO. // See https://support.google.com/webmasters/answer/139066 CanonicalURL string // PageKeywords for meta tag "keyword" PageKeywords string // Toggles (global or custom) used to tune the output Toggles Toggles // SearchQuery is printed in search field, in case of new similar search SearchQuery string // ExtraCss after programming-idioms.css ExtraCss []string // ExtraJs after programming-idioms.js ExtraJs []string // PreventIndexingRobots for edit pages, etc. PreventIndexingRobots bool }
PageMeta is basic metadata useful for any web page.
type Toggles ¶
Toggles should always be named after the positive feature they represent, and default value should be true.
type UserProfile ¶
type UserProfile struct { Nickname string FavoriteLanguages []string SeeNonFavorite bool // IsAdmin will never be set by user himself IsAdmin bool }
UserProfile is a soft (non-secure) user profile
func EmptyUserProfile ¶
func EmptyUserProfile() UserProfile
func (UserProfile) Empty ¶
func (u UserProfile) Empty() bool
Empty means the visitor doesn't have any meaningful profile data in her cookies.
func (UserProfile) String ¶
func (u UserProfile) String() string