Nourrane
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    #+SETUPFILE: https://fniessen.github.io/org-html-themes/org/theme-readtheorg.setup #+TITLE: Org Mode #+author: Yves-Jean DANIEL #+email: yves-jean.daniel@isima.fr #+STARTUP: inlineimages #+BEGIN_SRC elisp (eval-after-load 'org (add-hook 'org-babel-after-execute-hook 'org-redisplay-inline-images)) #+END_SRC#+BEGIN_SRC elisp (eval-after-load 'org (add-hook 'org-babel-after-execute-hook 'org-redisplay-inline-images)) #+END_SRC [lundi 08:30] Yves Jean DANIEL import random def generePermutationListe(L, p = None): n = len(L) if p == None: p = n out = list(L) for i in range(p): k = random.randint(i,n-1) out[i], out[k] = out[k], out[i] return out[:p] def generePermutationChaine(ch, p = None): return "".join(generePermutationListe(list(ch), p)) (org-babel-do-load-languages 'org-babel-load-languages '((ditaa . t) (C . t) (dot . t) (emacs-lisp . t) (scheme . t) (gnuplot . t) (haskell . t) (latex . t) (js . t) (ledger . t) (matlab . t) (ocaml . t) (octave . t) (plantuml . t) (python . t) (R . t) (ruby . t) (screen . nil) (scheme . t) (shell . t) (sql . t) (sqlite . t))) (setq org-babel-python-command "python3") ** Graphviz Pour débuter : http://magjac.com/graphviz-visual-editor/ #+BEGIN_SRC dot :file "graph1.png" :exports both strict digraph { a [shape="ellipse" style="filled" fillcolor="#1f77b4"] b [shape="polygon" style="filled" fillcolor="#ff7f0e"] a -> b [fillcolor="#a6cee3" color="#1f78b4"] Père [ shape=ellipse style="filled" fillcolor="#FF44cc"] Mère [ shape=octagon] Frère [ style="radial, solid" color="#c22727" fillcolor="#99cb0b" shape=ellipse] Père -> b Frère -> Père n6 n6 -> a Frère -> b [ style=dashed color="#824848" fillcolor="#a361bb"] n6 -> n6 [ style=dashed color="#824848" fillcolor="#a361bb"] a -> n6 [ style="tapered, solid" color="#824848" fillcolor="#a361bb"] n6 -> Mère [ style="dashed"] Mère -> Père Frère -> Pierre n6 -> Frère } #+END_SRC * Ditaa Manuel : http://ditaa.sourceforge.net/#usage #+BEGIN_SRC ditaa :file "ditaa1.png" :exports both /------------------------------\ +-------------------+ | | | {d} cGRE | | | | | | | | Help +--------+ | | Hello world +----->| | cYEL | | | | | +--------+ | | cBLU | +----------+--------+ | | | | \-------------+----------------/ *----+ | ^ | | | | v +-->*--+ | +---+---+ | | | {s} | | v | cPNK +-----+ +-------------+-----------------+ | Me... | | {io} | +---+---+ /--\ | cRED | | | | | Patatoes +<-----+ : /---* *---\ | | | | | + | | | | ++ | +-------------------------------+ +--+ \---------+ #+END_SRC ** C *** Un exemple basique #+BEGIN_SRC C :exports both #include "stdio.h" #include "stdlib.h" #include "string.h" int find(char c, char dico[], int len_dico){ int i = 0; char found = 0; for (i = 0 ; i < len_dico && !found; ++i){ if (dico[i] == c){ found= 1; } } if (found){ return i-1; } else{ return -1; } } void counting(char *s, char dico[], int len_dico, int counts[]){ int pos; while (*s){ pos = find(*s, dico, len_dico); if (pos != -1){ counts[pos]++; } s++; } } void print_counts(char dico[], int len_dico, int counts[]){ int i; for (i = 0 ; i < len_dico; ++i){ if (dico[i] !=' '){ printf("%c %d\n", dico[i], counts[i]); } else { printf("SPC %d\n", counts[i]); } } } int main(int argc, char** argv){ (void) argc; (void) argv; char *my_string = "HELLO MY FRIEND"; char dico[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ "; int len_dico = strlen(dico); int *counts = calloc(len_dico, sizeof *counts); counting(my_string,dico, len_dico, counts); print_counts(dico, len_dico, counts); free(counts); return 0; } #+END_SRC #+RESULTS: | A | 0 | | B | 0 | | C | 0 | | D | 1 | | E | 2 | | F | 1 | | G | 0 | | H | 1 | | I | 1 | | J | 0 | | K | 0 | | L | 2 | | M | 1 | | N | 1 | | O | 1 | | P | 0 | | Q | 0 | | R | 1 | | S | 0 | | T | 0 | | U | 0 | | V | 0 | | W | 0 | | X | 0 | | Y | 1 | | Z | 0 | | SPC | 2 | *** Directives de compilation, ligne de commande de faire appel à des bibliothèques (maths, **sdl**, ...) #+begin_example #+BEGIN_SRC C :flags -Wall -Wextra ...... #+end_src #+end_example On peut également préciser des paramètres d'entrée du programme (ce que l'on mettrait sur la ligne de commande lors de /l'exécution/ après le nom de l'exécutable) #+begin_example #+BEGIN_SRC C :flags -Wall -Wextra :cmdline <input.txt ...... #+end_src #+end_example * Graphiques Créer des graphiques en python est très fréquent car c'est un langage qui dispose de nombreuses bibliothèques très agréables pour manipuler des données (en particulier /pandas/), et pour réaliser des graphiques (en particulier /seaborn/). La méthode (indépendante du langage) est simple, il suffit que le code génère un fichier image, que l'on insère ensuite comme lien là où on désire l'afficher. Afin qu'une nouvelle exécution du code mette à jour l'image affichée, il est utile d'insérer dans le fichier de config d'emacs le code proposé dans la partie [[Configuration]]. #+BEGIN_SRC python :exports code import seaborn as sns import matplotlib.pyplot as plt import math import numpy as np import random def f(x): return math.sin(math.sqrt(7)*x)*x * math.sin(80*x) def courbe(): x = list(np.linspace(0,5,1000)) y = map(f, x) y = list(y) sns.lineplot(x=x, y=y) im = np.zeros((10,10), dtype=np.uint8) for l in range(10): for c in range(10): im[l, c] = random.randint(0,255) plt.clf() plt.imshow(im) plt.savefig('test2.png') plt.clf() courbe() plt.savefig('test1.png') #+END_SRC #+RESULTS: : None On peut alors afficher les images en insérant le fichier comme un lien ~[[./test1.png]]~ [09:34] Yves Jean DANIEL * Entrées utilisateur   S'il n'y a pas de 'réaction', on peut écrire la suite des entrées dans un   fichier, et utiliser ce fichier en entrée de la ligne de commande. #+BEGIN_SRC C :results raw html :flags -Wall -Wextra :cmdline <input_entree_utilisateur.txt  :exports both   #include "stdio.h"   int main(int argc, char ** argv){​​​​     (void) argc;     (void) argv;     int tab[4];     char txt[255];     puts("Entrer 4 entiers");     for (int i = 0 ; i < 4 ; ++i){​​​​       scanf("%d", &tab[i]);     }​​​​     puts("\n--------------------     FAIT     --------------------");     printf("Entrer une chaîne de caractères :");     scanf("%254s", txt);     puts("\n--------------------     FAIT     --------------------");         for(int i = 0 ; i < 4 ; ++i){​​​​       printf("%s\tn° %d\n", txt, tab[i]);     }​​​​   }​​​​  #+end_src #+RESULTS: [09:37] Yves Jean DANIEL * Pour expliquer un code *** Référencer une portion de code Il est parfois intéressant de référencer une portion de code afin d'y faire appel dans le texte. Cela peut se faire en plaçant dans le code une référence sur une ligne de code ~(ref:label)~ (où label est remplacé par une étiquette de son choix). Dans le texte, on pourra alors faire un lien sur la ligne de code par $[$[(label)][Texte à afficher]$]$ #+BEGIN_SRC python -r :exports code  :results output replace :var n=6  :exports both   def fact(n):     if n <= 1:                      (ref:cb)       return 1     else:                           (ref:rec)       return n * fact(n-1)   print("fact(5) =", fact(n) )    print("| hello |") #+END_SRC #+RESULTS: : fact(5) = 2 : | hello | "On pourra noter que le [[(cb)][cas de base]] est ici étendu au cas où l'argument vaut 1, ce qui n'est pas nécessaire, la [[(rec)][partie récursive]] est, elle,  conforme à la définition usuelle de la factorielle" *** Numéroter les lignes L'option ~-r~ permet d’afficher dans le texte le numéro de la ligne. *** Bloc de code sans langage précisé   Permet d'obtenir un paragraphe séparé du reste avec une fonte à chasse   fixe.   #+begin_example   #+BEGIN_SRC python :tangle results value  :exports both     def fact(n):       if n <= 1:                          return 1       else:                               return n * fact(n-1)     print("fact(5) =", fact(5) )    #+END_SRC   #+end_example * Export d'un code pour être utilisé ailleurs ** Export du code Pour effectuer cette forme d'export, on utilise ~C-c C-v t~. Le résultat est un nouveau fichier qui ne contient que ce code source. #+BEGIN_SRC python :tangle fic1.py :results none def hello(): print("hello World") #+END_SRC On peut complét#+RESULTS: : Salut les copains ! #+RESULTS: : Salut les copains ! er le fichier en réalisant des 'tangles' en utilisant le même nom de fichier, mais attention, le 'tangle' ne fait que copier les textes dans le fichier indiqué, il ne vérifie rien ! #+BEGIN_SRC python :tangle fic1.py :results none hello() #+END_SRC Ou écrire dans un autre fichier : #+BEGIN_SRC python :tangle fic2.py :results none print("ici est ailleurs") #+END_SRC ** Bash pour exécuter ce code - On crée un fichier à l'aide de la méthode précédente #+BEGIN_SRC C :tangle hello.c :results none int main(){ puts("Salut les copains !"); return 0; } #+END_SRC - Puis on travaille un peu en bash : #+BEGIN_SRC bash gcc -Wall -Wextra -o hello hello.c ./hello #+END_SRC * Appeler une fonction *** un exemple en python #+name: fct #+BEGIN_SRC python -r :exports both :results value html :return fact(n) :var n=7 def fact(n): if n <= 1: return 1 else: return n * fact(n-1) def succ(n): return n+1 #+END_SRC #+RESULTS: fct #+BEGIN_EXPORT html 5040 #+END_EXPORT Lorsque comme ci-dessus une variable a été définie, il est possible de rappeler le code en modifiant la valeur de la variable. Pour cela on utilise ~#+call: fct(n=5)~, où (ATTENTION !) ~fct~ est le nom du bloc de code (et pas le nom de la fonction), indiqué par le ~#+name: fct~ précédant le code. On peut noter qu'el est possible de modifier les options lors de cet appel si on le désire. #+call: fct(n=5) :exports results :results value latex #+RESULTS: #+BEGIN_EXPORT latex 120 #+END_EXPORT On peut également appeler une autre fonction : #+call: fct(n=5) :return succ(n) #+RESULTS: #+BEGIN_EXPORT html 6 #+END_EXPORT *** un exemple en c #+name: hello #+BEGIN_SRC C -r :results value :var n = 3 int f(int n){ return n==0?1:n*f(n-1); } int main(){ //printf("| "); for(int i = 0 ; i< n ; ++i){ printf(" %d | ", f(i)); } return 0; } #+END_SRC #+RESULTS: hello | 1 | 1 | 2 | 6 | 24 | et avec un appel avec la valeur 7 : #+call: hello(7) #+RESULTS: | 1 | 1 | 2 | 6 | 24 | 120 | 720 | Ce qui est bel et bien bon ! * Communiquer entre des blocs de code ** Utiliser des fichiers Un premier code prodit ses résultats dans un fichier, qui sert d'entrée à un autre code. Cela peut être fait sans utiliser de fonctionnalité d'orgmode (les codes utilisent de façon normale des fichiers), ou en utilisant comme variables d'entrées ou de sorties des fichiers (c'est alors très similaire aux redirections ~<~ et ~>~ du bash). *** Exemple en passant par la ligne de commande Voici un bloc en c qui produit des données : #+BEGIN_SRC C :output both :flags -Wall -Wextra :cmdline >c_to_py.txt #include "stdio.h" int main(int argc, char **argv){ (void) argc; (void) argv; int i; for(i = 0 ; i < 100 ; ++i){ printf("%d\n", i); } printf("%s", "Hello!"); return 0; } #+END_SRC #+RESULTS: Maintenant un bloc en python qui consomme les données : #+BEGIN_SRC python :output both :results output import sys import seaborn as sns import matplotlib.pyplot as plt sys.stdin = open('c_to_py.txt', 'r') L = [] for a in range(10): L.append(int(input(""))) sys.stdin.close() L = list(map(lambda x: x**2, L) ) sns.lineplot(x = range(len(L)), y = L) plt.savefig('test3.png') print(L) sys.stdout = open('py_to_c.txt', 'w') for a in L: print(a) sys.stdout.close() #+END_SRC #+RESULTS: : [0, 1, 4, 9, 16, 25, 36, 49, 64, 81] None [[./test3.png]] [[./py_to_c.txt]] ** Nommer les sorties On peut nommer avec ~#+NAME mon_joli_nom~ un bloc . Ce bloc peut alors être utilisé comme variable d'entrée à un autre bloc. Un bloc en C qui fabrique des arcs : #+BEGIN_SRC C :output both :flags -Wall -Wextra :results output #include "stdio.h" #include "stdlib.h" int main(int argc, char ** argv){ (void) argc; (void) argv; srand(143); int i, k; for(i = 0 ; i < 10 ; ++i){ for (k = 0 ; k < rand()%5+1; ++k){ printf("%d -> %d\n", i, rand()%10); } } return 0; } #+END_SRC #+name: testa #+RESULTS: #+begin_example 0 -> 6 1 -> 9 1 -> 5 1 -> 5 2 -> 8 2 -> 3 2 -> 6 3 -> 7 3 -> 1 3 -> 8 4 -> 6 5 -> 5 5 -> 9 6 -> 4 6 -> 2 6 -> 1 6 -> 8 7 -> 9 7 -> 2 8 -> 1 9 -> 2 9 -> 8 9 -> 5 9 -> 0 #+end_example [[./c_to_gv.txt]] Pour finalement être représenté sous forme de graphe : #+BEGIN_SRC dot :file "graph2.png" :exports both :var monGraph=testa strict digraph { $monGraph } #+END_SRC #+RESULTS: [[file:graph2.png]] int main() { int W,H,N,X0,Y0; scanf("%d%d%d%d%d", &W, &H,&N,&X0,&Y0); int xd=0; int xf=W-1; int yd=0; int yf=H-1; while (N) { char bomb[4]; scanf("%s", bomb); if (bomb[0]=='R' ||bomb[1]=='R')xd=X0+1; if (bomb[0]=='L'|| bomb[1]=='L')xf=X0-1; if (bomb[0]=='U') yf=Y0-1; if (bomb[0]=='D') yd=Y0+1; X0=xd+(xf-xd)/2,Y0=yd+(yf-yd)/2; printf("%d %d\n",X0,Y0);} return 0; }

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully