#!/bin/sh

build_type='uninitialized'            # release, debug, etc.
build_testing='uninitialized'         # build tests (on/off)
executable_name='uninitialized'       # name of program main executable
main_executable_src='uninitialized'   # name of src file with main exec code
test_driver_name='uninitialized'      # name of test driver executable
compiler_type='default'               # compiler to use (default/gnu/llvm/etc)
compiler_c='none'                     # c compiler (non-default compiler_type)
compiler_cpp='none'                   # cpp compiler (non-default compiler_type)
project_config_file='.project_config' # read build-dir, executable names
build_dir='build'                     # out-of-source cmake build dir
clean='none'                          # clean executables and/or cmake cache
tests='none'                          # make and/or run test driver
quiet_mode='off'                      # silence all output except errors
generate_new_project_config='false'   # gen new .project_config file
generate_new_cmakelists='false'       # gen new CMakeLists.txt file
generate_new_vimrc='false'            # gen new .vimrc file
compile_db='compile_commands.json'    # CMake-produced db used by various tools

print_usage() {
  echo 'USAGE:'
  echo "  $(basename "${0}")  -h"
  echo "  $(basename "${0}")  -c|-C  [-b <dir>]  [-p <file>]  [-e <file>]"
  echo '            [-x <file>]  [-q]'
  echo "  $(basename "${0}")  -d|-r|-w|-m  [-c|-C]  [-g|-l]  [-t|-T]"
  echo '            [-b <dir>]  [-p <file>]  [-e <file>|-E]  [-x <file>]  [-q]'
  echo "  $(basename "${0}")  -P  [-L]  [-V]"
  echo "  $(basename "${0}")  -L  [-P]  [-V]"
  echo "  $(basename "${0}")  -V  [-P]  [-L]"
  echo 'OPTIONS:'
  echo '  -h, --help'
  echo '      print this help message'
  echo '  -d, --build-type-debug'
  echo '      compile and link with debug symbols'
  echo '  -r, --build-type-release'
  echo '      compile and link release'
  echo '  -w, --build-type-release-with-debug'
  echo '      compile and link release with debug symbols'
  echo '  -m, --build-type-release-min-max'
  echo '      compile and link release for min-size, max-speed'
  echo '  -c, --clean-all'
  echo '      remove built program/testing executables and build dir'
  echo '  -C, --clean-executables'
  echo '      remove built program/testing executables'
  echo '  -g, --use-gnu-compiler'
  echo '      use GNU gcc/g++ compiler and linker'
  echo '  -l, --use-llvm-compiler'
  echo '      use LLVM clang/clang++ compiler and linker'
  echo '  -t, --make-and-run-tests'
  echo '      make and run tests'
  echo '  -T, --make-tests'
  echo '      make tests'
  echo '  -b <dir>, --build-dir=<dir>'
  echo '      specify build dir (default is "build")'
  echo '  -p <file>, --project-config-file=<file>'
  echo '      specify project config file (default is ".project_config")'
  echo '  -e <file>, --executable-name=<file>'
  echo '      specify program executable to build (override config file)'
  echo '  -E, --no-build-executable'
  echo '      do not build program executable (override config file)'
  echo '  -x <file>, --test-driver-name=<file>'
  echo '      specify test-driver executable to build (override config file)'
  echo '  -P, --generate-project-config'
  echo '      generate template .project_config file'
  echo '  -L, --generate-cmakelists'
  echo '      generate template CMakeLists.txt file'
  echo '  -V, --generate-vimrc'
  echo '      generate template .vimrc file'
  echo '  -q, --quiet-mode'
  echo '      quiet mode'
  echo 'EXIT CODES:'
  echo '    0  ok'
  echo '    1  usage, arguments, or options error'
  echo '    2  build error'
  echo '    3  test error'
  echo '  255  unknown error'
  exit "${1}"
}

print_error_msg() {
  echo 'ERROR:'
  printf "$(basename "${0}"): %s\\n\\n" "${1}"
  print_usage "${2}"
}

get_cmd_opts_and_args() {
  while getopts ':hdrwmcCgltTb:p:e:Ex:PLVq-:' option; do
    case "${option}" in
      h)  handle_help ;;
      d)  handle_build_type_debug ;;
      r)  handle_build_type_release ;;
      w)  handle_build_type_release_with_debug ;;
      m)  handle_build_type_release_min_max ;;
      c)  handle_clean_all ;;
      C)  handle_clean_execs ;;
      g)  handle_use_gnu_compiler ;;
      l)  handle_use_llvm_compiler ;;
      t)  handle_make_and_run_tests ;;
      T)  handle_make_tests ;;
      b)  handle_build_dir "${OPTARG}" ;;
      p)  handle_project_config_file "${OPTARG}" ;;
      e)  handle_executable_name "${OPTARG}" ;;
      E)  handle_no_build_executable ;;
      x)  handle_test_driver_name "${OPTARG}" ;;
      P)  handle_generate_project_config ;;
      L)  handle_generate_cmakelists ;;
      V)  handle_generate_vimrc ;;
      q)  handle_quiet_mode ;;
      -)  LONG_OPTARG="${OPTARG#*=}"
          case ${OPTARG} in
            help)                   handle_help ;;
            help=*)                 handle_illegal_option_arg "${OPTARG}" ;;
            build-type-debug)       handle_build_type_debug ;;
            build-type-debug=*)     handle_illegal_option_arg "${OPTARG}" ;;
            build-type-release)     handle_build_type_release ;;
            build-type-release=*)   handle_illegal_option_arg "${OPTARG}" ;;
            build-type-release-with-debug)    handle_build_type_release_with_debug ;;
            build-type-release-with-debug=*)  handle_illegal_option_arg "${OPTARG}" ;;
            build-type-release-min-max)       handle_build_type_release_min_max ;;
            build-type-release-min-max=*)     handle_illegal_option_arg "${OPTARG}" ;;
            clean-all)              handle_clean_all ;;
            clean-all=*)            handle_illegal_option_arg "${OPTARG}" ;;
            clean-executables)      handle_clean_execs ;;
            clean-executables=*)    handle_illegal_option_arg "${OPTARG}" ;;
            use-gnu-compiler)       handle_use_gnu_compiler ;;
            use-gnu-compiler=*)     handle_illegal_option_arg "${OPTARG}" ;;
            use-llvm-compiler)      handle_use_llvm_compiler ;;
            use-llvm-compiler=*)    handle_illegal_option_arg "${OPTARG}" ;;
            make-and-run-tests)     handle_make_and_run_tests ;;
            make-and-run-tests=*)   handle_illegal_option_arg "${OPTARG}" ;;
            make-tests)             handle_make_tests ;;
            make-tests=*)           handle_illegal_option_arg "${OPTARG}" ;;
            build-dir=?*)           handle_build_dir "${LONG_OPTARG}" ;;
            build-dir*)             handle_missing_option_arg "${OPTARG}" ;;
            project-config-file=?*) handle_project_config_file "${LONG_OPTARG}" ;;
            project-config-file*)   handle_missing_option_arg "${OPTARG}" ;;
            executable-name=?*)     handle_executable_name "${LONG_OPTARG}" ;;
            executable-name*)       handle_missing_option_arg "${OPTARG}" ;;
            no-build-executable)    handle_no_build_executable ;;
            no-build-executable=*)  handle_illegal_option_arg "${OPTARG}" ;;
            test-driver-name=?*)    handle_test_driver_name "${LONG_OPTARG}" ;;
            test-driver-name*)      handle_missing_option_arg "${OPTARG}" ;;
            generate-project-config)          handle_generate_project_config ;;
            generate-project-config=*)        handle_illegal_option_arg "${OPTARG}" ;;
            generate-cmakelists)    handle_generate_cmakelists ;;
            generate-cmakelists=*)  handle_illegal_option_arg "${OPTARG}" ;;
            generate-vimrc)         handle_generate_vimrc ;;
            generate-vimrc=*)       handle_illegal_option_arg "${OPTARG}" ;;
            quiet-mode)             handle_quiet_mode ;;
            quiet-mode=*)           handle_illegal_option_arg "${OPTARG}" ;;
            '')                     break ;; # non-option arg starting with '-'
            *)                      handle_unknown_option "${OPTARG}" ;;
          esac ;;
      \?) handle_unknown_option "${OPTARG}" ;;
    esac
  done
}

handle_help() {
  print_usage 0
}

handle_build_type_debug() {
  build_type='Debug'
}

handle_build_type_release() {
  build_type='Release'
}

handle_build_type_release_with_debug() {
  build_type='RelWithDebInfo'
}

handle_build_type_release_min_max() {
  build_type='MinSizeRel'
}

handle_make_and_run_tests() {
  tests='make_and_run_tests'
}

handle_make_tests() {
  tests='make_tests'
}

handle_clean_all() {
  clean='execs_and_build_dir'
}

handle_clean_execs() {
  clean='execs'
}

handle_use_gnu_compiler() {
  compiler_type='gnu'
  compiler_c='gcc'
  compiler_cpp='g++'
}

handle_use_llvm_compiler() {
  compiler_type='llvm'
  compiler_c='clang'
  compiler_cpp='clang++'
}

handle_build_dir() {
  build_dir="${1}"
}

handle_project_config_file() {
  project_config_file="${1}"
}

handle_executable_name() {
  if [ "${executable_name}" != 'uninitialized' ]; then
    err_msg="options \"-e\" and \"-E\" are mutually exclusive"
    print_error_msg "${err_msg}" 1
  fi
  executable_name="${1}"
}

handle_no_build_executable() {
  if [ "${executable_name}" != 'uninitialized' ]; then
    err_msg="options \"-e\" and \"-E\" are mutually exclusive"
    print_error_msg "${err_msg}" 1
  fi
  main_executable_src='-'
  executable_name='-'
}

handle_test_driver_name() {
  test_driver_name="${1}"
}

handle_quiet_mode() {
  quiet_mode='on'
}

handle_generate_project_config() {
  generate_new_project_config='true'
}

handle_generate_cmakelists() {
  generate_new_cmakelists='true'
}

handle_generate_vimrc() {
  generate_new_vimrc='true'
}

handle_unknown_option() {
  err_msg="unknown option \"${1}\""
  print_error_msg "${err_msg}" 1
}

handle_illegal_option_arg() {
  err_msg="illegal argument in \"${1}\""
  print_error_msg "${err_msg}" 1
}

handle_missing_option_arg() {
  err_msg="missing argument for option \"${1}\""
  print_error_msg "${err_msg}" 1
}

generate_project_config() {
  if [ -e '.project_config' ]; then
    err_msg=".project_config file already exists"
    print_error_msg "${err_msg}" 1
  fi
  cat <<- 'EOF' > .project_config
# cmake project title
my-project
# cmake min version required
3.0.2
# language type:"C" or "CPP"
CPP
# language standard
17
# defs and system-include standards: space-separated, "-" if empty
-DGNU_SOURCE -D_LARGEFILE64_SOURCE
# warning levels: space-separated, "-" if empty
-Wall -Wno-unused
# top-level src dirs: colon-separated
src:third_party
# src file with main-executable code: "-" if none, i.e. test only
src/main.cpp
# main executable file to build: "-" if none, i.e. test only
my-exec
# testing language type: "C" or "CPP" (N/A if building without -t/-T)
CPP
# testing language standard (N/A if building without -t/-T)
17
# testing top-level src dirs: colon-separated, "-" if none
tests
# test-driver executable to build (N/A if building without -t/-T)
my-test-driver
# EOF: FILE MUST END WITH THIS LAST LINE
EOF
}

generate_cmakelists() {
  if [ -e 'CMakeLists.txt' ]; then
    err_msg="CMakeLists.txt file already exists"
    print_error_msg "${err_msg}" 1
  fi
  cat <<- 'EOF' > CMakeLists.txt
################################################################################
# REQUIRED COMMAND-LINE INPUTS
#   1) -DBUILD_TESTING=[ON/OFF]
#   2) -DCMAKE_BUILD_TYPE=[Debug/Release/RelWithDebInfo/MinSizeRel]
#   3) -Dproject_config_file=[relative/path/to/config_settings_file]
#   4) -Dproject_source_main_exec=[source_file_name]
# OPTIONAL COMMAND-LINE INPUTS
#   1) -Dproject_main_exec_to_build=[executable_name]
#   2) -Dtesting_exec_to_build=[executable_name]
################################################################################

################################################################################
# MACROS / FUNCTIONS
################################################################################

function(include_dir_and_recurse_subdirs)
  foreach(arg IN LISTS ARGN)
    include_directories("${arg}")
    file(GLOB_RECURSE subdir_list LIST_DIRECTORIES true RELATIVE "${PROJECT_SOURCE_DIR}/" CONFIGURE_DEPENDS "${arg}/*")
    foreach(sdir ${subdir_list})
      if(IS_DIRECTORY "${PROJECT_SOURCE_DIR}/${sdir}")
        include_directories("${sdir}")
      endif()
    endforeach()
  endforeach()
endfunction()

function(collect_source_files_recursively out_sources)
  set(collected_sources "")
  foreach(arg IN LISTS ARGN)
    file(GLOB_RECURSE src CONFIGURE_DEPENDS "${arg}/*.c" "${arg}/*.cpp" "${arg}/*.hxx")
    list(APPEND collected_sources ${src})
  endforeach()
  set(${out_sources} ${collected_sources} PARENT_SCOPE)
endfunction()

function(convert_lang_type_field out_lang_type)
  if(${${out_lang_type}} STREQUAL "C")
    set(out_lang_type "C" PARENT_SCOPE)
  elseif(${${out_lang_type}} STREQUAL "CPP")
    set(${out_lang_type} "CXX" PARENT_SCOPE)
  else()
    message(FATAL_ERROR "Reading from project config file: unable to read/convert project_language_type")
  endif()
endfunction()

function(read_config_list_field out_field out_config_list)
  list(REMOVE_AT ${out_config_list} 0)
  list(GET ${out_config_list} 0 line)
  list(FIND ARGN "field_is_list" index)
  if(${index} GREATER -1)
    string(REPLACE ":" ";" line "${line}")
  endif()
  list(FIND ARGN "field_is_optional" index)
  if((${index} GREATER -1) AND ("${line}" STREQUAL "-"))
    set(line "")
  endif()
  list(FIND ARGN "field_is_lang_type" index)
  if(${index} GREATER -1)
    convert_lang_type_field(line)
  endif()
  set(${out_field} "${line}" PARENT_SCOPE)
  list(REMOVE_AT ${out_config_list} 0)
  set(${out_config_list} ${${out_config_list}} PARENT_SCOPE)
endfunction()

function(skip_config_list_field out_config_list)
  list(REMOVE_AT ${out_config_list} 0)
  list(REMOVE_AT ${out_config_list} 0)
  set(${out_config_list} ${${out_config_list}} PARENT_SCOPE)
endfunction()

################################################################################
# READ SETTINGS FROM PROJECT CONFIG FILE
################################################################################

set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${project_config_file}")
file(STRINGS "${project_config_file}" project_config_list)
read_config_list_field(project_cmake_title project_config_list)
read_config_list_field(project_cmake_version_req project_config_list)
read_config_list_field(project_language_type project_config_list "field_is_lang_type")
read_config_list_field(project_language_standard project_config_list)
read_config_list_field(project_include_standards project_config_list "field_is_optional")
read_config_list_field(project_warning_levels project_config_list "field_is_optional")
read_config_list_field(project_source_dirs project_config_list "field_is_list")
skip_config_list_field(project_config_list)
skip_config_list_field(project_config_list)
read_config_list_field(testing_language_type project_config_list "field_is_lang_type")
read_config_list_field(testing_language_standard project_config_list)
read_config_list_field(testing_source_dirs project_config_list "field_is_list")
skip_config_list_field(project_config_list)

################################################################################
# CMAKE VERSION REQUIRED
################################################################################

cmake_minimum_required(VERSION "${project_cmake_version_req}")

################################################################################
# MAIN PROJECT DEF
################################################################################

project("${project_cmake_title}" NONE)

################################################################################
# COMPILER
################################################################################

find_program(USER_C_COMPILER_SPECIFIED NAMES ${CMAKE_C_COMPILER})
find_program(USER_CPP_COMPILER_SPECIFIED NAMES ${CMAKE_CXX_COMPILER})

################################################################################
# CMAKE LANGUAGE SUPPORT CHECK
################################################################################

enable_language("${project_language_type}")

################################################################################
# SOURCE FILE GROUPS
################################################################################

# project sources
set(project_sources "")
collect_source_files_recursively(project_sources ${project_source_dirs})

################################################################################
# EXECUTABLES TO BUILD
################################################################################

if(NOT "${project_source_main_exec}" STREQUAL "-")
  # project main entry point source
  set(project_main_source "${project_source_main_exec}")

  # executable file to produce for main source
  add_executable("${project_main_exec_to_build}" "${project_source_main_exec}")

  # remove main source from project_sources
  list(REMOVE_ITEM project_sources "${CMAKE_CURRENT_SOURCE_DIR}/${project_source_main_exec}")
endif()

################################################################################
# USER LIB (ALL NON-MAIN SOURCES COLLECTED INTO ONE LIB)
################################################################################

add_library(user_lib ${project_sources})

################################################################################
# COMPILATION DATABASE
################################################################################

# generate compile_commands.json in build directory
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

################################################################################
# LINK LIBS --> EXECUTABLES
################################################################################

if(NOT "${project_source_main_exec}" STREQUAL "-")
  target_link_libraries("${project_main_exec_to_build}" PRIVATE user_lib)
endif()

################################################################################
# COMPILER OPTIONS
################################################################################

# warnings: enable most warnings
add_definitions("${project_warning_levels}")

################################################################################
# SOURCE CONFIG
################################################################################

# set project-wide language standards
if(NOT "${project_source_main_exec}" STREQUAL "-")
  set_target_properties("${project_main_exec_to_build}" PROPERTIES ${project_language_type}_STANDARD ${project_language_standard} ${project_language_type}_STANDARD_REQUIRED ON)
endif()
set_target_properties(user_lib PROPERTIES ${project_language_type}_STANDARD ${project_language_standard} ${project_language_type}_STANDARD_REQUIRED ON)

# set project-wide system-include standards
add_definitions("${project_include_standards}")

# set project-wide include dirs
include_directories("${CMAKE_SOURCE_DIR}")
include_directories("${CMAKE_CURRENT_BINARY_DIR}")
include_dir_and_recurse_subdirs(${project_source_dirs})

################################################################################
# TESTING (OPTIONAL ADD-ON TO BUILD)
################################################################################

# note BUILD_TESTING=ON must be passed to cmake (auto-calls enable_testing())
if(BUILD_TESTING)

  # load CTest suite build tests
  include(CTest)

  # cmake language support check
  enable_language("${testing_language_type}")

  # source file lists
  set(testing_sources "")
  collect_source_files_recursively(testing_sources ${testing_source_dirs})

  # test harness executable
  add_executable("${testing_exec_to_build}" ${testing_sources})
  # cmake ctests to run / linked libs
  add_test(NAME "${testing_exec_to_build}" COMMAND "${testing_exec_to_build}")
  # link libs --> executables
  target_link_libraries("${testing_exec_to_build}" PRIVATE user_lib)

  # source config

  # testing language standards
  set_target_properties("${testing_exec_to_build}" PROPERTIES
    ${testing_language_type}_STANDARD "${testing_language_standard}"
    ${testing_language_type}_STANDARD_REQUIRED ON)

  # testing include dirs
  include_dir_and_recurse_subdirs(${testing_source_dirs})

endif()

EOF
}

generate_vimrc() {
  if [ -e '.vimrc' ]; then
    err_msg=".vimrc file already exists"
    print_error_msg "${err_msg}" 1
  fi
  cat <<- 'EOF' > .vimrc
"*******************************************************************************
" NOTE: MUST START VIM IN PROJECT ROOT!
"*******************************************************************************

let b:config_file_name     = '.project_config'
let b:completion_file_name = '.clang_complete'
let b:config_lines = {
  \ 'lang_type'         : 5,
  \ 'lang_std'          : 7,
  \ 'testing_lang_type' : 19,
  \ 'testing_lang_std'  : 21,
  \ 'defs'              : 9,
  \ 'warnings'          : 11,
  \ 'src_dirs'          : 13,
  \ 'testing_src_dirs'  : 23
\ }
let b:cpp_fallback_std = "11"
let b:c_fallback_std   = "99"

function! s:GetConfigCompileDefs(project_config, config_lines)
  return (a:project_config[a:config_lines.defs] == "-")
    \ ? ''
    \ : a:project_config[a:config_lines.defs]
endfunction

function! s:GetConfigCompileWarnings(project_config, config_lines)
  return (a:project_config[a:config_lines.warnings] == "-")
    \ ? ''
    \ : a:project_config[a:config_lines.warnings]
endfunction

function! s:GetConfigCPPCompileStd(project_config, config_lines)
  let l:lang_type         = a:project_config[a:config_lines.lang_type]
  let l:lang_std          = a:project_config[a:config_lines.lang_std]
  let l:testing_lang_type = a:project_config[a:config_lines.testing_lang_type]
  let l:testing_lang_std  = a:project_config[a:config_lines.testing_lang_std]
  let l:std = (l:lang_type == "CPP")
    \ ? l:lang_std
    \ : (l:testing_lang_type == "CPP" ? l:testing_lang_std : b:cpp_fallback_std)
  return '-std=c++' . l:std
endfunction

function! s:GetConfigCCompileStd(project_config, config_lines)
  let l:lang_type         = a:project_config[a:config_lines.lang_type]
  let l:lang_std          = a:project_config[a:config_lines.lang_std]
  let l:testing_lang_type = a:project_config[a:config_lines.testing_lang_type]
  let l:testing_lang_std  = a:project_config[a:config_lines.testing_lang_std]
  let l:std = (l:lang_type == "C")
    \ ? l:lang_std
    \ : (l:testing_lang_type == "C" ? l:testing_lang_std : b:c_fallback_std)
  return '-std=c' . l:std
endfunction

function! s:GetConfigTopLevelSrcDirs(project_config, config_lines)
  let l:src_dirs     = split(a:project_config[a:config_lines.src_dirs], ":", 1)
  let l:testing_dirs = split(a:project_config[a:config_lines.testing_src_dirs], ":", 1)
  if (a:project_config[a:config_lines.testing_src_dirs] == "-")
    return l:src_dirs
  else
    return (l:src_dirs + l:testing_dirs)
  endif
endfunction

function! s:GetRecursedRelativeIncludePaths(project_config, config_lines)
  let l:top_level_src_dirs = s:GetConfigTopLevelSrcDirs(a:project_config, a:config_lines)
  let l:paths = []
  for l:dir in l:top_level_src_dirs
    let l:paths = l:paths + systemlist('find ' . l:dir . ' -type d | sed s/^//')
  endfor
  return l:paths
endfunction

function! s:SetVimIncludePaths(project_config, config_lines)
  let l:include_paths = s:GetRecursedRelativeIncludePaths(a:project_config, a:config_lines)
  let $CPATH = ""
  let $C_INCLUDE_PATH = ""
  let $CPLUS_INCLUDE_PATH = ""
  for l:path in l:include_paths
    let $CPATH .= getcwd() . '/' . l:path . ":"
    let $C_INCLUDE_PATH .= getcwd() . '/' . l:path . ":"
    let $CPLUS_INCLUDE_PATH .= getcwd() . '/' . l:path . ":"
  endfor
endfunction

function! s:SetLinterSettings(project_config, config_lines)
  let l:cpp_std = s:GetConfigCPPCompileStd(a:project_config, a:config_lines)
  let l:defs = s:GetConfigCompileDefs(a:project_config, a:config_lines)
  let l:warnings = s:GetConfigCompileWarnings(a:project_config, a:config_lines)
  let g:ale_cpp_gcc_options          = l:cpp_std . ' ' . l:defs . ' ' . l:warnings
  let g:ale_cpp_clang_options        = l:cpp_std . ' ' . l:defs . ' ' . l:warnings
  let g:ale_cpp_clangcheck_options   = l:cpp_std . ' ' . l:defs . ' ' . l:warnings
  let g:ale_cpp_clang_format_options = l:cpp_std . ' ' . l:defs . ' ' . l:warnings
  let g:ale_cpp_clangtidy_options    = l:cpp_std . ' ' . l:defs . ' ' . l:warnings
  let l:c_std = s:GetConfigCCompileStd(a:project_config, a:config_lines)
  let g:ale_c_gcc_options            = l:c_std . ' ' . l:defs . ' ' . l:warnings
  let g:ale_c_clang_options          = l:c_std . ' ' . l:defs . ' ' . l:warnings
  let g:ale_c_clangcheck_options     = l:c_std . ' ' . l:defs . ' ' . l:warnings
  let g:ale_c_clang_format_options   = l:c_std . ' ' . l:defs . ' ' . l:warnings
  let g:ale_c_clangtidy_options      = l:c_std . ' ' . l:defs . ' ' . l:warnings
endfunction

function! s:WriteSettingsToCompletionFile(completion_file_name, project_config, config_lines)
  let l:lang_type = a:project_config[a:config_lines.lang_type]
  let l:cpp_compile_standard = s:GetConfigCPPCompileStd(a:project_config, a:config_lines)
  let l:c_compile_standard = s:GetConfigCCompileStd(a:project_config, a:config_lines)
  let l:project_compile_std = (l:lang_type == "CPP")
    \ ? l:cpp_compile_standard
    \ : l:c_compile_standard
  call writefile([l:project_compile_std], a:completion_file_name)
  let l:defs = s:GetConfigCompileDefs(a:project_config, a:config_lines)
  call writefile(split(l:defs, " ", 0), a:completion_file_name, "a")
  let l:warnings = s:GetConfigCompileWarnings(a:project_config, a:config_lines)
  call writefile(split(l:warnings, " ", 0), a:completion_file_name, "a")
  let l:include_paths = s:GetRecursedRelativeIncludePaths(a:project_config, a:config_lines)
  for path in l:include_paths
    call writefile(["-I" . path], a:completion_file_name, "a")
  endfor
endfunction

function! s:Main()
  let l:project_config = readfile(b:config_file_name)
  call s:SetLinterSettings(l:project_config, b:config_lines)
  call s:WriteSettingsToCompletionFile(b:completion_file_name, l:project_config, b:config_lines)
  call s:SetVimIncludePaths(l:project_config, b:config_lines)
endfunction

call s:Main()

EOF
}

generate_new_setup_files() {
  setup_file_generated='false'
  if [ "${generate_new_project_config}" = 'true' ]; then
    generate_project_config
    setup_file_generated='true'
  fi
  if [ "${generate_new_cmakelists}" = 'true' ]; then
    generate_cmakelists
    setup_file_generated='true'
  fi
  if [ "${generate_new_vimrc}" = 'true' ]; then
    generate_vimrc
    setup_file_generated='true'
  fi
  if [ "${setup_file_generated}" = 'true' ]; then
    exit 0
  fi
}

load_settings_from_project_config() {
  if [ ! -e "${project_config_file}" ]; then
    err_msg="could not open project config file \"${project_config_file}\""
    print_error_msg "${err_msg}" 1
  fi
  if [ "${executable_name}" = 'uninitialized' ]; then
    executable_name=$(sed -n '18p' "${project_config_file}")
  fi
  if [ "${main_executable_src}" = 'uninitialized' ]; then
    main_executable_src=$(sed -n '16p' "${project_config_file}")
  fi
  if [ "${test_driver_name}" = 'uninitialized' ]; then
    test_driver_name=$(sed -n '26p' "${project_config_file}")
  fi
}

clean_execs() {
  [ -e "${executable_name}" ] && rm -rf "${executable_name}"
  [ -e "${test_driver_name}" ] && rm -rf "${test_driver_name}"
}

clean_cache() {
  [ -d "${build_dir}" ] && rm -rf "${build_dir}"
}

clean_project() {
  if [ "${clean}" = 'execs' ]; then
    clean_execs
  elif [ "${clean}" = 'execs_and_build_dir' ]; then
    clean_execs
    clean_cache
  fi
}

check_build_type() {
  if [ "${build_type}" = 'uninitialized' ] && [ "${clean}" = 'none' ]; then
    print_error_msg "no build type set with -d|-r|-w|-m" 1
  elif [ "${build_type}" = 'uninitialized' ] && [ "${clean}" != 'none' ]; then
    exit 0
  fi
}

create_and_switch_to_build_dir() {
  mkdir -p "${build_dir}"
  cd "${build_dir}" || exit
}

run_cmake_configure() {
  cmake \
    -DCMAKE_BUILD_TYPE="${build_type}" \
    -DBUILD_TESTING="${build_testing}" \
    -Dproject_config_file="${project_config_file}" \
    -Dproject_source_main_exec="${main_executable_src}" \
    "$([ "${main_executable_src}" != '-' ] && printf "%s%s" "-Dproject_main_exec_to_build=" "${executable_name}" || echo '')" \
    "$([ "${build_testing}" = 'ON' ] && printf "%s%s" "-Dtesting_exec_to_build=" "${test_driver_name}" || echo '')" \
    "$([ "${compiler_type}" != 'default' ] && printf "%s%s" "-DCMAKE_C_COMPILER=" "${compiler_c}" || echo '')" \
    "$([ "${compiler_type}" != 'default' ] && printf "%s%s" "-DCMAKE_CXX_COMPILER=" "${compiler_cpp}" || echo '')" \
    ..
  exit_code=${?}
  [ "${exit_code}" != 0 ] && exit 2
}

run_cmake_build() {
  cmake --build .
  exit_code=${?}
  [ "${exit_code}" != 0 ] && exit 2
}

build_project() {
  run_cmake_configure
  run_cmake_build
}

check_main_exec() {
  if [ "${executable_name}" = '-' ] && [ "${main_executable_src}" != '-' ]; then
    print_error_msg "main executable source file specified, but exec name missing" 1
  fi
}

check_tests() {
  if [ "${tests}" = 'none' ]; then
    build_testing='OFF'
  else
    build_testing='ON'
  fi
}

run_unit_tests() {
  "./${test_driver_name}"
  exit_code=${?}
  if [ "${exit_code}" != 0 ]; then
    copy_built_files
    exit 3
  fi
}

run_tests() {
  if [ "${tests}" = 'make_and_run_tests' ]; then
    run_unit_tests
  fi
}

copy_built_files() {
  [ -e "${executable_name}" ] && cp "${executable_name}" ..
  [ -e "${test_driver_name}" ] && cp "${test_driver_name}" ..
  [ -e "${compile_db}" ] && cp "${compile_db}" ..

}

build_and_test() {
  generate_new_setup_files
  load_settings_from_project_config
  clean_project
  check_build_type
  check_main_exec
  check_tests
  create_and_switch_to_build_dir
  build_project
  run_tests
  copy_built_files
}

main() {
  get_cmd_opts_and_args "$@"
  if [ "${quiet_mode}" = 'on' ]; then
    build_and_test "$@" > /dev/null
  else
    build_and_test "$@"
  fi
  exit 0
}

main "$@"


<filename>plugins/vscode.bash
cite about-plugin
about-plugin 'add vscode alias'

alias vscode='/Applications/Visual\ Studio\ Code.app/Contents/Resources/app/bin/code'


<reponame>freeletics/kubernetes-postfix-relay
#!/usr/bin/env bash

set -e

. /common.sh
. /functions.sh

info "Starting Postfix ..."

setup_timezone
rsyslog_log_format
reown_folders

postfix_create_aliases
postfix_set_hostname
postfix_set_relay_tls_level
postfix_setup_relayhost
postfix_setup_networks
postfix_open_submission_port

[[ -n "$INBOUND_DEBUGGING" ]] && postfix_setup_debugging

execute_post_init_scripts
unset_sensible_variables

info "Starting: ${emphasis}rsyslog${reset}, ${emphasis}postfix${reset}$DKIM_ENABLED"

exec supervisord -c /etc/supervisord.conf


<gh_stars>1-10
#!/bin/sh
docker build -t hl7_validator .


#!/bin/bash

# clear-crontabs.sh
# Contributors:
#   <NAME> <<EMAIL>>
# Description:
#   Backs up and clears all crontabs.
# Notes:
#   Ensure that no scored services are relying on crontabs, or make note of
#   those that do to restore them later.
# Tested on:
#   Ubuntu 17.04

DATE=`date '+%Y%m%d_%H%M%S'`
# Backup and remove main system crontab
echo -e "\e[1m\e[43mBacking up main system crontab /etc/crontab to ~/backups/crontab.$DATE/crontab\e[0m"
mkdir -p ~/backups/crontab.$DATE
sudo cp /etc/crontab ~/backups/crontab.$DATE/crontab
sudo rm /etc/crontab
# Backup and remove system crontabs
for cron_type in d hourly daily weekly monthly
do
  echo -e "\e[1m\e[43mBacking up system crontabs /etc/cron.$cron_type to ~/backups/crontab.$DATE/cron.$cron_type\e[0m"
  sudo cp -a /etc/cron.$cron_type ~/backups/crontab.$DATE/cron.$cron_type
  sudo rm -r /etc/cron.$cron_type/*
done
# Backup and remove user crontabs
echo -e "\e[1m\e[43mBacking up user crontabs /var/spool/cron/crontabs to ~/backups/crontab.$DATE/crontabs\e[0m"
sudo cp -a /var/spool/cron/crontabs ~/backups/crontab.$DATE/crontabs
for user in `cut -f1 -d: /etc/passwd`
do
  sudo crontab -u $user -r
done
echo -e "\e[1m\e[42mFinished clearing crontabs\e[0m"


<filename>src/external/jstack/tools/compileDebug.sh
#!/bin/bash
OUTPUT=../release/jstack.js
rm $OUTPUT
cat ../src/JSTACK.js >> $OUTPUT
cat ../src/JSTACK.Comm.js >> $OUTPUT
cat ../src/JSTACK.Utils.js >> $OUTPUT
cat ../src/JSTACK.Keystone.js >> $OUTPUT
cat ../src/JSTACK.Nova.js >> $OUTPUT
cat ../src/JSTACK.Swift.js >> $OUTPUT
cat ../src/JSTACK.Cinder.js >> $OUTPUT
cat ../src/JSTACK.Glance.js >> $OUTPUT
cat ../src/JSTACK.Neutron.js >> $OUTPUT


#!/bin/bash

sudo php -S localhost:8000 server.php


#!/bin/bash

DATA_SETS=(MUTAG PROTEINS IMDB-BINARY IMDB-MULTI PTC_MR NCI1)

if [ -z ${KERNELS+x} ]; then
  KERNELS=(EH HGKSP_seed0 HGKWL_seed0 MLG MP VH WL WLOA)
fi

# Check whether the number of iterations has been set from the outside.
# If not, set it to a reasonable default value.
if [ -z ${N_ITERS+x} ]; then
  N_ITERS=500
fi

MEMORY=64000
TIME=119:59

for DATA_SET in "${DATA_SETS[@]}"; do
  for KERNEL in "${KERNELS[@]}"; do
    bsub -W ${TIME} -R "rusage[mem=${MEMORY}]" "./run_directly.sh ${DATA_SET} ${KERNEL}"
  done
done


<reponame>kpelzel/charliecloud
#!/bin/bash

# Warning: This script installs software and messes with your "docker" binary.
# Don't run it unless you know what you are doing.

# We start in the Charliecloud Git working directory.

set -e
PREFIX=/var/tmp

# Remove sbin directories from $PATH (see issue #43). Assume none are first.
echo "$PATH"
for i in /sbin /usr/sbin /usr/local/sbin; do
    export PATH=${PATH/:$i/}
done
echo "$PATH"

set -x

case $TARBALL in
    export)
        (cd doc-src && make)
        make export
        mv charliecloud-*.tar.gz "$PREFIX"
        cd "$PREFIX"
        tar xf charliecloud-*.tar.gz
        cd charliecloud-*
        ;;
    export-bats)
        (cd doc-src && make)
        make export-bats
        mv charliecloud-*.tar.gz "$PREFIX"
        cd "$PREFIX"
        tar xf charliecloud-*.tar.gz
        cd charliecloud-*
        ;;
    archive)
        # The Travis image already has Bats installed.
        git archive HEAD --prefix=charliecloud/ -o "$PREFIX/charliecloud.tar"
        cd "$PREFIX"
        tar xf charliecloud.tar
        cd charliecloud
        ;;
esac

make
bin/ch-run --version
version=$(cat VERSION.full)

if [[ $INSTALL ]]; then
    sudo make install PREFIX="$PREFIX"
    cd "$PREFIX/libexec/charliecloud-$version"
fi

if [[ $SUDO_RM_FIRST ]]; then
    sudo rm /etc/sudoers.d/travis
fi
sudo -v || true

cd test

make where-bats
make test-build

if [[ $SUDO_RM_AFTER_BUILD ]]; then
    sudo rm /etc/sudoers.d/travis
fi
if [[ $SUDO_AVOID_AFTER_BUILD ]]; then
    export CH_TEST_DONT_SUDO=yes
fi
sudo -v || true
echo "\$CH_TEST_DONT_SUDO=$CH_TEST_DONT_SUDO"

make test-run
make test-test


#!/bin/bash

# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

echo ""
echo ""

set -eux

# build a "bad" example image
BAD_IMAGE_URL=gcr.io/$PROJECT_ID/signer-int-bad-image:$BUILD_ID
docker build --no-cache -t $BAD_IMAGE_URL -f ./Dockerfile.bad .

trap 'delete_image $BAD_IMAGE_URL'  EXIT

# push bad image
docker push $BAD_IMAGE_URL
# get image url with digest format
BAD_IMG_DIGEST_URL=$(docker image inspect $BAD_IMAGE_URL --format '{{index .RepoDigests 0}}')

trap 'delete_occ $BAD_IMG_DIGEST_URL'  EXIT

signing_bad_image_failed=false
./signer -v 10 \
-alsologtostderr \
-image=${BAD_IMG_DIGEST_URL} \
-pgp_private_key=private.key \
-policy=policy.yaml \
-note_name=${NOTE_NAME} || signing_bad_image_failed=true

if [ "$signing_bad_image_failed" = true ] ; then
	echo "Signing failed for bad image as expected."
    exit 0
else
	echo "Error: signing should fail for bad image, but succeeded."
    exit 1
fi

echo ""
echo ""


#!/bin/bash
DEPLOY_URL=154769901104.dkr.ecr.sa-east-1.amazonaws.com
REPO_NAME=turing/ada
API_FUNCTION=turing-ada-api
APP_FUNCTION=turing-ada-app

# update api
zip $API_FUNCTION.zip api.py
aws lambda update-function-code --function-name $API_FUNCTION --zip-file fileb://$API_FUNCTION.zip
rm $API_FUNCTION.zip

# update main app
sudo docker build . -t $REPO_NAME -q
aws ecr get-login-password --region sa-east-1 | sudo docker login --username AWS --password-stdin $DEPLOY_URL
sudo docker tag $REPO_NAME:latest $DEPLOY_URL/$REPO_NAME:latest
sudo docker push $DEPLOY_URL/$REPO_NAME:latest -q
aws lambda update-function-code --function-name $APP_FUNCTION --image-uri $DEPLOY_URL/$REPO_NAME:latest


<reponame>LumaKernel/dotfiles
#!/bin/bash

# -- apt でのインストール
# add-apt-repository ppa:avsm/ppa -y
# add-apt-repository ppa:gophers/go -y
# apt-add-repository ppa:fish-shell/release-3 -y
# apt-add-repository ppa:git-core/ppa -y

sudo apt-get update -y
sudo apt-get upgrade -y
sudo apt-get autoremove -y

sudo apt-get install git zip cargo -y
sudo apt-get install python3 python3-venv python3-pip -y
sudo apt-get install clang -y
sudo apt-get install source-highlight -y
sudo apt-get install exuberant-ctags -y
sudo apt-get install fd-find -y

# ---- ocaml
sudo apt-get install opam -y
# opam init -n >/dev/null --disable-sandboxing

sudo apt-get install python-software-properties -y

sudo apt-get install silversearcher-ag -y
sudo apt-get install ripgrep -y

sudo apt-get install tmux -y
sudo apt-get install fish -y
sudo apt-get install rlwrap -y

# -- install tmux-powerline
bash "$HOME/dotfiles/linux/install-tmux-powerline.sh"

# -- install tpm
bash "$HOME/dotfiles/linux/install-tpm.sh"

# -- install fisher
if [[ ! -e "$HOME/.config/fish/functions/fisher.fish" ]] ; then
  curl https://git.io/fisher --create-dirs -sLo ~/.config/fish/functions/fisher.fish
fi

# ---- fisher plugins
fish "$HOME/dotfiles/wsl/install.fish"

# -- pip でのインストール
bash "$HOME/dotfiles/linux/pip-install.sh"

# -- ocaml
# TODO
# npm install -g ocaml-language-server
# opam install ocamlfind num merlin -y
# opam user-setup install -y
# opam pin add ocaml-lsp-server https://github.com/ocaml/ocaml-lsp.git -y
# opam install ocaml-lsp-server -y
# opam install ocp-indent -y


make
cp bin/release/examples/example-dsm /home/yzhang/expr/clutter/.


#!/bin/bash
cd ../DryPrecompiler
dub run --compiler=ldc2
cd ..


<reponame>lizhe960118/CenterNet<filename>experiments/voc/srfpn/test_dla_srfpn_area_64.sh
#!/bin/bash
python tools/test_file_dir/test_1.py \
   configs/centernet_voc/dla_srfpn_area_64.py \
   /data/lizhe/srfpn/dla_srfpn_area_64_cache/latest.pth \
   --out dla_srfpn_area_64_result.pkl \
   --eval bbox


#!/bin/bash

# pip_packages=“$(pip freeze)”
# if [[ ${pip_packages} == *django-calendarium* ]]; then
#	echo django-calendarium found.
# else
#  	echo django-calendarium not found, installing....
#	pip install django-calendarium
# fi
# if [[ ${pip_packages} == *pytz* ]]; then
#	echo pytz found.
# else
#  	echo pytz not found, installing....
#	pip install pytz
# fi

pip install -qr requirements.txt

echo Nuking database..
cd HealthNet/;
sudo rm -rf db.sqlite3 */migrations/ */migrations\ \(1\)/ &&
echo Nuked.

if type python3 >/dev/null 2>&1; then
	echo Using command python3....
	python3 manage.py makemigrations core appointments messaging sysstats prescriptions transfer testResults calendarium&&
	python3 manage.py migrate &&
	python3 manage.py loaddata db.json
	while getopts “:r” opt; do
  		case $opt in
    		r)
      			echo Running server >&2
			python3 manage.py runserver
      			;;
    		\?)
      			echo "Invalid option: -$OPTARG" >&2
      			;;
  		esac
	done
else
	echo Using command python....
	python manage.py makemigrations core appointments messaging sysstats prescriptions transfer testResults calendarium&&
	python manage.py migrate &&
	python manage.py loaddata db.json
	while getopts “:r” opt; do
  		case $opt in
    		r)
      			echo Running server >&2
			python manage.py runserver
      			;;
    		\?)
      			echo "Invalid option: -$OPTARG" >&2
      			;;
  		esac
	done
fi


<reponame>francisco137/IpIntervals
#!/bin/bash

./ip_intervals.sh --build all -c
./ip_intervals.sh --minikube -c
./ip_intervals.sh --dashboard -c
./ip_intervals.sh --start -c
./ip_intervals.sh --execute -c
./ip_intervals.sh --remove -c
./ip_intervals.sh --quit -c


<gh_stars>1-10
#!/bin/bash

gnuplot << EOF
reset
set terminal postscript enhanced "Helvetica" 20
set output "Raman.ps"
set xrange[0:4000]
set style line 1 lt 1 lc -1 lw 4 # black-solid
#set style line 2 lt 2 lc 1 lw 4 # red-dashed
#set style line 3 lt 3 lc 2 lw 4 # red-dashed
# set title "Off-resonance Raman:\nSolid - AO; Dashed - PAW\n@ PBE level."
#set nokey
set xlabel "Energy, cm^{-1}"
set ylabel "Intensity, a.u."

plot "crystal_raman.dat-broaden.dat" u 1:2 w l ls 1
EOF


<gh_stars>0
# Author:		ggutierrez @ Intelligent Pharma - 2017
# Description:	helper functions for azure's slurm partition and nodes management

# az_addpartition <PartitionName> [<config file=/grid/env/slurm/slurm.conf>]
#	creates a new partition block with the partition description
#	the Nodes property is empty, and this creates an invalid slurm.conf file
#	az_addnode or az_delpartition must be called before reconfiguring slurm
	export conffile=${2:-'/grid/env/slurm/slurm.conf'}
    if [ "$(cat $conffile | grep '^#<partition.*name.*=.*"'$1'".*>')" != "" ]; then
		echo "partition $1 already exists"
		exit
	fi
	cat >> $conffile <<EOF
#<partition name="$1">
PartitionName=$1 Default=NO MaxTime=4320 Priority=50 State=UP Nodes=
#</partition>
EOF


cd docs
rm -rf _book
gitbook build
cd _book
git init
git add -A
git commit -m 'update book'
git push -f <EMAIL>:NdagiStanley/vue-django.git master:gh-pages


<gh_stars>0
#!/bin/bash -e
project_name=img-seg-3d
component_name=trainer
image_name=gcr.io/${project_name}/${component_name}
image_tag=v1
full_image_name=${image_name}:${image_tag}

# for me, cloud build doesn't work cross projects due to authentication issue
# gcloud builds submit --tag ${full_image_name} .

docker build -t "${full_image_name}" .
docker push "$full_image_name"

# # Output the strict image name (which contains the sha256 image digest)
docker inspect --format="{{index .RepoDigests 0}}" "${IMAGE_NAME}"


<filename>entrypoint.sh
#!/bin/bash

address=$1
user=$2
pass=$3
search_dir=$4

if [[ -d $search_dir ]]; then
   for file in "$search_dir"/*
   do
   cypher-shell -a $address -u $user -p $pass -f $file
   echo "$file"
   done
elif [[ -f $search_dir ]]; then
   cypher-shell -a $address -u $user -p $pass -f $search_dir
   echo "$search_dir"
else
   echo not valid
   exit 1
fi


<reponame>sumannewton/parking-lot
#!/usr/bin/env bash

# Setup/Install
./setup.sh

# Start and run tests from file
./parking_lot.sh ../parking_lot/functional_spec/fixtures/file_input.txt


#!/bin/bash
# use:  sbatch -J manifest.csv arrayjob-kickoff.sh
#SBATCH --output=%x_%A_%a.out
#SBATCH --error=%x_%A_%a.err
#SBATCH --array=1-2  # 1-452%20 # kicks off 453 jobs but only 20 can run at a time.

ml R/3.5.1-foss-2016b-fh1
Rscript consensusVariantCalling.R $SLURM_JOB_NAME


<reponame>arturgontijo/Recipes<gh_stars>0
#!/bin/bash
#
# Copyright 2017 Ubiqus   (Author: <NAME>)
#		 Systran  (Author: <NAME>)
# License MIT
#
# This recipe shows how to build an openNMT translation model from English to French
# based on a limited resource (1 Mio segments)
#
# Based on the tuto from the OpenNMT forum

# TODO test is GPU is present or not
CUDA_VISIBLE_DEVICES=0
decode_cpu=false

# Make symlinks to access OpenNMT scripts - change this line if needed
OPENNMT_PATH=../../OpenNMT
[ ! -h tools ] && ln -s $OPENNMT_PATH/tools tools
[ ! -h preprocess.lua ] && ln -s $OPENNMT_PATH/preprocess.lua preprocess.lua
[ ! -h train.lua ] && ln -s $OPENNMT_PATH/train.lua train.lua
[ ! -h translate.lua ] && ln -s $OPENNMT_PATH/translate.lua translate.lua
[ ! -h onmt ] && ln -s $OPENNMT_PATH/onmt onmt

# this is usefull to skip some stages during step by step execution
stage=0

# if you want to run without training and use an existing model in the "exp" folder set notrain to true
notrain=false

# making these variables to make replication easier for other languages
sl=en
tl=fr

# training corpus - baseline-1M/baseline-2M available
corpus=baseline-1M

# At the moment only "stage" option is available anyway
. local/parse_options.sh

# Data download and preparation

if [ $stage -le 0 ]; then
# TODO put this part in a local/download_data.sh script ?
  mkdir -p data
  cd data
  if [ ! -f $corpus-$sl$tl.tgz ]; then
    echo "$0: downloading the baseline corpus from amazon s3"
    wget https://s3.amazonaws.com/opennmt-trainingdata/$corpus-$sl$tl.tgz
    tar xzfv $corpus-$sl$tl.tgz
  fi
  if [ ! -f testsets-$sl$tl.tgz ]; then
    echo "$0: downloading the baseline corpus from amazon s3"
    wget https://s3.amazonaws.com/opennmt-tests/testsets-$sl$tl.tgz
    tar xzfv testsets-$sl$tl.tgz
  fi
  cd ../local
  if [ ! -f mteval-v13a.pl ]; then
    wget https://raw.githubusercontent.com/moses-smt/mosesdecoder/master/scripts/generic/mteval-v13a.pl
  fi
  if [ ! -f input-from-sgm.perl ]; then
    wget https://raw.githubusercontent.com/moses-smt/mosesdecoder/master/scripts/ems/support/input-from-sgm.perl
  fi
  if [ ! -f wrap-xml.perl ]; then
    wget https://raw.githubusercontent.com/moses-smt/mosesdecoder/master/scripts/ems/support/wrap-xml.perl
  fi
  if [ ! -f multi-bleu.perl ]; then
    wget https://raw.githubusercontent.com/moses-smt/mosesdecoder/master/scripts/generic/multi-bleu.perl
  fi
  cd ..
fi

# Tokenize the Corpus
if [ $stage -le 1 ]; then
  echo "$0: tokenizing corpus and test sets"
  for f in data/$corpus-$sl$tl/*.?? ; do th tools/tokenize.lua -case_feature -joiner_annotate < $f > $f.tok ; done
fi

# Preprocess the data - decide here the vocabulary size 50000 default value
if [ $stage -le 2 ]; then
  mkdir -p exp
  echo "$0: preprocessing corpus"
  th preprocess.lua -src_vocab_size 50000 -tgt_vocab_size 50000 \
  -train_src data/$corpus-$sl$tl/*_train.$sl.tok \
  -train_tgt data/$corpus-$sl$tl/*_train.$tl.tok \
  -valid_src data/$corpus-$sl$tl/*_valid.$sl.tok \
  -valid_tgt data/$corpus-$sl$tl/*_valid.$tl.tok -save_data exp/data-$corpus-$sl$tl
fi

# Train the model !!!! even if OS cuda device ID is 0 you need -gpuid=1
# Decide here the number of epochs, learning rate, which epoch to start decay, decay rate
# if you change number of epochs do not forget to change the model name too
if [ $stage -le 3 ]; then
  if [ $notrain = false ]; then
    echo "$0: training starting, will take a while."
    th train.lua -data  exp/data-$corpus-$sl$tl-train.t7 \
    -save_model exp/model-$corpus-$sl$tl \
    -end_epoch 13 -start_decay_at 5 -learning_rate_decay 0.65 -gpuid 1
    cp -f exp/model-$corpus-$sl$tl"_epoch13_"*".t7" exp/model-$corpus-$sl$tl"_final.t7"
  else
    echo "$0: using an existing model"
    if [ ! -f exp/model-$corpus-$sl$tl"_final.t7" ]; then
      echo "$0: mode file does not exist"
      exit 1
    fi
  fi
fi

# Deploy model for CPU usage
if [ $stage -le 4 ]; then
  if [ $decode_cpu = true ]; then
    th tools/release_model.lua -force -model exp/model-$corpus-$sl$tl"_final.t7" -output_model exp/model-$corpus-$sl$tl"_cpu.t7" -gpuid 1
  fi
fi

# Translate using gpu
# you can change this by changing the model name from _final to _cpu and remove -gpuid 1
if [ $stage -le 5 ]; then
  [ $decode_cpu = true ] && dec_opt="" || dec_opt="-gpuid 1"
  th translate.lua -replace_unk -model exp/model-$corpus-$sl$tl"_final.t7" \
  -src data/$corpus-$sl$tl/*_test.$sl.tok -output exp/${corpus}_test.hyp.$tl.tok $dec_opt
fi

# Evaluate the generic test set with multi-bleu
if [ $stage -le 6 ]; then
  th tools/detokenize.lua -case_feature < exp/${corpus}_test.hyp.$tl.tok > exp/${corpus}_test.hyp.$tl.detok
  perl local/multi-bleu.perl data/$corpus-$sl$tl/*_test.$tl \
  < exp/${corpus}_test.hyp.$tl.detok > exp/${corpus}_test_multibleu.txt
fi

###############################
#### Newstest Evaluation
####

if [ $stage -le 7 ]; then

testset=newstest2014-$sl$tl

  perl local/input-from-sgm.perl < data/testsets-$sl$tl/News/$testset-src.$sl.sgm \
  > data/testsets-$sl$tl/News/$testset-src.$sl

  th tools/tokenize.lua -case_feature -joiner_annotate < data/testsets-$sl$tl/News/$testset-src.$sl \
  > data/testsets-$sl$tl/News/$testset-src.$sl.tok

  [ $decode_cpu = true ] && dec_opt="" || dec_opt="-gpuid 1"

  th translate.lua -replace_unk -model exp/model-$corpus-$sl$tl"_final"*.t7 \
  -src data/testsets-$sl$tl/News/$testset-src.$sl.tok \
  -output exp/$testset-tgt.trans.$tl.tok $dec_opt

  th tools/detokenize.lua -case_feature < exp/$testset-tgt.trans.$tl.tok \
  > exp/$testset-tgt.trans.$tl

# Wrap-xml to convert to sgm
  perl local/wrap-xml.perl $tl data/testsets-$sl$tl/News/$testset-src.$sl.sgm tst \
  < exp/$testset-tgt.trans.$tl \
  > exp/$testset-tgt.trans.$tl.sgm

  perl local/mteval-v13a.pl -r data/testsets-$sl$tl/News/$testset-ref.$tl.sgm \
  -s data/testsets-$sl$tl/News/$testset-src.$sl.sgm -t exp/$testset-tgt.trans.$tl.sgm \
  -c > exp/nist-bleu-$testset
fi


<gh_stars>1-10
flex -o../lex.yy.c ../pp.l
g++ -DGCOMPILE=1 -o pp ../pp.cpp ../lex.yy.c


#!/bin/sh
${SIMULATOR}lame3.70/lame large.wav output_large.mp3


#!/bin/bash

# Install the bare minimum to bootstrap and start the first provisioning.
#
# This script should run only once for OS installation.

function main {
  install_yaourt
  install_puppet
  call_first_provisioning
}

function install_yaourt {
sudo bash <<SCRIPT

cat >> /etc/pacman.conf << "YAOURT_REPOSITORY"
[archlinuxfr]
SigLevel = Never
Server = http://repo.archlinux.fr/\$arch
YAOURT_REPOSITORY

pacman -Sy
pacman -S yaourt --noconfirm
SCRIPT
}

function install_puppet {
  yaourt -S puppet --noconfirm
}

function call_first_provisioning {
  exec scripts/provision.sh
}

main


<reponame>jschmid1/docker-pulp
#!/bin/bash -e

PULP_API_BIND_PORT=${PULP_API_BIND_PORT:-24817}

echo "[INFO] Updating database schema"
pulpcore-manager migrate --noinput

if [[ -n $PULP_ADMIN_PASSWORD ]]; then
    echo "[INFO] Setting admin password"
    pulpcore-manager reset-admin-password --password "${<PASSWORD>}"
fi

echo "[INFO] handling any needed checksum migration"
pulpcore-manager handle-artifact-checksums

echo "[INFO] Collecting static files"
pulpcore-manager collectstatic --noinput

echo "[INFO] Starting API server"

declare -a args=()
for arg in "$@"
do
  eval "args[${#args[*]}]=$arg"
done

exec gunicorn pulpcore.app.wsgi:application \
              "${args[@]}" \
              --bind "0.0.0.0:${PULP_API_BIND_PORT}" \
              --access-logfile -


#!/bin/sh
# Arthur
printf "\033]4;0;#3d352a;1;#cd5c5c;2;#86af80;3;#e8ae5b;4;#6495ed;5;#deb887;6;#b0c4de;7;#bbaa99;8;#554444;9;#cc5533;10;#88aa22;11;#ffa75d;12;#87ceeb;13;#996600;14;#b0c4de;15;#ddccbb\007"
printf "\033]10;#ddeedd;#1c1c1c;#e2bbef\007"
printf "\033]17;#4d4d4d\007"
printf "\033]19;#ffffff\007"
printf "\033]5;0;#ffffff\007"


#!/bin/bash

# One way to run this script:
#
# $ bash scripts/start-all.sh bond0
# if bond0 is the name of interface associated with IB network

set -x

max_workers=4
sched_port=13337
worker_start_port=13338
iface=$1
echo "starting scheduler and workers using ${iface} ..."
sleep 2

get_cvd () {

    start_idx=$1
    num_workers=$2
    user_cvd_str=$3
    ordinates=()
    for i in $(echo $user_cvd_str | sed "s/,/ /g")
    do
	ordinates+=($i)
    done

    cvd_str=""
    for j in $(seq 1 1 $num_workers)
    do
	if [ $j == 1 ]; then
	    cvd_str="${ordinates[$start_idx]}"
	else
	    cvd_str="$cvd_str,${ordinates[$start_idx]}"
	fi
	start_idx=$((start_idx + 1))
	start_idx=$((start_idx % num_workers))
    done
}

rm active-dask-procs
source ucx-setup.sh
echo $CUDA_VISIBLE_DEVICES

# start scheduler

get_cvd 0 $max_workers $CUDA_VISIBLE_DEVICES

bash scripts/start-ucx-dask-gpu-scheduler.sh $cvd_str $sched_port $iface &
echo "$!" >> active-dask-procs
sleep 2

# start workers

for i in $(seq 1 1 $max_workers)
do
    idx=$((i - 1))
    get_cvd $idx $max_workers $CUDA_VISIBLE_DEVICES
    echo $cvd_str
    bash scripts/start-ucx-dask-gpu-worker.sh $cvd_str $sched_port $worker_start_port $iface &
    echo "$!" >> active-dask-procs
    sleep 2
    worker_start_port=$((worker_start_port + 1))
done


<reponame>uoregon-libraries/newspaper-curation-app
#!/usr/bin/env bash
wget --recursive --no-host-directories --cut-dirs 6 --reject index.html* --reject *.jp2 \
     --include-directories /data/batches/batch_uuml_thys_ver01/data/sn83045396/print/1912031701/ \
     https://chroniclingamerica.loc.gov/data/batches/batch_uuml_thys_ver01/data/sn83045396/print/1912031701/

mv 1912031701 sources/sftp/sn83045396-1912031701


#!/bin/bash
cd /usr/share/grafana.krator
grafana-server -config /etc/grafana.krator/grafana.ini cfg:default.paths.data=/var/lib/grafana.krator 1>/var/log/grafana.krator.log 2>&1


#!/usr/bin/env bash

docker run \
    -it \
    --link mariadb:mysql \
    --rm \
    -v ${PROJECT_PATH}/db/data/:/db/data/ \
    -v ${PROJECT_PATH}/db/schema/:/db/schema/ \
    mariadb:10.1.23 \
    sh -c 'exec mysql \
    -h"$MYSQL_PORT_3306_TCP_ADDR" \
    -P"$MYSQL_PORT_3306_TCP_PORT" \
    -uroot \
    -p"$MYSQL_ENV_MYSQL_ROOT_PASSWORD" \
    --default-character-set=utf8mb4 \
    "$MYSQL_ENV_MYSQL_DATABASE" \
    -e "source db/schema/mysql.sql; source db/data/mysql.sql; show databases; show tables;"'

# 挂载数据目录，是因为可以使用统一的sql脚本路径


#!/usr/bin/env bash

brew install jenv
brew install mvnvm

export PATH="$HOME/.jenv/bin:$PATH"
eval "$(jenv init -)"

# Configure jenv
jenv enable-plugin export
jenv enable-plugin ant
jenv enable-plugin scala
jenv enable-plugin gradle
jenv enable-plugin groovy
jenv enable-plugin maven

source ./.functions

addJavaToJenv /System/Library/Java/JavaVirtualMachines/
addJavaToJenv /Library/Java/JavaVirtualMachines/

jenv global 172.16.17.32
jenv shell 172.16.17.32


<reponame>hexa-one/ubuntumainline
echo only remove kernel if you have a newer one!
sleep 2
sudo apt remove linux-headers-5.8.17-0508017
sudo apt remove linux-image-unsigned-5.8.17-0508017-generic
sudo apt remove linux-modules-5.8.17-0508017-generic
echo linux 5.8.17 is successfully removed


#!/bin/bash
#
# A script to permanently delete an existing Datalab VM.
#
# author: <EMAIL> (<NAME>)

set -e

. "$(dirname "$0")/common.sh"

assert_datalab_vm_exists

prompt_user_for_confirmation "Datalab VM and its disks will be deleted forever."

echo "Deleting Datalab VM and its disks"
gcloud --quiet compute instances delete "${MLCC_INSTANCE}" \
    --zone="${MLCC_ZONE}" --delete-disks all

echo "Removing Datalab components and tools from the gcloud shell"
sudo gcloud --quiet components remove datalab

echo "Success!"


<reponame>ezhes/honggfuzz
#!/bin/sh
../../honggfuzz -n1 -u -i inputfiles -- targets/badcode1 ___FILE___


<gh_stars>0
#!/bin/sh
if ! hash sqlectron 2>/dev/null; then
    cd /resources
    echo "Installing Sqlectron Term"
    npm install -g sqlectron-term
    echo "Installing Sqlectron GUI"
    wget https://github.com/sqlectron/sqlectron-gui/releases/download/v1.30.0/Sqlectron_1.30.0_amd64.deb -O ./sqlectron.deb
    dpkg -i ./sqlectron.deb
    rm ./sqlectron.deb
fi

# Run
sqlectron


#!/usr/bin/env bash
#  Configuration for build, run and flash scripts on Raspberry Pi

#  Select Raspberry Pi as SWD Programmer
swd_device=scripts/nrf52-pi/swd-pi.ocd


#!/bin/sh

drone_cache="/drone/drone_cache/$1.cache.tar"

if [ "$1" = "ledger-frontend" ];
then
  echo "* $1"
  tar -cf "$drone_cache" /drone/src/frontend/node_modules/ /drone/src/frontend/dist/
else
  if [ "$1" = "ledger-backend" ];
  then
    tar -cf "$drone_cache" /drone/src/.gradle/ /drone/src/backend/build/
  else
    echo "neither ledger-frontend or ledger-backend was passed as a parameter"
  fi
fi


#!/usr/bin/env bash
set -eo pipefail

ROOT=$(pwd)
SOURCE=${1:-"$ROOT"/samples/sourceFile.hcl}

TMP=$(mktemp -d -t converge.apply.XXXXXXXXXX)
function finish {
    rm -rf "$TMP"
}
trap finish EXIT

pushd "$TMP"

"$ROOT"/converge apply --local --rpc-addr=:8002 -p "message=x" "$SOURCE"

if [ ! -f test.txt ]; then
    echo "test.txt doesn't exist"
    exit 1
fi

if [[ "$(cat test.txt)" != "x" ]]; then
    echo "test.txt doesn't have the right content"
    echo "has '$(cat test.txt)', want 'x'"
    exit 1
fi

popd


<filename>build.sh
#!/bin/bash
current_working_directory=`pwd`

root=$1
folder=$2
path=$root/$folder
number_of_files_disk=0
number_of_files_size_added=0
number_of_crc_hashes_added=0
number_of_md5_hashes_added=0
number_of_sha1_hashes_added=0
number_of_files_size_not_added=0
number_of_crc_hashes_not_added=0
number_of_md5_hashes_not_added=0
number_of_sha1_hashes_not_added=0

argument_index=0
is_verbose=false
hashing_algorithms=("md5")
for var in "$@"
do
	if [ $argument_index -ge 2 ] ; then
    	if [ "$var" == "--verbose" ] ; then
			is_verbose=true
		fi
		if [[ $var =~ ^--hashing-algorithm ]] ; then
			hashing_algorithm_raw=`echo $var | cut --field=2 --delimiter="="`
			IFS=',' read -ra hashing_algorithms <<< "$hashing_algorithm_raw"
		fi
    fi

    ((argument_index++))
done

cd $path

for line in $(find ./); do
	if [ -f "${line}" ]; then	# if the file exists and
		if $is_verbose; then echo -n "Record $line "; fi

		((number_of_files_disk++))

		if $is_verbose; then echo -n "getting file size"; fi
		if [ "`redis-cli get $root:$folder:$line:size`" == "" ] ; then	# there is no index of it in redis
			redis-cli set $root:$folder:$line:size "`ls -l --all --size $line | cut --field=6 --delimiter=' '`" > /dev/null

			((number_of_files_size_added++))
			if $is_verbose; then echo -n "✓ "; fi
		else
			((number_of_files_size_not_added++))
			if $is_verbose; then echo -n "✗ "; fi
		fi

		if $is_verbose; then echo -n "generating hash(es) "; fi
		for this_hashing_algorithm in "${hashing_algorithms[@]}"; do :
			if $is_verbose; then echo -n "$this_hashing_algorithm"; fi
			if [ "$this_hashing_algorithm" != "crc" ] && [ "$this_hashing_algorithm" != "md5" ] && [ "$this_hashing_algorithm" != "sha1" ] ; then
				if $is_verbose; then echo -n "⚠ "; fi
			else
				if [ "`redis-cli get $root:$folder:$line:$this_hashing_algorithm`" == "" ] ; then	# there is no index of it in redis
					if [ "$this_hashing_algorithm" = "crc" ]; then
						bash_command_prefix="ck";
					else
						bash_command_prefix=$this_hashing_algorithm
					fi
					redis-cli set $root:$folder:$line:$this_hashing_algorithm "`$bash_command_prefix""sum $line | cut --field=1 --delimiter=' '`" > /dev/null

					if [ "$this_hashing_algorithm" == "ck" ]; then ((number_of_crc_hashes_added++)); fi
					if [ "$this_hashing_algorithm" == "md5" ]; then ((number_of_md5_hashes_added++)); fi
					if [ "$this_hashing_algorithm" == "sha1" ]; then ((number_of_sha1_hashes_added++)); fi

					if $is_verbose ; then echo -n "✓ "; fi
				else
					if [ "$this_hashing_algorithm" = "ck" ]; then ((number_of_crc_hashes_not_added++)); fi
					if [ "$this_hashing_algorithm" = "md5" ]; then ((number_of_md5_hashes_not_added++)); fi
					if [ "$this_hashing_algorithm" = "sha1" ]; then ((number_of_sha1_hashes_not_added++)); fi

					if $is_verbose ; then echo -n "✗ "; fi
				fi
			fi
		done
		if $is_verbose ; then
			echo "done"
		fi
	fi
done

cd $current_working_directory

number_of_file_size_datastore=`redis-cli keys "$root:$folder:*:size" | wc -l`
number_of_crc_hashes_datastore=`redis-cli keys "$root:$folder:*:crc" | wc -l`
number_of_md5_hashes_datastore=`redis-cli keys "$root:$folder:*:md5" | wc -l`
number_of_sha1_hashes_datastore=`redis-cli keys "$root:$folder:*:sha1" | wc -l`

echo ""
echo "build:$root/$folder"
echo "            Number of files on disk: $number_of_files_disk"
echo " Number of files sizes in datastore: $number_of_file_size_datastore"
for this_hashing_algorithm in "${hashing_algorithms[@]}"; do :
	if [ "$this_hashing_algorithm" = "crc" ]; then
		echo "         Number of crc hashes added: $number_of_crc_hashes_added"
		echo "     Number of crc hashes not added: $number_of_crc_hashes_not_added"
	fi
	if [ "$this_hashing_algorithm" = "md5" ]; then
		echo "         Number of md5 hashes added: $number_of_md5_hashes_added"
		echo "     Number of md5 hashes not added: $number_of_md5_hashes_not_added"
	fi
	if [ "$this_hashing_algorithm" = "sha1" ]; then
		echo "        Number of sha1 hashes added: $number_of_sha1_hashes_added"
		echo "    Number of sha1 hashes not added: $number_of_sha1_hashes_not_added"
	fi
done
echo "  Number of crc hashes in datastore: $number_of_crc_hashes_datastore"
echo "  Number of md5 hashes in datastore: $number_of_md5_hashes_datastore"
echo " Number of sha1 hashes in datastore: $number_of_sha1_hashes_datastore"


set -e
./build-html-docker.sh
./build-reveal-docker.sh
./build-pdf-docker.sh


#!/usr/bin/env bash
set -e

if [[ "$1" == "-nc" ]]; then
  NOCOLOR=''
  BOLDBLUE=''
  shift
else
  NOCOLOR='\033[0m'
  BOLDBLUE='\033[1;34m'
fi

cd "$(dirname "$0")"
echo -e "\n${BOLDBLUE}Setting up K8ssandra cluster...${NOCOLOR}"

if [[ "$#" -gt 1 ]]; then
  echo "Usage: $0 [k8ssandra-namespace=k8ssandra]"
  exit 1
elif [[ "$#" -eq 1 ]]; then
  NAME=$1
else
  NAME=k8ssandra
fi

set -x
helm upgrade ${NAME}-k8ssandra ../charts/k8ssandra  --set cassandra.cassandraLibDirVolume.storageClass=${STORAGE_CLASS:-standard} --set k8ssandra.namespace=${NAME} -n ${NAME} --create-namespace -f sample-values.yaml


<filename>scripts/test-webui.sh<gh_stars>1-10
#!/bin/sh -eu

[ -d "$DPPM_WEBUI_DIR" ] || git clone $DPPM_WEBUI_GIT $DPPM_WEBUI_DIR
cd $DPPM_WEBUI_DIR

yarn install
yarn dev


<filename>sharelatex.sh
#!/bin/bash
binary=1
# 1 to install, 0 to uninstall
if [ -n "$1" ]; then
	if [ $1 -eq "1" ]; then
		binary=1
	else
		binary=0
	fi
fi
if [ $binary -eq 1 ]; then
	sudo echo "安装ShareLatex..."
	touch sharelatex.desktop
	echo "[Desktop Entry]" >>sharelatex.desktop
	echo "Version=1.0" >>sharelatex.desktop
	echo "Terminal=false" >>sharelatex.desktop
	echo "Type=Application" >>sharelatex.desktop
	echo "Name=ShareLatex" >>sharelatex.desktop
	echo "Exec=xdg-open http://202.114.194.35/login/" >>sharelatex.desktop
	echo "Icon=${HOME}/shell/icon/sharelatex.jpg" >>sharelatex.desktop
	sudo chmod +x sharelatex.desktop
	sudo mv sharelatex.desktop ${HOME}/桌面
	sudo chown ${USER}: -R ${HOME}/桌面/sharelatex.desktop
else
	sudo echo "卸载ShareLatex..."
	sudo rm -rf ${HOME}/桌面/sharelatex.desktop
fi


#!/usr/bin/env bash
set -e
source 'approvals.bash'
cd ./fixtures/empty-dir

describe "op --add with arguments"
  rm -f op.conf
  approve "op --add say echo say --say -s"
  approve "op --add shout echo shout"
  approve "op shout"
  rm -f op.conf

describe "op --add without arguments"
  set +e # allow non zero exit code
  rm -f op.conf
  approve "op --add"
  set -e

describe "op --add with quoted arguments"
  rm -f op.conf
  approve "op --add say echo \"hello world\" --color"
  rm -f op.conf


#!/usr/bin/env bash

###############################################################################
# Siri
###############################################################################

# Siri Enabled?
defaults write com.apple.assistant.support "Assistant Enabled" -bool false

# Language
# defaults write com.apple.assistant.backedup "Session Language" -string "en-US"

# Voice Feedback
# 2 : On
# 3 : Off
# defaults write com.apple.assistant.backedup "Use device speaker for TTS" -int 3

# Keybord shortcut
# 0 : Off
# 2 : Hold Command Space
# 3 : Hold Option Space
# 4 : Press Fn (Function) Space
# 7 : Customize
# defaults write com.apple.Siri HotkeyTag -int 2
# defaults write com.apple.Siri CustomizedKeyboardShortcut

# Show Siri in menu bar
defaults write com.apple.Siri StatusMenuVisible -bool false


<filename>bin/run_c2dw_transform_test.sh
# @Author: <NAME>
# @Date:   2018-03-01 23:11:35
# @Last Modified by:   <NAME>
# @Last Modified time: 2018-03-06 13:17:57
sl=1
export sem_limit=$sl
for i in `seq 1 $2`;
do
  nice -20 python -q -X faulthandler ./etl/clarity2dw/planner.py 2>&1 | tee /mnt/c2dw-test/hcgh-1m-t-s$sl-$1-$i.log
done

sl=2
export sem_limit=$sl
for i in `seq 1 $2`;
do
  nice -20 python -q -X faulthandler ./etl/clarity2dw/planner.py 2>&1 | tee /mnt/c2dw-test/hcgh-1m-t-s$sl-$1-$i.log
done

sl=4
export sem_limit=$sl
for i in `seq 1 $2`;
do
  nice -20 python -q -X faulthandler ./etl/clarity2dw/planner.py 2>&1 | tee /mnt/c2dw-test/hcgh-1m-t-s$sl-$1-$i.log
done

sl=8
export sem_limit=$sl
for i in `seq 1 $2`;
do
  nice -20 python -q -X faulthandler ./etl/clarity2dw/planner.py 2>&1 | tee /mnt/c2dw-test/hcgh-1m-t-s$sl-$1-$i.log
done

sl=16
export sem_limit=$sl
for i in `seq 1 $2`;
do
  nice -20 python -q -X faulthandler ./etl/clarity2dw/planner.py 2>&1 | tee /mnt/c2dw-test/hcgh-1m-t-s$sl-$1-$i.log
done

sl=32
export sem_limit=$sl
for i in `seq 1 $2`;
do
  nice -20 python -q -X faulthandler ./etl/clarity2dw/planner.py 2>&1 | tee /mnt/c2dw-test/hcgh-1m-t-s$sl-$1-$i.log
done

sl=64
export sem_limit=$sl
for i in `seq 1 $2`;
do
  nice -20 python -q -X faulthandler ./etl/clarity2dw/planner.py 2>&1 | tee /mnt/c2dw-test/hcgh-1m-t-s$sl-$1-$i.log
done


#!/bin/bash
# This script packages up the importer as it exists in the current git repo,
# creates a bunch of GCE VMs, and runs the importer there on all cities, using
# static sharding.
#
# This process is only runnable by Dustin, due to current GCE/S3 permissions.
#
# Run from the repo's root dir: cloud/start_batch_import.sh

set -e
set -x

EXPERIMENT_TAG=$1
if [ "$EXPERIMENT_TAG" == "" ]; then
	echo Missing args;
	exit 1;
fi

if [ "$2" != "gcs_sync_done" ]; then
	echo First go sync dev/data/input from S3 to GCS. https://console.cloud.google.com/transfer/cloud/jobs
	exit 1;
fi

NUM_WORKERS=10
ZONE=us-east1-b
# See other options: https://cloud.google.com/compute/docs/machine-types
# Particularly... e2-standard-2, n2-standard-2, c2-standard-4
SMALL_MACHINE_TYPE=e2-standard-2
LARGE_MACHINE_TYPE=c2-standard-4
# All of data/ is currently around 30GB
DISK_SIZE=40GB
# Compressing and checksumming gigantic files needs more IOPS
# TODO But wait, e2-standard-2 doesn't support local PD?!
DISK_TYPE=pd-ssd
# Haha, using a project from college, my last traffic sim...
PROJECT=aorta-routes

function build_payload {
	# It's a faster workflow to copy the local binaries into the VMs, rather than
	# build them there.
	cargo build --release --bin updater
	# This is needed to regenerate popdat.bin for Seattle. It requires the
	# VMs to have a matching GDAL version. Since the VM runs the same
	# version of Ubuntu as I do locally, this works out fine.
	cargo build --release --bin cli --features importer/scenarios

	# Build our payload for the VMs
	# This mkdir deliberately fails if the directory is already there; it probably
	# means the last run broke somehow
	mkdir worker_payload
	mkdir -p worker_payload/target/release
	cp target/release/cli worker_payload/target/release/cli
	cp target/release/updater worker_payload/target/release/
	mkdir worker_payload/data
	cp data/MANIFEST.json worker_payload/data
	mkdir worker_payload/importer
	cp -Rv importer/config worker_payload/importer
	cp cloud/worker_script.sh worker_payload/
	# Copy in AWS credentials! Obviously don't go making worker_payload/ public or
	# letting anybody into the VMs.
	#
	# Alternatively, I could just scp the files from the VMs back to my local
	# computer. But more than likely, GCE's upstream speed to S3 (even
	# cross-region) is better than Comcast. :)
	cp -Rv ~/.aws worker_payload/
	zip -r worker_payload worker_payload
}

function create_vms {
	# Ideally we'd use the bulk API, but someone's not on top of those
	# gcloud integration tests...
	# https://issuetracker.google.com/issues/188462253
	for ((i = 0; i < $NUM_WORKERS; i++)); do
		# The first shard always handles Seattle, which needs more than
		# 8GB of memory. Just give it really hefty hardware.
		if [ $i == 0 ]; then
			machine_type=$LARGE_MACHINE_TYPE;
		else
			machine_type=$SMALL_MACHINE_TYPE;
		fi

		gcloud compute \
			--project=$PROJECT \
			instances create "worker-$i" \
			--zone=$ZONE \
			--machine-type=$machine_type \
			--boot-disk-size=$DISK_SIZE \
			--boot-disk-type=$DISK_TYPE \
			--image-family=ubuntu-2004-lts \
			--image-project=ubuntu-os-cloud \
			--scopes=compute-rw,storage-ro
	done

	# There's a funny history behind the whole "how do I wait for my VM to be
	# SSHable?" question...
	sleep 30s
}

function start_workers {
	for ((i = 0; i < $NUM_WORKERS; i++)); do
		gcloud compute scp \
			--project=$PROJECT \
			--zone=$ZONE \
			worker_payload.zip \
			worker-$i:~/worker_payload.zip
		gcloud compute ssh \
			--project=$PROJECT \
			--zone=$ZONE \
			worker-$i \
			--command="sudo apt-get -qq install -y unzip; unzip -q worker_payload.zip; ./worker_payload/worker_script.sh $EXPERIMENT_TAG $i $NUM_WORKERS 1> logs 2>&1 &"
	done
}

build_payload
create_vms
start_workers

# To follow along with a worker:
# > gcloud compute ssh worker-5 --command='tail -f logs'
#
# To see which workers are still running (or have failed):
# > gcloud compute instances list


<reponame>dhh1128/sdk<gh_stars>1-10
#!/bin/sh

set -e
source ./shared.functions.sh

START_DIR=$PWD
WORK_DIR=$START_DIR/../../../../../.macosbuild
mkdir -p $WORK_DIR
WORK_DIR=$(abspath "$WORK_DIR")
SHA_HASH_DIR=$START_DIR/../..
SHA_HASH_DIR=$(abspath "$SHA_HASH_DIR")

source ./mac.02.libindy.env.sh

if [ "$#" -gt 0 ]; then
    CLEAN_BUILD="cleanbuild"
    if [ ! -z "$3" ]; then
        CLEAN_BUILD=$3
    fi

    if [ -d $WORK_DIR/vcx-indy-sdk ]; then
        #rm -rf $WORK_DIR/vcx-indy-sdk
        cd $WORK_DIR/vcx-indy-sdk
    else
        git clone https://github.com/hyperledger/indy-sdk.git $WORK_DIR/vcx-indy-sdk
        cd $WORK_DIR/vcx-indy-sdk
    fi

    if [ "$CLEAN_BUILD" = "cleanbuild" ]; then
        git checkout .
        git checkout master
        git clean -f
        git clean -fd
        git pull
        git checkout `cat $SHA_HASH_DIR/libindy.commit.sha1.hash.txt`
        #cd $WORK_DIR/vcx-indy-sdk
        #git checkout tags/v1.3.0
    else
        git checkout -- libindy/Cargo.toml
        git checkout -- libnullpay/Cargo.toml
    fi

    git log -1 > $WORK_DIR/hyperledger.indy-sdk.git.commit.log

    DEBUG_SYMBOLS="debuginfo"
    if [ ! -z "$1" ]; then
        DEBUG_SYMBOLS=$1
    fi

    IOS_TARGETS="aarch64-apple-ios,armv7-apple-ios,armv7s-apple-ios,i386-apple-ios,x86_64-apple-ios"
    if [ ! -z "$2" ]; then
        IOS_TARGETS=$2
    fi

    #########################################################################################################################
    # Now build libindy
    #########################################################################################################################
    cd $WORK_DIR/vcx-indy-sdk/libindy

    #if [ "$DEBUG_SYMBOLS" = "debuginfo" ]; then
        cat $START_DIR/cargo.toml.add.debug.txt >> Cargo.toml
    #else
    #    cat $START_DIR/cargo.toml.reduce.size.txt >> Cargo.toml
    #fi
    if [ "$DEBUG_SYMBOLS" = "nodebug" ]; then
        sed -i .bak 's/debug = true/debug = false/' Cargo.toml
    fi

    if [ "$CLEAN_BUILD" = "cleanbuild" ]; then
        cargo clean
        # cargo update
    fi

    # To build for macos
    #cargo build
    # To build for iOS
    #echo "cargo lipo --release --verbose --targets=${IOS_TARGETS}"
    # cargo lipo --release --verbose --targets="${IOS_TARGETS}"
    cargo lipo --release --targets="${IOS_TARGETS}"
    #cargo lipo
    mkdir -p ${BUILD_CACHE}/libindy/${LIBINDY_VERSION}
    cp $WORK_DIR/vcx-indy-sdk/libindy/target/universal/release/libindy.a ${BUILD_CACHE}/libindy/${LIBINDY_VERSION}/libindy.a
    for hfile in $(find ${WORK_DIR}/vcx-indy-sdk/libindy -name "*.h")
    do
        cp ${hfile} ${BUILD_CACHE}/libindy/${LIBINDY_VERSION}
    done
else

    if [ -e ${BUILD_CACHE}/libindy/${LIBINDY_VERSION}/libindy.a ]; then
        echo "libindy build for ios already exist"
    else
        mkdir -p ${BUILD_CACHE}/libindy/${LIBINDY_VERSION}
        cd ${BUILD_CACHE}/libindy/${LIBINDY_VERSION}
        curl -o ${LIBINDY_VERSION}-${LIBINDY_FILE} $LIBINDY_IOS_BUILD_URL
        tar -xvzf ${LIBINDY_VERSION}-${LIBINDY_FILE}
        # Deletes extra folders that we don't need
        rm -rf __MACOSX
        rm ${LIBINDY_VERSION}-${LIBINDY_FILE}
    fi

    #########################################################################################################################
    # Now setup libsovtoken
    #########################################################################################################################

    if [ -e ${BUILD_CACHE}/libsovtoken-ios/${LIBSOVTOKEN_VERSION}/libsovtoken/universal/libsovtoken.a ]; then
        echo "libsovtoken build for ios already exist"
    else
        mkdir -p ${BUILD_CACHE}/libsovtoken-ios/${LIBSOVTOKEN_VERSION}
        cd ${BUILD_CACHE}/libsovtoken-ios/${LIBSOVTOKEN_VERSION}
        curl --insecure -o ${LIBSOVTOKEN_VERSION}-${LIBSOVTOKEN_FILE} ${LIBSOVTOKEN_IOS_BUILD_URL}
        unzip ${LIBSOVTOKEN_VERSION}-${LIBSOVTOKEN_FILE}
        # Deletes extra folders that we don't need
        rm -rf __MACOSX
        rm ${LIBSOVTOKEN_VERSION}-${LIBSOVTOKEN_FILE}
    fi

    #########################################################################################################################
    # Now setup libnullpay
    #########################################################################################################################

    if [ -e ${BUILD_CACHE}/libnullpay/${LIBNULLPAY_VERSION}/libnullpay.a ]; then
        echo "libnullpay build for ios already exist"
    else
        mkdir -p ${BUILD_CACHE}/libnullpay/${LIBNULLPAY_VERSION}
        cd ${BUILD_CACHE}/libnullpay/${LIBNULLPAY_VERSION}
        curl -o ${LIBNULLPAY_VERSION}-${LIBNULLPAY_FILE} $LIBNULLPAY_IOS_BUILD_URL
        tar -xvzf ${LIBNULLPAY_VERSION}-${LIBNULLPAY_FILE}

        # Deletes extra folders that we don't need
        rm -rf __MACOSX
        rm ${LIBNULLPAY_VERSION}-${LIBNULLPAY_FILE}
    fi
fi


#!/bin/sh

CNAME="cn=localhost,ou=Camel,o=Apache"

SERVER_KEY=server-keystore.jks
CLIENT_KEY=client-keystore.jks
CLIENT_TRUST=client-truststore.jks

keytool -genkey -alias server -keyalg RSA -keystore $SERVER_KEY -keypass secret -storepass secret -validity 7300 -storetype JKS -dname $CNAME
keytool -genkey -alias client -keyalg RSA -keystore $CLIENT_KEY -keypass secret -storepass secret -validity 7300 -storetype JKS -dname $CNAME
keytool -export -alias server -keystore $SERVER_KEY -file server -storepass secret
keytool -import -alias server -keystore $CLIENT_TRUST -file server -storetype JKS -storepass secret --no-prompt

rm server


#!/bin/bash
# Copyright 2021 The BladeDISC Authors. All rights reserved.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -ex

SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"

source ${SCRIPT_DIR}/parse_args.sh "$@"

ENTRY=scripts/python/tao_build.py
VENV_PATH=/opt/venv_disc
BLADE_DISC_DIR=tao/python/blade_disc_tf

# cleanup build cache
(rm -rf build \
  && rm -rf tao/build \
  && cd tf_community && bazel clean --expunge)

python ${ENTRY} ${VENV_PATH} -s configure --bridge-gcc default --compiler-gcc default ${CPU_ONLY}
python ${ENTRY} ${VENV_PATH} -s build_tao_bridge ${CPU_ONLY}
python ${ENTRY} ${VENV_PATH} -s build_tao_compiler ${CPU_ONLY}
python ${ENTRY} ${VENV_PATH} -s build_mlir_ral ${CPU_ONLY}
python ${ENTRY} ${VENV_PATH} -s test_tao_bridge_cpp ${CPU_ONLY}
python ${ENTRY} ${VENV_PATH} -s test_tao_bridge_py ${CPU_ONLY}
python ${ENTRY} ${VENV_PATH} -s test_tao_compiler ${CPU_ONLY}

# copy libtao_ops.so and tao_compiler_main to blade-disc-tf
cp tao/build/libtao_ops.so ${BLADE_DISC_DIR}
cp tf_community/bazel-bin/tensorflow/compiler/decoupling/tao_compiler_main ${BLADE_DISC_DIR}

(cd tao && \
  ${VENV_PATH}/bin/pytest --pyargs python
  ${VENV_PATH}/bin/python setup.py bdist_wheel)

# copy Python wheel package to build folder
mkdir -p build && \
cp tao/dist/blade_disc*.whl ./build
cp tf_community/bazel-bin/tensorflow/compiler/mlir/disc/tools/disc-replay/disc-replay-main ./build/

# test example models
source ${SCRIPT_DIR}/test_cpu_examples.sh


<reponame>physar/webots
#!/bin/bash

# install the latest Qt 5 which comes with msys64

QT_PACKAGE=mingw-w64-x86_64-qt5
QT_WEBKIT_PACKAGE=mingw-w64-x86_64-qtwebkit

REQUESTED_QT_VERSION=5.12.2

PACMAN_AVAILABLE_QT_VERSION=(`pacman -Syi $QT_PACKAGE | grep Version`)
IFS='-' read -a QT_AVAILABLE_VERSION_SPLIT <<< "${PACMAN_AVAILABLE_QT_VERSION[2]}"
AVAILABLE_QT_VERSION=${QT_AVAILABLE_VERSION_SPLIT[0]}

PACMAN_INSTALLED_QT_VERSION=(`pacman -Qi $QT_PACKAGE | grep Version`)
IFS='-' read -a QT_INSTALLED_VERSION_SPLIT <<< "${PACMAN_AVAILABLE_QT_VERSION[2]}"
INSTALLED_QT_VERSION=${QT_INSTALLED_VERSION_SPLIT[0]}

echo Qt5 version requested: $REQUESTED_QT_VERSION
echo Qt5 version installed: ${PACMAN_INSTALLED_QT_VERSION[2]}
echo Qt5 version available: ${PACMAN_AVAILABLE_QT_VERSION[2]}

if [[ $REQUESTED_QT_VERSION != $INSTALLED_QT_VERSION ]] && [[ $REQUESTED_QT_VERSION != $AVAILABLE_QT_VERSION ]]
then
  echo Requested version not available
  exit
fi

if [[ $PACMAN_AVAILABLE_QT_VERSION != $PACMAN_INSTALLED_QT_VERSION ]]
then
  echo Installing Qt5 version ${PACMAN_AVAILABLE_QT_VERSION[2]}
  pacman -Sy --noconfirm $QT_PACKAGE
  pacman -Sy --noconfirm $QT_WEBKIT_PACKAGE
fi

script_name=$0
script_full_path=$(dirname "$0")
cd $script_full_path/../..

rm -rf include/qt

for MODULE in QtCore QtConcurrent QtGui QtNetwork QtOpenGL QtPrintSupport QtWebKit QtWebKitWidgets QtWebSockets QtWidgets QtXml
do
  echo installing $MODULE...
  mkdir -p include/qt/$MODULE/$MODULE
  cp /mingw64/include/$MODULE/* include/qt/$MODULE/$MODULE/ 2>&1 | grep -v 'omitting directory'
done

echo installing QtPlatformHeaders...
mkdir -p include/qt/QtPlatformHeaders/QtPlatformHeaders
cp /mingw64/include/QtPlatformHeaders/* include/qt/QtPlatformHeaders/QtPlatformHeaders/

echo done.


user_name=`echo $USER | sed 's/ /_/g'`
dir_name=./results_${user_name}
if [ ! -d $dir_name ]
then
    mkdir $dir_name
fi

dir_data=./data

imu_file=${dir_data}/Calibration_Data.txt

echo $imu_file

calibration --input $imu_file --help


<filename>test/run.sh
#!/bin/bash

get_abs_filename() {
  # $1 : relative filename
  echo "$(cd "$(dirname "$1")" && pwd)/$(basename "$1")"
}

DETAIL_PLACER_FLAG="NTU4"
LEF="a2a_wb_dma_top/contest.lef"
DEF="a2a_wb_dma_top/wb_dma_top_soce.def"
LIB="a2a_wb_dma_top/contest.lib"
SDC="a2a_wb_dma_top/wb_dma_top.sdc"
VERILOG="a2a_wb_dma_top/wb_dma_top_soce.v"
OUT="a2a_wb_dma_top_out"
DETAIL_PLACE_LOC=$(get_abs_filename "../ntuplace/ntuplace4h")

./replace -bmflag etc \
  -lef $LEF -def $DEF -verilog $VERILOG -lib $LIB -sdc $SDC \
  -output $OUT \
  -dpflag $DETAIL_PLACER_FLAG -dploc $DETAIL_PLACE_LOC \
  -skipIP -bin 64 -plot -timing -capPerMicron 0.23e-15 -resPerMicron 23


# Sane default for Home Sweet Home root
if [ ! -n "$HOME_SWEET_HOME" ]; then
    export HOME_SWEET_HOME=~/.home-sweet-home
fi

# Set up aliases
alias home="git --work-tree=$HOME --git-dir=${HOME_SWEET_HOME}/.git"


#!/bin/sh

sudo mkdir -p /etc/rpi-webcam-stream
sudo cp ffserver.conf /etc/rpi-webcam-stream

sudo cp rpi-webcam-capture.service /etc/systemd/system/rpi-webcam-capture.service
sudo cp rpi-webcam-stream.service /etc/systemd/system/rpi-webcam-stream.service

sudo systemctl enable rpi-webcam-stream.service
sudo systemctl restart rpi-webcam-stream.service


<reponame>acdh-oeaw/digitarium-static
echo "build index"
ant -f ./static-search/build.xml -DssConfigFile=${PWD}/ss_config.xml
rm ./html/static-search/staticSearch_report.html


#!/bin/bash

# Build a ddev-dbserver image for variety of mariadb/mysql
# and per architecture, optionally push
# By default loads to local docker

set -eu -o pipefail

OS=$(uname -s)
if [ ${OS} = "Darwin" ]; then
  if ! command -v brew >/dev/null; then
    echo "On macOS, homebrew is required to get gnu-getopt" && exit 1
  fi
  if ! brew info gnu-getopt >/dev/null; then
    echo "On macOS, brew install gnu-getopt"
    exit 1
  fi
  PATH="$(brew --prefix gnu-getopt)/bin:$PATH"
fi

! getopt --test >/dev/null
if [[ ${PIPESTATUS[0]} -ne 4 ]]; then
  echo 'getopt --test` failed in this environment.'
  exit 1
fi

OPTS=-h,-v:,-d:
LONGOPTS=archs:,db-type:,db-major-version:,db-pinned-version:,docker-args:,tag:,push,help

! PARSED=$(getopt --options=$OPTS --longoptions=$LONGOPTS --name "$0" -- "$@")
if [[ ${PIPESTATUS[0]} -ne 0 ]]; then
  # e.g. return value is 1
  #  then getopt has complained about wrong arguments to stdout
  printf "\n\nFailed parsing options:\n"
  getopt --longoptions=$LONGOPTS --name "$0" -- "$@"
  exit 3
fi

eval set -- "$PARSED"

ARCHS=linux/$(../get_arch.sh)
MYARCH=${ARCHS}
PUSH=""
NO_LOAD=""
DB_TYPE=mariadb
DB_MAJOR_VERSION=10.3
IMAGE_TAG=$(git describe --tags --always --dirty)
DOCKER_ARGS=""

while true; do
  case "$1" in
  --db-type | -d)
    DB_TYPE=$2
    shift 2
    ;;
  --db-major-version | -v)
    DB_MAJOR_VERSION=$2
    shift 2
    ;;
  --db-pinned-version)
    DB_PINNED_VERSION=$2
    shift 2
    ;;
  --archs)
    ARCHS=$2
    shift 2
    ;;
  --push)
    PUSH=true
    shift 1
    ;;
  --no-load)
    NO_LOAD=true
    shift 1
    ;;
  --docker-args)
    DOCKER_ARGS=$2
    shift 2
    ;;
  --tag)
    IMAGE_TAG=$2
    shift 2
    ;;
  -h | --help)
    echo "Usage: $0 --db-type [mariadb|mysql] --db-major-version <major> --tag <image_tag> --archs <comma-delimted_architectures> --push --no-load"
    printf "Examples: $0 ./build_image.sh --db-type mysql --db-major-version 8.0 --tag junker99 --archs linux/amd64 --push
  $0 --db-type mariadb --db-major-version 10.3 --tag junker99 --archs linux/amd64,linux/arm64"
    exit 0
    ;;
  --)
    break
    ;;
  esac
done

set -o nounset

if [ -z ${DB_PINNED_VERSION:-} ]; then
  DB_PINNED_VERSION=${DB_MAJOR_VERSION}
fi

BASE_IMAGE=${DB_TYPE}

# For mysql, we have to use our own base images at drud/mysql
set -x

if [ ${DB_TYPE} = "mysql" ] && [[ "$ARCHS" == *"linux/arm64"* ]]; then
  BASE_IMAGE=drud/mysql
fi
printf "\n\n========== Building drud/ddev-dbserver-${DB_TYPE}-${DB_MAJOR_VERSION}:${IMAGE_TAG} from ${BASE_IMAGE} for ${ARCHS} with pinned version ${DB_PINNED_VERSION} ==========\n"

if [ ! -z ${PUSH:-} ]; then
  echo "building/pushing drud/ddev-dbserver-${DB_TYPE}-${DB_MAJOR_VERSION}:${IMAGE_TAG}"
  set -x
  docker buildx build --push --platform ${ARCHS} ${DOCKER_ARGS} --build-arg="BASE_IMAGE=${BASE_IMAGE}" --build-arg="DB_PINNED_VERSION=${DB_PINNED_VERSION}" --build-arg="DB_VERSION=${DB_MAJOR_VERSION}" -t "drud/ddev-dbserver-${DB_TYPE}-${DB_MAJOR_VERSION}:${IMAGE_TAG}" .
  set +x
fi

# By default, load/import into local docker
set -x
if [ -z "${PUSH:-}" ]; then
    echo "Loading to local docker drud/ddev-dbserver-${DB_TYPE}-${DB_MAJOR_VERSION}:${IMAGE_TAG}"
    docker buildx build --load ${DOCKER_ARGS} --build-arg="DB_TYPE=${DB_TYPE}" --build-arg="DB_VERSION=${DB_MAJOR_VERSION}" --build-arg="BASE_IMAGE=${BASE_IMAGE}" --build-arg="DB_PINNED_VERSION=${DB_PINNED_VERSION}" -t "drud/ddev-dbserver-${DB_TYPE}-${DB_MAJOR_VERSION}:${IMAGE_TAG}" .
fi


<reponame>AndroidX/androidx
set -e
SCRIPT_PATH="$(cd $(dirname $0) && pwd)"

# Exclude lint tasks, as those are covered by the
# androidx-studio-integration-lint.sh script
$SCRIPT_PATH/impl/build-studio-and-androidx.sh \
  -x lint \
  -x lintDebug \
  -x lintReport \
  -x verifyDependencyVersions \
  listTaskOutputs \
  bOS


#!/bin/bash
#PBS -l walltime=0:30:00,select=1:ncpus=1:ngpus=1:mem=4gb
#PBS -N faces
#PBS -A st-schieb-1-gpu
#PBS -J 1-10

################################################################################

export NUMBA_CACHE_DIR=$PBS_O_WORKDIR

source ~/.bashrc
module load gcc/9.1.0
conda activate sdecouplings
cd $PBS_O_WORKDIR
SRAND=$PBS_ARRAY_INDEX
python faces.py --srcpath /scratch/st-schieb-1/zsteve/wtf/src --n_iter 25 --outfile "output_$SRAND" --r 70 --srand $SRAND --rho0 0.05


<filename>d/build.sh<gh_stars>0
#!/usr/bin/env sh
dmd hello.d


#!/bin/bash
trap exit ERR
yum -y install krb5-server rng-tools

function svcctl() {
    if which systemctl 2>/dev/null
    then
       systemctl $@
    else
	if [ "$1" = "enable" ]
	then
	    chkconfig $2 on
	else
	    service $2 $1
	fi
    fi
}

grep rdrand /proc/cpuinfo || echo 'EXTRAOPTIONS="-r /dev/urandom"' >> /etc/sysconfig/rngd
svcctl start rngd

REALM=HADOOPSECURITY.LOCAL

PRIVATE_IP=$(hostname -I)

cp -f /etc/krb5.conf{,.original}

cat - >/etc/krb5.conf <<EOF
[libdefaults]
 default_realm = ${REALM:?}
 dns_lookup_realm = false
 dns_lookup_kdc = false
 ticket_lifetime = 24h
 renew_lifetime = 7d
 forwardable = true
 default_tgs_enctypes = aes256-cts-hmac-sha1-96 aes128-cts-hmac-sha1-96 arcfour-hmac-md5
 default_tkt_enctypes = aes256-cts-hmac-sha1-96 aes128-cts-hmac-sha1-96 arcfour-hmac-md5
 permitted_enctypes = aes256-cts-hmac-sha1-96 aes128-cts-hmac-sha1-96 arcfour-hmac-md5

[realms]
 ${REALM:?} = {
  kdc = ${PRIVATE_IP:?}
  admin_server = ${PRIVATE_IP:?}
 }
EOF

mv /var/kerberos/krb5kdc/kadm5.acl{,.original}
cat - >/var/kerberos/krb5kdc/kadm5.acl <<EOF
*/admin@${REALM:?}	*
EOF

