[Ruby] the second day of the Ruby algorithm-helps generate the code for VIM to add code headers.

Source: Internet
Author: User
Tags cmath

The script language is too strong.

My goal is to add my default code header function to vim.

 1 /****************************************************************************** 2 *       COPYRIGHT NOTICE 3 *       Copyright (c) 2014 All rights reserved 4 *       ----Stay Hungry Stay Foolish---- 5 * 6 *       @author       : Shen 7 *       @name         : 8 *       @file         : G:\My Source Code\DefaultCode.cpp 9 *       @date         : 2014/06/14 02:4410 *       @algorithm    :11 ******************************************************************************/12 13 //#pragma GCC optimize ("O2")14 //#pragma comment(linker, "/STACK:1024000000,1024000000")15 16 #include <bits/stdc++.h>17 #include <cmath>18 #include <cstdio>19 #include <string>20 #include <cstring>21 #include <iomanip>22 #include <iostream>23 #include <algorithm>24 using namespace std;25 template<class T>inline bool updateMin(T& a, T b){ return a > b ? a = b, 1: 0; }26 template<class T>inline bool updateMax(T& a, T b){ return a < b ? a = b, 1: 0; }27 28 /*//STL29 #include <map>30 #include <vector>31 #include <list>32 #include <stack>33 #include <deque>34 #include <queue>35 */36 37 /*//Computational Geometry38 #include <complex>39 #define x real()40 #define y imag()41 typedef complex<double> point;42 */43 44 typedef long long int64;45 46 void solve()47 {48 49 }50 51 int main()52 {53 54     return 0;55 }
View code

Use the ruby10 line to handle the string processing. It's amazing.

def load( path )    File.foreach(path) do |line|        line["\n"] = ""        str = "let l = l + 1 | call setline(l, \‘#{line}\‘)"        File.open("s.txt", "a") do |f|            f << "#{str}\n"        end    endendload("DefaultCode.cpp")

In the end, manually add the first and the last parts.

1 "F4 add File Header 2 Map <F4>: Call titledet () <CR> 3 function addtitle () 4 Let L = 0 5 Let L = L + 1 | call setline (L, '/************************************** **************************************** ') 6 Let L = L + 1 | call setline (L, '* copyright notice') 7 Let L = L + 1 | call setline (L, '* copyright (c) 2014 All Rights Reserved ') 8 Let L = L + 1 | call setline (L,' * ---- stay hungry Stay Foolish ----') 9 Let L = L + 1 | call setline (L, '*') 10 Let L = L + 1 | call setline (L, '* @ Author: shen ') 11 Let L = L + 1 | call setline (L, '* @ name:') 12 Let L = L + 1 | call setline (L, '* @ file :'. expand ("%: P: H "). "\\". expand ("%: t") 13 Let L = L + 1 | call setline (L, '* @ Date :'. strftime ("% Y/% m/% d % H: % m") 14 Let L = L + 1 | call setline (L, '* @ algorithm :') 15 Let L = L + 1 | call setline (L ,'*************** **************************************** ***********************/') 16 Let L = L + 1 | call setline (L, '') 17 Let L = L + 1 | call setline (L, '// # pragma GCC optimize ("O2")') 18 Let L = L + 1 | call setline (L, '// # pragma comment (linker, "/Stack: 1024000000,1024000000 ") ') 19 Let L = L + 1 | call setline (L,'') 20 Let L = L + 1 | call setline (L, '# include <bits/stdc ++. h> ') 21 Let L = L + 1 | call setline (L, '# Include <cmath>') 22 Let L = L + 1 | call setline (L, '# include <cstdio> ') 23 Let L = L + 1 | call setline (L, '# include <string>') 24 Let L = L + 1 | call setline (L, '# include <cstring>') 25 Let L = L + 1 | call setline (L, '# include <iomanip> ') 26 Let L = L + 1 | call setline (L, '# include <iostream>') 27 Let L = L + 1 | call setline (L, '# include <algorithm>') 28 Let L = L + 1 | call setline (L, 'using n Amespace STD; ') 29 Let L = L + 1 | call setline (L, 'template <class T> inline bool updatemin (T & A, t B) {return A> B? A = B, 1: 0;} ') 30 Let L = L + 1 | call setline (L, 'template <class T> inline bool updatemax (T &, t B) {return a <B? A = B, 1: 0;} ') 31 Let L = L + 1 | call setline (L, '') 32 Let L = L + 1 | call setline (L, '/* // STL') 33 Let L = L + 1 | call setline (L, '# include <map> ') 34 Let L = L + 1 | call setline (L, '# include <vector>') 35 Let L = L + 1 | call setline (L, '# include <list>') 36 Let L = L + 1 | call setline (L, '# include <stack> ') 37 Let L = L + 1 | call setline (L, '# include <deque>') 38 Let L = L + 1 | call setline (L, '# Include <queue>') 39 Let L = L + 1 | call setline (L, '*/') 40 Let L = L + 1 | call setline (L, '') 41 Let L = L + 1 | call setline (L, '/* // computational ry') 42 Let L = L + 1 | call setline (L, '# include <complex>') 43 Let L = L + 1 | call setline (L, '# define x real ()') 44 Let L = L + 1 | call setline (L, '# define y imag ()') 45 Let L = L + 1 | call setline (L, 'typedef complex <double> point; ') 46 le T l = L + 1 | call setline (L, '*/') 47 Let L = L + 1 | call setline (L ,'') 48 Let L = L + 1 | call setline (L, 'typedef long int64; ') 49 Let L = L + 1 | call setline (L ,'') 50 Let L = L + 1 | call setline (L, 'void solve () ') 51 Let L = L + 1 | call setline (L ,'{') 52 Let L = L + 1 | call setline (L, '') 53 Let L = L + 1 | call setline (L ,'}') 54 Let L = L + 1 | call setline (L, '') 55 Let L = L + 1 | Cal L setline (L, 'int main () ') 56 Let L = L + 1 | call setline (L ,'{') 57 Let L = L + 1 | call setline (L, '') 58 Let L = L + 1 | call setline (L, 'Return 0 ;') 59 Let L = L + 1 | call setline (L, '}') 60 endfunction61 62 "update the last modification time and file name 63 function updatetitle () 64 call setline (8, '* @ file :'. expand ("%: P: H "). "\\". expand ("%: t") 65 call setline (9, '* @ Date :'. strftime ("% Y/% m/% d % H: % m") 66 endfunction67 68 "prior to judgment 1 Whether the word copyright notice exists in the 0-line code. 69. If not, it indicates that the author information has not been added and needs to be added. 70. If yes, then you only need to update 71 function titledet () 72 Let n = 273 "add 74 let line = Getline (n) by default) 75 let STR = '^ * copyright notice $' 76 If line = ~ Str77 call updatetitle () 78 return79 endif80 call addtitle () 81 endfunction
View code
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.