Initial commit

This commit is contained in:
JoseluCross
2017-09-17 18:28:06 +02:00
commit 92dd9181cf
14 changed files with 2021 additions and 0 deletions

6
README.md Normal file
View File

@@ -0,0 +1,6 @@
# What is CodeGuide?
CodeGuide is a part of CodeShare where we have a basic help when starting to program in a language, and
a set of functions with examples to use directly, fast and helpful
Its a collaborative project, and we will upload a doc guide to push changes in a short time, wait for it :)

67
assets/css/codesee.css Normal file
View File

@@ -0,0 +1,67 @@
/* General CSS */
/* Some rules from: https://fabiomsr.github.io/from-java-to-kotlin/, thanks */
.mitalic {
font-size:14px;
font-style:italic;
margin-bottom: 0px;
}
p.lang {
color: #292626;
font-size:18px;
text-align: left;
margin-bottom: 0px;
}
.alignleft {
text-align: left;
}
div.mdgeneral h2 {
text-align: center;
}
div.mdgeneral p {
text-align: left;
}
div.mdgeneral {
background-color: #fbfbfb;
border-radius: 5px;
padding: 7px;
margin: 3px;
}
/* CSS for two langs side by side */
h2, h3{
text-align: center;
}
p.mitalic {
text-align: center;
}
.pairlang div.showone {
flex: 1;
-ms-flex: 1;
min-width: 550px;
margin: 0 10px;
}
.pairlang {
display: flex;
justify-content: center;
-webkit-justify-content: center;
-ms-box-pack: center;
-ms-box-align: center;
}
.onelangname{
text-align:center;
}

4
assets/html/footer.php Normal file
View File

@@ -0,0 +1,4 @@
</div> <!-- Finish content div -->
<script>hljs.initHighlightingOnLoad();</script>
</body>
</html>

120
assets/html/header.php Normal file
View File

@@ -0,0 +1,120 @@
<?php
$commonAssets = '../assets/'; /* It loads from root path */
?>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="<?php echo $commonAssets ?>css/bootstrap-paper.css">
<link rel="stylesheet" type="text/css" href="assets/css/codesee.css">
<link rel="stylesheet" type="text/css" href="<?php echo $commonAssets ?>css/codeStyles/vs.css">
<script src="<?php echo $commonAssets ?>js/highlight.pack.js"></script>
</head>
<body>
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-2">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">CodeGuide</a>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-2">
<ul class="nav navbar-nav">
<li <?php if ($site == 'index'){ echo 'class="active"';} ?> >
<a href="index.php">Index</a>
</li>
<li <?php if ($site == 'funcs'){ echo 'class="active"';} ?> >
<a href="funcs.php">Functions Helper</a>
</li>
<!--<li <?php if ($site == 'ginfo'){ echo 'class="active"';}?> >
<a href="index.php?page=ginfo">General info of a lang</a>
</li>-->
<li><a href="../">CodeShare, snippets of code</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><a href="proyecto.jkanetwork.com">JKANetwork</a></li>
</ul>
</div>
</div>
</nav>
<!-- Start of content (Container div in Bootstrap), after nav -->
<div class="container">
<div class="panel panel-default">
<div class="panel-heading">Welcome to CodeGuide, fast help to programmers</div>
<div class="panel-body">
<?php
if ($site == 'index'){
?>
<h4>Select lang to show.</h4>
<p>You can see how different works a lang from another, or simple things to program in your lang,
as a fast guide to see when you don't remember something</p>
<form method='get'>
<p>Lang to show:
<input type="radio" name="lang" value="kotlin" <?php if ($lang == 'kotlin'){echo 'checked="checked"';} ?>>Kotlin
<input type="radio" name="lang" value="php" <?php if ($lang == 'php'){echo 'checked="checked"';} ?>>PHP
</p>
<p>What to see:
<input type="radio" name="see" value="basic" <?php if ($see == 'basic'){echo 'checked="checked"';} ?>>Basic things
<input type="radio" name="see" value="ginfo" <?php if ($see == 'ginfo'){echo 'checked="checked"';} ?>>General info
</p>
<button type="submit" class="btn btn-default">Ver</button>
</form>
<?php
}else if ($site == 'funcs'){
?>
<h4>Select lang to show</h4>
<form method='get'>
<p>Lang to show:
<select name="lang" style="min-width:100px;">
<option value="php" <?php if ($lang == 'php'){echo 'selected="selected"';} ?>>PHP</option>
<option value="kotlin" <?php if ($lang == 'kotlin'){echo 'selected="selected"';} ?>>Kotlin</option>
</select>
<button type="submit" class="btn btn-default">Change</button> </p>
</form>
<form method="GET">
<p>Search: <input onkeyup="searchAjax();" type="text" name="search" size="15"/></p>
</form>
<!-- Script for searching -->
<script>
function searchAjax(){
var searchText = document.getElementsByName("search")[0].value.trim();
var xhr = new XMLHttpRequest();
if (searchText.length > 2){
xhr.open('GET', 'searchhelper.php?what=func&lang=<?php print $lang;?>&str='+searchText);
if (document.getElementById("nosearch")){
document.getElementById("nosearch").style.display = 'none'; /* Not display standard */
}
}else{
document.getElementById("searchresult").innerHTML = "<p>Debes escribir más de dos caracteres</p>";
if (document.getElementById("nosearch")){
document.getElementById("nosearch").style.display = 'block'; /* Display all functions */
}
}
xhr.onload = function() {
if (xhr.status === 200) {
document.getElementById("searchresult").innerHTML = xhr.responseText;
}
};
if (searchText.length > 2){
xhr.send();
}
}
</script>
<?php
}
?>
</div>
</div>

74
funcs.php Normal file
View File

@@ -0,0 +1,74 @@
<?php
$site = 'funcs'; /* For menus */
$func = isset($_GET['func']) ? $_GET['func'] : '';
/* Set lang to see */
$lang = isset($_GET['lang']) ? $_GET['lang'] : 'php';
/* Show header */
require_once 'assets/html/header.php';
/* For searches */
echo '<div id="searchresult">';
echo '</div>';
if ($func != ""){
require_once "lib/parsedown.php";
$file = "langs/$lang/functions/$func.json";
if (file_exists($file)){
$fulljson = json_decode(file_get_contents($file), true);
/* Show function */
if (!isset($fulljson['input'])){ $fulljson['input'] = null; }
if (!isset($fulljson['output'])){ $fulljson['output'] = null; }
seefunc($lang,$func,$fulljson['visual'],$fulljson['description'],$fulljson['parameters'],$fulljson['example'],$fulljson['input'],$fulljson['output']);
}else{
echo "<p>No existe la función</p>";
}
} else { /* Function search */
echo '<div id="nosearch">';
echo '<p>Mostrando todas las funciones...</p>';
$funcs = scandir("langs/$lang/functions/");
foreach ($funcs as $file){
$file = explode('.',$file)[0];
echo "<p><a href='?lang=$lang&func=$file'>$file</a></p>";
}
echo '</div>';
}
require_once 'assets/html/footer.php';
function seefunc($lang,$func,$visual,$description,$parameters,$example,$input,$output) {
echo "<h3>$lang - Function $func</h3>";
echo "<pre><code class='$lang'>$visual</code></pre>";
?>
<h4>Description: </h4>
<p><?php print $description;?></p>
<?php
/* Run for all params to show it */
foreach($parameters as $param => $descr)
{
echo "<p><b><u>$param</u></b>: $descr</p>";
}
?>
<h4>Example</h4>
<h5>Code</h5>
<pre><code class="<?php print $lang?>"><?php
foreach($example as $x)
{
echo "$x".PHP_EOL;
}
?>
</code></pre>
<?php
if (isset($input)){
echo '<h5>Input for example: </h5><p>'.$input.'</p>';
}
if (isset($output)){
echo '<h5>Output of example: </h5><p>'.$output.'</p>';
}
}
?>

12
guide.md Normal file
View File

@@ -0,0 +1,12 @@
# Variables
## Declare and set variable
- First line, declare. Second line, set. Third, declare and set.
. variable
## Declare and set constant
- Same
. constant
## Set array and show position 1 of that array
. array

100
index.php Normal file
View File

@@ -0,0 +1,100 @@
<?php
$site = 'index'; /* For menus */
if (isset($_GET['page'])){
$site = $_GET['page'];
}
/* First convert post to get if needed */
$lang = isset($_GET['lang']) ? $_GET['lang'] : 'php';
$see = isset($_GET['see']) ? $_GET['see'] : 'basic';
/* Show header */
require_once 'assets/html/header.php';
switch ($see){
case 'ginfo':
echo "<h3>General info for $lang</h3>";
echo '<div class="pairlang">';
require_once "lib/parsedown.php";
echo '<div class="showone">';
if (file_exists("langs/$lang/general.md")){
$filemd = file("langs/$lang/general.md", FILE_IGNORE_NEW_LINES);
array_shift($filemd);
$filemd = implode(PHP_EOL,$filemd);
echo Parsedown::instance()
->setMarkupEscaped(true) # escapes markup (HTML)
->text($filemd);
}else{
echo '<h4>No hay información disponible</h4>';
}
echo '</div>';
echo '</div>';
break;
case 'basic':
echo "<h3>Basic things of $lang</h3>";
if (!file_exists('guide.md') || !file_exists("langs/$lang/basic.json")){
die("<p>Some files not found</p>");
}
$file = fopen('guide.md', "r");
$start = 0;
$jsonbasic = json_decode(file_get_contents("langs/$lang/basic.json"),true);
while (($line = fgets($file)) !== false) {
//See if line have '# '
if (substr( $line, 0, 2 ) == '# '){
echo '<h3>';
echo substr($line,2).'</h3>';
}
else if (substr( $line, 0, 3 ) == '## '){
$start = 1;
echo '<h4 class="alignleft">';
echo substr($line,3).'</h4>';
}
else if (substr($line,0,2) == '- '){
echo '<p class="mitalic">'. substr($line,2).'</p>';
}
else if ((substr( $line, 0, 2 ) == '. ') && $start == 1){
echo '<div class="pairlang">';
$start = 0;
echo '<div class="showone">';
// See if exists and load it
if (isset($jsonbasic[trim(substr($line,2))])){
echo '<pre><code>';
if (is_array($jsonbasic[trim(substr($line,2))])){
foreach($jsonbasic[trim(substr($line,2))] as $c)
{
echo "$c".PHP_EOL;
}
}else{
print $jsonbasic[trim(substr($line,2))];
}
echo '</code></pre>';
}else {
echo '<pre>This can\'t be do in this lang, or it isn\'t added yet to this guide.</pre>';
}
echo '</div>';
echo '</div>';
}
}
fclose($file); /* Close guide.md */
break;
case 'sql':
if (!file_exists("langs/$lang/database.json")){
break;
}
$jsonbasic = json_decode(file_get_contents("langs/$lang/basic.json"),true);
break;
default:
echo '<p>Default</p>';
break;
}
require_once 'assets/html/footer.php';

16
langs/kotlin/basic.json Normal file
View File

@@ -0,0 +1,16 @@
{
"array": [
"var arr = arrayOf(1, 2, 3)",
"println(arr[0])"
],
"constant": [
"val a: Int",
"// It cannot be do",
"val b = 6"
],
"variable": [
"var a: Int",
"a = 5",
"var b = 6"
]
}

8
langs/php/basic.json Normal file
View File

@@ -0,0 +1,8 @@
{
"array": "$var = array(1,2,3,'texto');",
"variable": [
"// It cannot be do",
"$a = 5;",
"$b = 6;"
]
}

8
langs/php/database.json Normal file
View File

@@ -0,0 +1,8 @@
{
"sqlite": {
"connect": "$db_conn = new SQLite3('path/to/database.sqlite');",
"query": "$query = $db_conn->query(\"Query\");",
"fetch_array": "$array = $query->fetchArray();"
}
}

View File

@@ -0,0 +1,16 @@
{
"visual": "in_array($search,$array[,type])",
"description": "It searches in a Array for a string \n Type is optional and its for searching exact pattern (true) or not (nothing)",
"parameters" : {
"$search": "What you want to find",
"$array": "The array for search",
"$type": "Exact pattern or not"
},
"example": [
"$os = array(\"Windows\",\"Linux\",\"Mac\");",
"if (in_array(\"Win\",$os)){",
" echo \"Encontrado Win en os\";",
"}"
],
"output": "Encontrado Win en os"
}

27
langs/php/general.md Normal file
View File

@@ -0,0 +1,27 @@
- Version 0.1 -
#### General grammar of lang
- All lines finish with a semicolon (;)
- Vars are append with a dollar sign ever -> $x is x variable
- Vars aren't defined before use. Doesn't name Int,String,.... ever
- When echoing or using functions, you can use 'text' or "text", but in first ones you can't embed a var. Example:
'Hello $x' -> Hello $x
"Hello $x" -> Hello World
#### Comments
```
// This is a single line comment
/* This is
a multiline comment */
```
#### Types of vars
Nothing to show here.

1548
lib/parsedown.php Executable file

File diff suppressed because it is too large Load Diff

15
searchhelper.php Normal file
View File

@@ -0,0 +1,15 @@
<?php
$searchstr = $_GET['str'];
$send = "";
$lang = $_GET['lang'];
if ($_GET['what'] == "func"){ //Si es el buscador rápido de newmidi.php (Tanto para nuevas como las del cajón)
$send .= "<p>Mostrando funciones que contengan $searchstr...</p>";
$funcs = scandir("langs/$lang/functions/");
foreach ($funcs as $file){
if (strpos($file, $searchstr) !== false){
$file = explode('.',$file)[0];
$send .= "<p><a href='?lang=$lang&func=$file'>$file</a></p>";
}
}
}
echo $send;