mv /var/kerberos/krb5kdc/kdc.conf{,.original}
cat - >/var/kerberos/krb5kdc/kdc.conf <<EOF
[kdcdefaults]
 kdc_ports = 88
 kdc_tcp_ports = 88

[realms]
 ${REALM:?} = {
 acl_file = /var/kerberos/krb5kdc/kadm5.acl
 dict_file = /usr/share/dict/words
 admin_keytab = /var/kerberos/krb5kdc/kadm5.keytab
 supported_enctypes = aes256-cts-hmac-sha1-96:normal aes128-cts-hmac-sha1-96:normal arcfour-hmac-md5:normal
 max_renewable_life = 7d
}
EOF

kdb5_util create -P Passw0rd!

svcctl start krb5kdc
svcctl enable krb5kdc
svcctl start kadmin
svcctl enable kadmin
svcctl stop iptables || :

# use this technique instead of kadmin.local addprinc -pw ... because
# the version of kadmin.local on CentOS6 doesn't allow for passing
# commands in directly.

echo -e 'addprinc -pw Passw0rd! cm/admin\nexit' | kadmin.local
echo -e 'addprinc -pw Cloudera1 cdsw\nexit' | kadmin.local

# Ensure that selinux is turned off now and at reboot
setenforce 0
sed -i 's/SELINUX=.*/SELINUX=permissive/' /etc/selinux/config


