Skip to content

Instantly share code, notes, and snippets.

View marcotrosi's full-sized avatar

Marco Trosi marcotrosi

View GitHub Profile
@marcotrosi
marcotrosi / printTable.lua
Created May 25, 2015 14:39
Lua - printTable - print tables on stdout or write into files
--[[
A simple function to print tables or to write tables into files.
Great for debugging but also for data storage.
When writing into files the 'return' keyword will be added automatically,
so the tables can be loaded with 'dofile()' into a variable.
The basic datatypes table, string, number, boolean and nil are supported.
The tables can be nested and have number and string indices.
This function has no protection when writing files without proper permissions and
when datatypes other then the supported ones are used.
--]]
@marcotrosi
marcotrosi / placeLintSigns.vim
Last active August 29, 2015 14:24
Vim - signs for static code analyzer like splint
hi org guifg=#FD971F guibg=#232526 gui=bold
sign define Warn text=! texthl=org
function! LintSign()
let Messages_l = []
let SignIDCnt = 0
" capture splint output as list
let LintOutput_l=systemlist("splint *.c")
" remove all previously placed signs
sign unplace *
@marcotrosi
marcotrosi / createLintBalloonText.vim
Last active August 29, 2015 14:24
Vim - create balloon message text out of lint messages
function! LintBalloon()
let BalloonText_l = []
" read lint output into a list
let LintOutput_l=readfile("project.lnt")
" iterate through list
for line in LintOutput_l
" find the message lines and capture the pure message (here for standard gcc format)
let Match_l = matchlist(line, '^' . expand('%:.') . ':' . v:beval_lnum .':\d\+: \(.*\)')
if len(Match_l) != 0 " if match
" add all matching lines to list
@marcotrosi
marcotrosi / extBalloonLuaScript.vim
Created July 6, 2015 07:21
Vim/Lua - exporting balloon info as Lua data and running external script to create the balloon text
set balloonexpr=Balloon()
let g:BalloonScript="<scriptname>"
set ballooneval
function! Balloon()
let balloondata = ['return', '{']
call add(balloondata, " ['cwd'] = [[" . getcwd() . "]],")
call add(balloondata, " ['fileabspath'] = [[" . expand('%:p') . "]],")
call add(balloondata, " ['filerelpath'] = [[" . expand('%:.') . "]],")
call add(balloondata, " ['fileabsdir'] = [[" . expand('%:p:h') . "]],")
@marcotrosi
marcotrosi / log-minimal-demo.lua
Created July 8, 2015 08:22
Lua - automatic logging idea
-- load the log module
local log = require("log")
-- some function for demo
function add(a, b)
return a+b
end
-- wrap the main script in a main function
function main()
function! MakeMenu()
let l:myMakeTargets = ["abort", "", "tags", "clean", "build", "test", "doc"]
let l:c = 0
let l:c = confirm("Make Menu","&make\nta&gs\n&clean\n&build\n&test\n&doc")
if l:c != 0
exe "make " . l:myMakeTargets[l:c]
endif
endfunction
nnoremap <leader>mm :call MakeMenu()<CR>
function! LaTeXMenu(modeprecmd)
let l:FontCmds = ["abort", "FontFamily", "FontSize"]
let l:c = 0
let l:c = confirm("LaTeX Menu","Font&Family\nFont&Size")
if l:c == 1
call FontFamily(a:modeprecmd)
endif
if l:c == 2
call FontSize(a:modeprecmd)
endif
#!/bin/bash
mkdir tmp.iconset
sips -z 16 16 $1 --out tmp.iconset/icon_16x16.png
sips -z 32 32 $1 --out tmp.iconset/icon_16x16@2x.png
sips -z 32 32 $1 --out tmp.iconset/icon_32x32.png
sips -z 64 64 $1 --out tmp.iconset/icon_32x32@2x.png
sips -z 128 128 $1 --out tmp.iconset/icon_128x128.png
sips -z 256 256 $1 --out tmp.iconset/icon_128x128@2x.png
sips -z 256 256 $1 --out tmp.iconset/icon_256x256.png
sips -z 512 512 $1 --out tmp.iconset/icon_256x256@2x.png
#!/bin/bash
# save tool paths in variables
CocoaDialog='/Applications/cocoaDialog.app/Contents/MacOS/cocoaDialog'
YoutubeDL='/usr/local/bin/youtube-dl'
# get clipboard content
Clipboard=$(pbpaste)
# run youtube-dl
#!/bin/bash
# extend PATH variable; dirty workaround for the audio extraction feature which requires ffmpeg
PATH=$PATH:/usr/local/bin
# save tool paths in variables
CocoaDialog='/Applications/cocoaDialog.app/Contents/MacOS/cocoaDialog'
YoutubeDL='/usr/local/bin/youtube-dl'
# get clipboard content