#!/usr/bin/env bash

# run docker container
docker run -p 3306:3306 --name mysql -e MYSQL_ROOT_PASSWORD=<PASSWORD> -d mysql:8.0.16

sleep 20

# run sql script for initializing database
mysql -u root -p12345 -h 127.0.0.1 -P 3306 < ./init_db.sql


<reponame>SimonRit/RTKPythonPackage<filename>BuildLinuxWheels.sh
#!/bin/bash
set -x
set -e
# This script should lie in a directory alongside with the RTK sources
cd RTK

# Fetch script from https://rawgit.com/InsightSoftwareConsortium/ITKPythonPackage
curl -L https://raw.githubusercontent.com/InsightSoftwareConsortium/ITKPythonPackage/master/scripts/dockcross-manylinux-download-cache-and-build-module-wheels.sh -O
chmod u+x dockcross-manylinux-download-cache-and-build-module-wheels.sh

export ITK_PACKAGE_VERSION=v5.0rc01

# Remove call to the build script to only perform the download step.
# This allows for altering the cache in case sources are not up-to-date
replace_line="./ITKPythonPackage/scripts/dockcross-manylinux-build-module-wheels.sh"
sed -i -e "s|$replace_line||g" \
  dockcross-manylinux-download-cache-and-build-module-wheels.sh

if [[ ! -d ITKPythonPackage ]]; then
  ./dockcross-manylinux-download-cache-and-build-module-wheels.sh
fi

# Add CMake options for building the module
after_line='-DBUILD_TESTING:BOOL=OFF \\'
pwd
rtk_build_applications='-DRTK_BUILD_APPLICATIONS:BOOL=OFF \\'
sed -i -e "s|$after_line|$after_line\n      $rtk_build_applications|g" \
  ITKPythonPackage/scripts/internal/manylinux-build-module-wheels.sh

rtk_cuda='-DRTK_USE_CUDA:BOOL=OFF \\'
sed -i -e "s|$after_line|$after_line\n      $rtk_cuda|g" \
  ITKPythonPackage/scripts/internal/manylinux-build-module-wheels.sh

if [ $ITK_PACKAGE_VERSION == v4.13.0 ]; then
  echo 'Building against ITK 4.13.0 Adding -std=c++11 flag.. ' 1>&2
  cmake_cxx_flags='-DCMAKE_CXX_FLAGS="${CMAKE_CXX_FLAGS} -std=c++11" \\'
  sed -i -e "s|$after_line|$after_line\n      $cmake_cxx_flags|g" \
    ITKPythonPackage/scripts/internal/manylinux-build-module-wheels.sh
fi

# Finally build Linux wheels
./ITKPythonPackage/scripts/dockcross-manylinux-build-module-wheels.sh


#!/bin/sh
set -e
for target in aarch64 armv6 i686 x86_64; do
  cp /usr/local/$target-unknown-cloudabi*/libexec/cloudabi-reexec bin/$target/
done


<reponame>manish-ntnx/future-0.18.2-ntnx<filename>create_egg.sh
#!/bin/bash

mkdir -p log
rm -rf build dist/*
python setup.py bdist_egg > "log/setup_py2_bdist_egg-`date "+%Y-%m-%d-%H-%M-%S"`.log"  2>&1
rm -rf build
python3 setup.py bdist_egg > "log/setup_py3_bdist_egg-`date "+%Y-%m-%d-%H-%M-%S"`.log"  2>&1
echo "Eggs:"
ls -lrt dist


<reponame>woofers/libgdx-tools-installer
#!/bin/bash

# Create .gdxtools
echo -n "export GDXTOOLS=" > ~/.gdxtools
pwd >> ~/.gdxtools
source ~/.gdxtools

# Clone Repo
git clone https://github.com/woofers/libgdx-tools-installer libgdx-tools

# LibGDX Nightly
cd libgdx-tools
wget https://libgdx.badlogicgames.com/nightlies/libgdx-nightly-latest.zip
unzip libgdx-nightly-latest.zip -d libgdx
rm libgdx-nightly-latest.zip

# fbx-conv
cd libgdx
wget http://libgdx.badlogicgames.com/fbx-conv/fbx-conv.zip
unzip fbx-conv.zip -d fbx-conv
ln -s "$GDXTOOLS/libgdx-tools/libgdx/fbx-conv/libfbxsdk.so" "/usr/lib64/libfbxsdk.so"
rm fbx-conv.zip

# Set GUI Versions
FBX_GUI=1.5
TEXTURE_PACKER_GUI=4.7.3

# fbx-conv GUI
cd fbx-conv
wget https://github.com/ASneakyFox/libgdx-fbxconv-gui/releases/download/$FBX_GUI/fbxconv-gui.jar
cd ..

# texture-packer GUI
wget https://github.com/crashinvaders/gdx-texture-packer-gui/releases/download/$TEXTURE_PACKER_GUI/gdx-texturepacker-$TEXTURE_PACKER_GUI.zip
unzip gdx-texturepacker-$TEXTURE_PACKER_GUI.zip -d texture-packer-gui
cd texture-packer-gui

# Alias Commands
ln -s "$GDXTOOLS/libgdx-tools/texture-packer" "/usr/bin/texture-packer"
ln -s "$GDXTOOLS/libgdx-tools/texture-packer-gui" "/usr/bin/texture-packer-gui"
ln -s "$GDXTOOLS/libgdx-tools/tiled-packer" "/usr/bin/tiled-packer"
ln -s "$GDXTOOLS/libgdx-tools/fbx-conv-gui" "/usr/bin/fbx-conv-gui"

if [[ "$OSTYPE" == "darwin"* ]]; then
    ln -s "$GDXTOOLS/libgdx-tools/libgdx/fbx-conv/fbx-conv-mac" "/usr/bin/fbx-conv"
else
    ln -s "$GDXTOOLS/libgdx-tools/libgdx/fbx-conv/fbx-conv-lin64" "/usr/bin/fbx-conv"
fi


#!/usr/bin/env bash

set -e

usage() {
  cat << EOF
Usage: REGION=<region> AWS_PROFILE=<profile> $(basename $0) <cluster_name>

Upgrade EKS cluster worker nodes by draining and terminating a single instance at a time.

This script requires ~10.5min to cycle EKS worker nodes.

ENVIRONMENT VARIABLES REQUIRED:

  REGION            the AWS region your cluster is deployed to
  AWS_PROFILE       an AWS profile to access your cluster

EXAMPLE:

  REGION=us-west-2 AWS_PROFILE=nwi-eks-admin ./upgrade-eks-workers.sh <cluster_name>

EOF
    if [[ ! -z $AWS_PROFILE ]]; then
        echo "Specify an EKS cluster you want to upgrade:"
        aws eks list-clusters --region $REGION --profile $AWS_PROFILE --no-cli-pager | jq '.clusters[]' | cut -d '"' -f 2 | xargs -I'{}' echo "  {}"
    fi
}

# check ENV Vars and cluster were provided
if [[ -z $REGION || -z $AWS_PROFILE || -z $1 ]]; then
    usage
    exit 1;
fi

# check that cluster is accessible via provided profile
CLUSTER_NAME=$1
if [[ $(aws eks list-clusters --region $REGION --profile $AWS_PROFILE --no-cli-pager | jq '.clusters[]' | cut -d '"' -f 2 | grep $CLUSTER_NAME | wc -l) -lt 1 ]]; then
    usage
    exit 1;
fi

# Configure EKS cluster kube config
aws eks update-kubeconfig --name "$CLUSTER_NAME" --region $REGION --profile $AWS_PROFILE

################################################################
# Pre-Check: ensure we have a healthy cluster to upgrade
################################################################

node_count=$(kubectl get node | wc -l)
if [[ $node_count -lt 4 ]];
then
    echo "UNABLE TO UPGRADE WORKERS: cluster is missing worker nodes."
    kubectl get node
    exit 1;
fi

node_not_ready_count=$(kubectl get node | egrep "NotReady|SchedulingDisabled" | wc -l)
if [[ $node_not_ready_count -gt 0 ]];
then
    echo "UNABLE TO UPGRADE WORKERS: eks worker nodes not ready"
    kubectl get node
    exit 1;
fi

echo ">>> Current pod count: $(kubectl get pod | wc -l )"
echo ">>> Current Node configuration:"
kubectl get nodes
echo ">>> Current Pod configuration:"
kubectl get pods -o wide

################################################################
# Upgrade EKS worker nodes
################################################################

WORKERS=($(kubectl describe node | grep 'Name:' | awk '{print $2}'))
WORKER_COUNT=${#WORKERS[@]}
looptime="5 minute"

for worker in "${WORKERS[@]}"
do
    POD_COUNT=$(kubectl get pods | wc -l)
    INSTANCE_ID=$(kubectl describe node $worker | grep 'ProviderID:' | awk '{print $2}' | cut -d'/' -f 5)

    kubectl drain $worker --ignore-daemonsets --delete-emptydir-data
    # poll/wait for pods to drain from worker node
    wait_for_pod_drain=true
    wait_for_loop_timeout=true
    endtime=$(date -ud "$looptime" +%s)
    while $wait_for_pod_drain && $wait_for_loop_timeout;
    do
        echo ">>> pods on this worker $worker"
        kubectl get pods -o wide | grep $worker
        if [[ $(kubectl drain $worker --ignore-daemonsets --delete-emptydir-data | grep "drained" | wc -l) -gt 0 ]]; then
            wait_for_pod_drain=false
        fi
        if [[ $(date -u +%s) -ge $endtime ]]; then
            wait_for_loop_timeout=false
            echo ">>> draining $worker timed out (will now terminate the ec2 instance)"
        fi
        sleep 2;
    done

    echo ">>> terminating EC2 instance $INSTANCE_ID"
    aws ec2 terminate-instances --instance-ids $INSTANCE_ID --region $REGION --profile $AWS_PROFILE --no-cli-pager || \
        (echo "The profile we are currently using doesnt have sufficient permission to terminate $INSTANCE_ID" && exit 1)

    # poll/wait for instance termination
    wait_for_instance_term=true
    endtime=$(date -ud "$looptime" +%s)
    while $wait_for_instance_term;
    do
        echo ">>> waiting for instance $INSTANCE_ID to terminate"
        sleep 2;
        if [[ $(aws ec2 terminate-instances --region $REGION --profile $AWS_PROFILE --instance-ids $INSTANCE_ID | jq '.TerminatingInstances[].CurrentState|.Name' | grep 'terminated' | wc -l) == 1 ]]; then
            wait_for_instance_term=false
        fi
        if [[ $(date -u +%s) -ge $endtime ]]; then
            echo ">>> TIMEOUT: ec2 instance termination taking longer than expected...exiting"
            exit 1
        fi
    done

    # poll/wait for replacement node to come online
    wait_for_replacement_node_prov=true
    endtime=$(date -ud "$looptime" +%s)
    while $wait_for_replacement_node_prov;
    do
        echo ">>> waiting for ASG to prov new k8s worker node"
        kubectl get node
        echo ">>> current pod count: $(kubectl get pod | wc -l ) (target pod count >= $POD_COUNT)"
        sleep 2;
        if [[ $(kubectl get node | grep -v 'NotReady' | grep 'Ready' | wc -l ) -ge $WORKER_COUNT && \
            $(kubectl get node | egrep 'NotReady|SchedulingDisabled' | wc -l ) -lt 1 ]]; then
            wait_for_replacement_node_prov=false
        fi
        if [[ $(date -u +%s) -ge $endtime ]]; then
            echo ">>> TIMEOUT: replacement worker node instance provisioning taking longer than expecting...exiting"
            exit 1
        fi
    done
done

echo ">>> EKS WORKERS UPGRADED!"
echo ">>> Current pod count: $(kubectl get pod | wc -l )"
echo ">>> Current Node configuration:"
kubectl get nodes
echo ">>> Current Pod configuration:"
kubectl get pods -o wide


#! /usr/bin/env bash

cd "$(dirname "$0")"
virtualenv -p python3 env
source env/bin/activate
make dependencies


#!/usr/bin/env bash

set -Eeo pipefail

setup_stack () {
  zenml model-deployer register mlflow_deployer --type=mlflow || \
    msg "${WARNING}Reusing preexisting model deployer ${NOFORMAT}mlflow_deployer"
  zenml experiment-tracker register mlflow_tracker  --type=mlflow || \
    msg "${WARNING}Reusing preexisting experiment tracker ${NOFORMAT}mlflow_tracker"
  zenml stack register local_mlflow_stack \
      -m default \
      -a default \
      -o default \
      -d mlflow_deployer \
      -e mlflow_tracker || \
    msg "${WARNING}Reusing preexisting stack ${NOFORMAT}local_mlflow_stack"

  zenml stack set local_mlflow_stack
}

pre_run () {
  zenml integration install tensorflow mlflow
}

pre_run_forced () {
  zenml integration install tensorflow mlflow -y
}

post_run () {
  # cleanup the last local ZenML daemon started by the example
  pkill -n -f zenml.services.local.local_daemon_entrypoint
}


#!/bin/bash

. /etc/profile.d/btcpay-env.sh

cd "`dirname $BTCPAY_ENV_FILE`"
docker-compose -f $BTCPAY_DOCKER_COMPOSE up -d