text:
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;

namespace Hangman
{
    #region Vung khai bao kieu du lieu
    // cau truc luu tru mot thanh tich
    struct ThanhTich
    {
        public string ten; // ho ten nguoi choi
        public double sogiay; // thoi gian choi bang giay
    }

    // Kieu cu phap the hien cu phap dong lenh khi goi chuong trinh
    // Dang 1 : Hangman.exe
    // Dang 2 : Hangman.exe -h
    // Dang 3 : Hangman.exe <path>
    enum KieuCuPhap { Dang1, Dang2, Dang3 };
    #endregion

    class Program
    {
        #region Khai bao bien
        // duong dan den tap tin tu dien tu
        static string dictpath = "words.txt";
        // danh sach cac tu doc duoc trong tu dien
        static List<string> listWords;
        // tu duoc chon de choi
        static string secret_word;
        // cac ky tu da doan
        static List<char> letters_guessed;
        // so lan da doan sai
        static int mistakes_made;
        // bien kieuCP de nhan dang cu phap dong lenh
        static KieuCuPhap kieuCP;
        // duong dan den tap tin luu danh sach vinh danh
        static string top10path = "top10.txt";
        // bien luu tru danh sach top10
        static List<ThanhTich> listTop10;
        // thanh tich moi
        static ThanhTich thanhtich;
        #endregion

        #region Main
        static void Main(string[] args)
        {
            // thiet lap lai kich thuoc cua console
            Console.SetWindowSize(Console.LargestWindowWidth, Console.LargestWindowHeight);

            // Kiem tra doi so dong lenh
            // de xac dinh dang cu phap dong lenh
            if (args.Length == 0)
                kieuCP = KieuCuPhap.Dang1; // khi khong co doi so nao thi thuc hien theo dang 1
            else if (args.Length == 1)
            { // khi co 1 doi so, co the thuoc vao dang 2, 3
                if (args[0] == "-h") // neu la chuoi "-h"
                    kieuCP = KieuCuPhap.Dang2; // thuoc dang 2
                else // nguoc lai, thuoc dang 3
                    kieuCP = KieuCuPhap.Dang3;
            }
            else
            {
                // In thong bao loi va hien thi huong dan su dung
                Console.WriteLine("Lenh goi chuong trinh cua ban bi sai");
                kieuCP = KieuCuPhap.Dang2;
            }

            // xu ly theo dang cu phap dong lenh
            switch (kieuCP)
            {
                case KieuCuPhap.Dang2:
                    InHuongDanSuDung(); // In ra huong dan su dung
                    Console.ReadKey(); // Cho nguoi sd doc huong dan va bam enter
                    Environment.Exit(0); // roi thoat khoi chuong trinh
                    break;
                case KieuCuPhap.Dang3:
                    // Goi ham nhap du lieu voi so luong phan tu da biet
                    dictpath = args[0];
                    break;
            }

            // Doc file tu dien
            if (!DocTuDien())
                return; // neu doc khong duoc

            // khoi tao va doc file top10.txt
            listTop10 = new List<ThanhTich>();
            DocTop10();

            // Doc duoc thi hien thi menu
            XuLyMenu();
        }

        // Ham thuc hien in ra huong dan su dung cho chuong trinh
        static void InHuongDanSuDung()
        {
            Console.WriteLine();
            Console.WriteLine("TRO CHOI HANGMAN");
            Console.WriteLine("Cu phap cau lenh theo 1 trong 3 dang sau :");
            Console.WriteLine("Hangman.exe"); // Dang 1
            Console.WriteLine("Hangman.exe -h"); // Dang 2
            Console.WriteLine("Hangman.exe <path>"); // Dang 4
            Console.WriteLine();
        }
        #endregion

        #region Xu ly menu
        // In menu cua chuong trinh
        static void InMenu()
        {
            Console.WriteLine();
            Console.Write("TRO CHOI HANGMAN");
            Console.WriteLine();
            Console.WriteLine("1 - Choi van moi");
            Console.WriteLine("2 - Xem danh sach vinh danh");
            Console.WriteLine("3 - Thoat");
            Console.WriteLine("Hay chon so tu 1 den 3 phu hop voi chuc nang tuong ung.");
            Console.Write("Ban chon so : ");
        }

        // ham xu ly menu
        static void XuLyMenu()
        {
            int menu;
            while (true)
            {
                InMenu(); // in menu ra man hinh
                menu = XulyChonMenu(1, 3); // cho nguoi su dung chon menu

                switch (menu)
                {
                    case 1: // Choi van moi
                        Choi();
                        break;
                    case 2: // Xem danh sach vinh danh
                        InTop10();
                        break;
                    case 3: // thoat khoi chuong trinh
                        if (XuLyCauHoiYesNo("Ban co chac muon thoat chuong trinh ? (Y/N): "))
                        {
                            Console.WriteLine("\nCam on ban da su dung chuong trinh !");
                            Console.ReadKey();

                            // luu danh sach vinh danh truoc khi ket thuc chuong trinh
                            LuuTop10();
                            Environment.Exit(0);
                        }
                        break;
                }
            }
        }

        // ham nay tra ra mot so tu 1 den 3
        // tuong ung voi cac so tren menu ma nguoi su dung nhap
        // hai tham so soduoi va sotren giup cho ham nay co the xu ly cho bat ky menu nao
        static int XulyChonMenu(int soduoi, int sotren)
        {
            int menu;
            // ham TryParse thuc hien chuyen doi tu chuoi sang so
            // neu co the chuyen duoc thi ham nay tra ra gia tri true
            // va ket qua o tham chieu menu
            while (!int.TryParse(Console.ReadLine(), out menu)
                   && ((menu < soduoi) || (menu > sotren)))
            {
                Console.WriteLine("Ban chon so nam ngoai pham vi cac so tren menu.");
                Console.WriteLine("Hay chon so tu {0} den {1} phu hop voi chuc nang tuong ung.", soduoi, sotren);
                Console.Write("Moi ban chon lai : ");
            }
            return menu;
        }
        #endregion

        #region Hangman
        static void Choi()
        {
            // Lay mot tu ngau nhien tu tu dien
            secret_word = ChonTuDeChoi();
            if (secret_word == null) // neu loi
            {
                ThongBaoLoi("Khong the lua chon tu de choi.");
                return;
            }

            // Khoi gan lai gia tri cho letters_guessed va mistakes_made
            KhoiGanLaiGiaTri();
            // lay ten nguoi choi
            Console.Write("Moi ban nhap ten nguoi choi : ");
            thanhtich.ten = Console.ReadLine();

            DateTime tgBatDauChoi = DateTime.Now; // lay thoi gian bat dau choi

            TrangThai trangthai = TrangThai.Choi;
            string mess = string.Format("TU can doan co {0} ky tu: ", secret_word.Length);
            while (true)
            {
                InTrangThaiHienTai(trangthai, mess);
                if (trangthai == TrangThai.Thang) // tinh thoi gian thang
                {
                    TimeSpan tongThoiGianChoi = DateTime.Now - tgBatDauChoi;
                    thanhtich.sogiay = tongThoiGianChoi.TotalSeconds;

                    // so sanh xem thoi gian nay co nam trong pham vi top 10 khong
                    // neu co thi chen vao, xoa cuoi
                    // luu xuong file truoc khi ket thuc chuong trinh
                    ThemThanhTich();
                }
                if (trangthai == TrangThai.Thang || trangthai == TrangThai.Thua)
                    break;
                // Cho nguoi dung nhap vao ky tu hoac tu can doan
                string doan = NhapDuDoan();
                Console.Clear();

                if (doan.Length == 1) // doan 1 ky tu
                {
                    // Kiem tra xem ky tu do da doan hay chua
                    if (LaDaDoan(doan[0]))
                    {
                        mess = string.Format("Ban da doan ky tu \'{0}\' roi : ", doan[0]);
                        continue;
                    }

                    char c = doan[0];
                    letters_guessed.Add(c);
                    if (LaTrung())
                    {
                        trangthai = TrangThai.Thang;
                        mess += string.Format("THANG ROI. Chuc mung ban!\nTu ban doan duoc la : {0}", secret_word);
                    }
                    else
                    {
                        // Kiem tra tu moi doan co dung khong
                        if (LaCo(c))
                        {
                            mess = string.Format("Co {0} ky tu \'{1}\' trong tu can doan : ",
                                                 DemKyTu(c),
                                                 c);
                        }
                        else // neu khong co
                        {
                            mistakes_made++; // tang so loi
                            if (mistakes_made < 6)
                                mess = string.Format("Khong co ky tu \'{0}\' trong tu can doan : ", c);
                            else if (mistakes_made == 6) // neu da du 6 loi
                            {
                                trangthai = TrangThai.Thua;
                                mess = string.Format("Khong co ky tu \'{0}\' trong tu can doan.\n", c);
                                mess += "BAN THUA! Ban da co 6 lan doan sai.\n";
                                mess += string.Format("Tu can doan la {0}\n", secret_word);
                                // in ra cac ky tu chua doan duoc
                                mess += string.Format("Cac ky tu ban chua doan duoc : {0}", CacKyTuChuaDoanDuoc());
                            }
                        }
                    }
                }
                else // mot tu
                {
                    if (LaTrung(doan))
                    {
                        trangthai = TrangThai.Thang;
                        mess += string.Format("\nTHANG ROI. Chuc mung ban!\nTu ban doan duoc la : {0}", secret_word);
                    }
                    else
                    {
                        mistakes_made += 2;
                        mess = string.Format("Khong phai la tu {0} dau ban.", doan);
                        if (mistakes_made >= 6)
                        {
                            trangthai = TrangThai.Thua;
                            mess += "BAN THUA! Ban da co 6 lan doan sai.\n";
                            mess += string.Format("Tu can doan la {0}\n", secret_word);
                            // in ra cac ky tu chua doan duoc
                            mess += string.Format("Cac ky tu ban chua doan duoc : {0}", CacKyTuChuaDoanDuoc());
                        }
                    }
                }
            }
        }

        enum TrangThai { Choi, Thang, Thua}
        // Ham in trang thai hien tai cua tro choi
        static void InTrangThaiHienTai(TrangThai trangthai, string mess)
        {
            Console.Clear();
            //Console.WriteLine(secret_word); // XOA SAU KHI XONG CHUONG TRINH
            Console.WriteLine("TRO CHOI HANGMAN");
            HangmanImage.PrintImage(mistakes_made);
            Console.WriteLine();
            switch (trangthai)
            {
                case TrangThai.Choi:
                    Console.Write(mess);
                    // In chuoi ky tu can doan
                    Console.WriteLine(ChuoiKyTuCanDoan());
                    // Thong bao cac ky tu da du doan
                    Console.WriteLine("Ban da doan cac ky tu : {0}", CacKyTuDaDuDoan());
                    // Thong bao so lan con co the du doan
                    Console.WriteLine("Ban con {0} lan doan.", 6 - mistakes_made);
                    break;
                case TrangThai.Thang:
                case TrangThai.Thua:
                    Console.WriteLine(mess);
                    Console.ReadKey();
                    break;
            }
        }

        // Ham nhap tu hoac ky tu du doan
        static string NhapDuDoan()
        {
            Console.Write("Moi nhap ky tu hoac tu du doan: ");
            string doan = Console.ReadLine();
            while (true)
            {
                if (string.IsNullOrEmpty(doan))
                {
                    Console.Write("Ky tu hoac tu khong the la rong. Moi ban nhap lai: ");
                    doan = Console.ReadLine();
                    continue;
                }
                if (doan.Length == 1 && !char.IsLetter(doan[0]))
                {
                    Console.Write("Ban phai nhap ky tu. Moi ban nhap lai: ");
                    doan = Console.ReadLine();
                    continue;
                }
                break;
            }
            return doan;
        }

        // Ham kiem tra cac ky tu da doan trung voi tu can doan
        static bool LaTrung()
        {
            foreach (char c in secret_word)
                if (!letters_guessed.Contains(c))
                    return false;
            return true;
        }

        // Ham kiem tra trung 1 tu
        static bool LaTrung(string st)
        {
            return secret_word == st;
        }

        // Ham kiem tra ky tu da co trong letters_guessed hay khong
        static bool LaDaDoan(char c)
        {
            return letters_guessed.Contains(c);
        }

        // Ham kiem tra ky tu doan co ton tai trong tu du doan khong
        static bool LaCo(char c)
        {
            return secret_word.Contains(c);
        }

        // Ham dem so ky tu trong tu can doan
        static int DemKyTu(char c)
        {
            int dem = 0;
            foreach (char t in secret_word)
                if (c == t) dem++;
            return dem;
        }

        // Ham tra ra cac ky tu da du doan
        static string CacKyTuDaDuDoan()
        {
            string st = "";
            foreach (char c in letters_guessed)
                st += string.Format(" {0}", c);
            return st;
        }

        // Ham tra ra ky tu chua doan duoc
        static string CacKyTuChuaDoanDuoc()
        {
            string st = "";
            foreach (char c in secret_word)
                if (!letters_guessed.Contains(c))
                    st += string.Format(" {0}", c);
            return st;
        }

        // Ham in day ky tu can doan
        static string ChuoiKyTuCanDoan()
        {
            string st = "";
            foreach (char c in secret_word)
                if (letters_guessed.Contains(c))
                    st += c;
                else
                    st += "-";
            return st;
        }

        // Ham lua chon 1 tu de choi
        static string ChonTuDeChoi()
        {
            // neu chua co danh sach tu
            if (listWords == null || listWords.Count == 0)
                return null; // thi tra ra null

            Random r = new Random();
            int index = r.Next(0, listWords.Count); // lay mot so ngau nhien
            return listWords[index]; // tra ra tu tai vi tri ngau nhien do
        }

        // Gan lai gia tri ban dau cho cac bien luu tru du lieu
        static void KhoiGanLaiGiaTri()
        {
            letters_guessed = new List<char>();
            mistakes_made = 0;
            thanhtich = new ThanhTich();
        }
        #endregion

        #region Top10
        // In danh sach vinh danh
        static void InTop10()
        {
            Console.Clear();
            Console.WriteLine("BANG VINH DANH");
            int count = 0;
            foreach(ThanhTich tt in listTop10)
            {
                count++;
                TimeSpan time = TimeSpan.FromSeconds((long)tt.sogiay);
                Console.WriteLine("{0}. {1} - {2}:{3}:{4}",
                                  count,
                                  tt.ten,
                                  time.Hours,
                                  time.Minutes,
                                  time.Seconds);
            }
        }

        // Them thanh tich moi vao top10
        // co the them duoc hoac khong
        static void ThemThanhTich()
        {
            int i;
            for (i = 0; i < listTop10.Count; i++)
                if (listTop10[i].sogiay > thanhtich.sogiay)
                    break;
            if (i == listTop10.Count && listTop10.Count < 10)
                listTop10.Add(thanhtich);
            if (i < listTop10.Count)
                listTop10.Insert(i, thanhtich);
            if (listTop10.Count > 10)
                listTop10.RemoveAt(listTop10.Count - 1);
        }
        #endregion

        #region Xu ly file
        static bool DocTuDien()
        {
            if (dictpath == null) // neu khong co duong dan den tu dien
            {
                ThongBaoLoiFile("Ban chua cung cap tu dien tu.");
                return false; // thi thoat khoi ham
            }

            // mo file ra de doc
            StreamReader reader = new StreamReader(dictpath);
            if (reader == null) // neu mo bi loi
            {
                ThongBaoLoiFile("File ban nhap khong ton tai hoac duong dan sai.");
                return false; // thi thoat khoi ham
            }

            // doc tat ca cac tu
            string dong = reader.ReadLine();
            if (dong == null) // neu doc khong duoc
            {
                ThongBaoLoiFile("File tu dien bi loi.");
                return false; // thoat khoi ham
            }

            if (!TachTu(dong)) // thuc hien tach tu
            {
                listWords = null; // tach khong duoc
                return false;
            }

            // Dong tap tin
            reader.Close();

            return true;
        }

        // Ham co nhiem vu tach cac tu da doc duoc tu tu dien
        static bool TachTu(string input)
        {
            if (input == null)
            {
                ThongBaoLoiFile("File tu dien bi loi.");
                return false;
            }

            listWords = new List<string>();

            string[] items = input.Split(new char[]{' '}, StringSplitOptions.RemoveEmptyEntries);
            listWords.AddRange(items);

            return true;
        }

        // Ham doc file top10.txt
        static void DocTop10()
        {
            // kiem tra xem file top10.txt da co hay chua
            if (!File.Exists(top10path)) // neu chua thi thoat, khong can doc
                return;

            // neu roi thi mo ra doc
            StreamReader reader = new StreamReader(top10path);
            if (reader == null) // neu mo bi loi
                return; // thi thoat khoi ham

            // neu loi trong qua trinh doc va xu ly thi khong doc nua
            // danh sach da doc duoc cu de vay
            string dong = null;
            // doc mot dong trong file
            while ((dong = reader.ReadLine()) != null) // neu het file thi khong doc nua
            {
                ThanhTich tt;
                // tach cac thanh phan trong dong doc duoc
                // va gan gia tri vao bien cau truc don
                if (!TachGiaTri(dong, out tt)) // neu qua trinh tach bi loi
                    return; // thoat khoi ham

                // nguoc lai
                listTop10.Add(tt); // them thanh tich vao danh sach
                // file da luu theo thu tu so giay tang dan
                // nen khi doc ra chi can dung ham Add
            }

            // Dong tap tin
            reader.Close();
        }

        // Ham co nhiem vu tach chuoi doc duoc tu file top10.txt
        // gan gia tri vao bien tt
        static bool TachGiaTri(string input, out ThanhTich tt)
        {
            tt = new ThanhTich();
            string[] items = input.Split('|'); // tach chuoi

            // phai chua 2 thanh phan
            if (items.Length != 2) return false;

            tt.ten = items[0]; // thanh phan thu nhat gan cho ten

            // thanh phan thu hai
            // ep kieu sang so kieu double
            if (!double.TryParse(items[1], out tt.sogiay))
                return false; // neu ep khong duoc thi bao loi

            return true;
        }

        // Xu ly luu danh sach top10 xuong file
        static void LuuTop10()
        {
            while (string.IsNullOrEmpty(top10path)) // neu khong co duong dan
                top10path = "top10.txt";

            // mo file ra de ghi
            StreamWriter writer = new StreamWriter(top10path);
            if (writer == null) // mo khong duoc
                return; // error

            // Ghi dữ liệu vào tập tin
            foreach (ThanhTich tt in listTop10)
                writer.WriteLine("{0}|{1}",
                                 tt.ten,
                                 tt.sogiay);

            writer.Close(); // dong file
        }

        // Ham xu ly in thong bao cac loi khi doc va ghi file
        static void ThongBaoLoiFile(string st, StreamReader reader = null)
        {
            ThongBaoLoi(st);
            if (reader != null)
                reader.Close();
        }
        #endregion

        #region CHUNG
        // Ham xu ly in cau hoi yes no
        static bool XuLyCauHoiYesNo(string cauhoi)
        {
            Console.Write(cauhoi); // in cau hoi
            ConsoleKeyInfo c = Console.ReadKey(); // nguoi su dung nhap vao lua chon
            Console.WriteLine();

            if (c.KeyChar == 'Y' || c.KeyChar == 'y')
                return true;
            return false;
        }

        // Ham xu ly in thong bao cac loi
        static void ThongBaoLoi(string st)
        {
            Console.Write(st);
            Console.ReadKey();
        }

        // Ham kiem tra danh sach rong
        //static bool LaRong(string mucdich)
        //{
        //    if (listFC.Count == 0)
        //    {
        //        Console.WriteLine("\nCo so du lieu khong co flashcard nao {0}.", mucdich);
        //        Console.ReadKey();
        //        return true;
        //    }
        //    return false;
        //}

        // xu ly nhap ma don dang ky muon phong
        //static int XulyNhapMa(string mucdich)
        //{
        //    int ma;
        //    Console.Write("Nhap ma don dang ky {0} : ", mucdich);
        //    while (!int.TryParse(Console.ReadLine(), out ma)
        //          || ma < 0)
        //    {
        //        Console.WriteLine("Ma don dang ky ban nhap khong dung.");
        //        if (XuLyCauHoiYesNo("Ban co muon nhap lai khong ? (Y/N) : "))
        //            Console.Write("Moi ban nhap lai :");
        //        else
        //            break;
        //    }
        //    return ma;
        //}

        // Ham tra ra vi tri cua mot flashcard theo tu
        //static int LayIndexTheoTu(string tu)
        //{
        //    for (int i = 0; i < listFC.Count; i++)
        //        if (tu == listFC[i].tu)
        //            return i;
        //    return -1;
        //}
        #endregion
    }
}


text:
import os
from scrapy.exceptions import CloseSpider
from scraper.models import Event
from scraper.scraper_test import EventSpider, ScraperTest
from dynamic_scraper.models import SchedulerRuntime

class ScraperJSRunTest(ScraperTest):

    def setUpScraperJSDefaultScraper(self):
        self.event_website.url = os.path.join('http://localhost:8010/static/', 'site_with_js/event_main.html')
        self.event_website.save()

    def setUpScraperJSDockerScraper(self):
        self.event_website.url = os.path.join('http://10.0.2.2:8010/static/', 'site_with_js/event_main_docker.html')
        self.event_website.save()
        self.rpt_mp.render_javascript = True
        self.rpt_mp.dont_filter = True
        self.rpt_mp.save()
        self.rpt_dp1.render_javascript = True
        self.rpt_dp1.dont_filter = True
        self.rpt_dp1.save()

    def setUpScraperJSChecker(self, path):
        super(ScraperJSRunTest, self).setUp()

        self.scraper.checker_type = 'X'
        self.scraper.checker_x_path = u'//div[@class="event_not_found"]/div/text()'
        self.scraper.checker_ref_url = u'%ssite_with_js/event_not_found.html' % path
        self.scraper.save()

        scheduler_rt = SchedulerRuntime()
        scheduler_rt.save()

        self.event = Event(title='Event 1', event_website=self.event_website,
            description='Event 1 description',
            url='%ssite_with_js/event_not_found.html' % path,
            checker_runtime=scheduler_rt)
        self.event.save()

    def setUpScraperJSDefaultChecker(self):
        self.setUpScraperJSChecker('http://localhost:8010/static/')

    def setUpScraperJSDockerChecker(self):
        self.setUpScraperJSChecker('http://10.0.2.2:8010/static/')
        self.rpt_dp1.render_javascript = True
        self.rpt_dp1.save()

    def test_default_no_scrapyjs_main_page(self):
        self.setUpScraperJSDefaultScraper()
        self.run_event_spider(1)
        self.assertEqual(len(Event.objects.all()), 1)

    def test_default_no_scrapyjs_detail_page(self):
        self.setUpScraperJSDefaultScraper()
        self.run_event_spider(1)
        self.assertEqual(len(Event.objects.filter(description='Event 1 description')), 1)

    def test_activated_scrapyjs_main_page(self):
        self.setUpScraperJSDockerScraper()
        self.run_event_spider(1)
        self.assertEqual(len(Event.objects.all()), 2)

    def test_activated_scrapyjs_detail_page(self):
        self.setUpScraperJSDockerScraper()
        self.run_event_spider(1)
        self.assertEqual(len(Event.objects.filter(description='Event 1 JS description')), 1)

    def test_only_main_page_scrapyjs_main_page(self):
        self.setUpScraperJSDockerScraper()
        self.event_website.url = os.path.join('http://10.0.2.2:8010/static/', 'site_with_js/event_main.html')
        self.event_website.save()
        self.rpt_dp1.render_javascript = False
        self.rpt_dp1.save()

        self.run_event_spider(1)
        self.assertEqual(len(Event.objects.all()), 2)
        self.assertEqual(len(Event.objects.filter(description='Event 1 description')), 1)
        self.assertEqual(len(Event.objects.filter(description='Event 1 JS description')), 0)

    def test_default_no_scrapyjs_checker_delete(self):
        self.setUpScraperJSDefaultChecker()
        self.scraper.checker_x_path_result = u'Event not found'
        self.scraper.save()

        self.run_event_checker(1)
        self.assertEqual(len(Event.objects.all()), 0)

    def test_default_no_scrapyjs_checker_no_delete(self):
        self.setUpScraperJSDefaultChecker()
        self.scraper.checker_x_path_result = u'Event JS not found'
        self.scraper.save()

        self.run_event_checker(1)
        self.assertEqual(len(Event.objects.all()), 1)

    def test_activated_scrapyjs_checker_delete(self):
        self.setUpScraperJSDockerChecker()
        self.scraper.checker_x_path_result = u'Event JS not found'
        self.scraper.save()

        self.run_event_checker(1)
        self.assertEqual(len(Event.objects.all()), 0)

    def test_activated_scrapyjs_checker_no_delete(self):
        self.setUpScraperJSDockerChecker()
        self.scraper.checker_x_path_result = u'Event not found'
        self.scraper.save()

        self.run_event_checker(1)
        self.assertEqual(len(Event.objects.all()), 1)

redpajama_set_name: RedPajamaGithub


text:
var fs = require("fs");
var path = require("path");
var exec = require("child_process").exec;

var through2 = require("through2");

var FILE = path.join(__dirname, "plays.json");
var GAME_ID = "0021401228";

var movement = require("../lib/");

function demo () {
  try {
    fs.unlinkSync(FILE);
  } catch (e) { /* probably worked? */ }

  var st = movement.getMovementForGame(GAME_ID);

  st.on("close", function () {
      console.log("CLOSE");
      console.timeEnd("close");
    })
    .on("end", function () {
      console.log("END");
      console.timeEnd("end");
    });

  st.pipe(logger())
    .pipe(delimitedJson("\n"))
    .pipe(writeOne())
    .pipe(fs.createWriteStream(FILE));

  return st;
}

demo();

console.time("end");
console.time("close");
var events = [];

function delimitedJson (d) {
  return through2.obj(function (data, enc, done) {
    done(null, JSON.stringify(data) + d);
  });
}

function toMoment () {
  return through2.obj(function (data, enc, done) {
   done(null, data.moments.map(movement.Moment));
  });
}

function logger () {
  var i = 0;
  return through2.obj(function (data, enc, done) {
    console.log("eventid", data.eventid);
    ++i;
    events.push(data.eventid);
    done(null, data);
  });
}

function writeOne () {
  var written = false;
  return through2(function (data, enc, done) {
    if (!written) {
      written = true;
      var obj = JSON.parse(data.toString().trim());
      var str = JSON.stringify(obj, null, 2);
      fs.writeFileSync(path.join(__dirname, "head.json"), str);
    }
    done(null, data);
  });
}


text:
package ru.job4j.array;

import org.junit.Test;

import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
/**
 * TurnTest.
 *
 * @author Anatolii Shalobasov (proboostbiznes@gmail.com)
 * @version 1
 * @since 22.06.2017
 */
public class TurnTest {
	/**
     * Test add.
     */
    @Test
    public void whenTurnArrayWithEvenAmountOfElementsThenTurnedArray() {
		Turn turn = new Turn();
        int[] resultArray = {4, 3, 2, 1};
        int[] expectArray = turn.back(new int[]{1, 2, 3, 4});
        assertThat(resultArray, is(expectArray));
    }
	/**
     * Test add.
     */
    @Test
    public void whenTurnArrayWithOddAmountOfElementsThenTurnedArray() {
		Turn turn = new Turn();
        int[] resultArray = {5, 4, 3, 2, 1};
        int[] expectArray = turn.back(new int[]{1, 2, 3, 4, 5});
        assertThat(resultArray, is(expectArray));
    }
}


text:
export var noiseUniforms = {
  cNoiseOctave: { value: 6 },
  cNoiseFrequency: { value: 2.0 },
  cNoiseAmplitude: { value: 0.65 },
  cNoisePersistence: { value: 0.5 },
  cNoiseGraphEnable: { value: false},
};


text:
#ifndef TARGET_SIGNAL_H
#define TARGET_SIGNAL_H

#include "cpu.h"

/* this struct defines a stack used during syscall handling */

typedef struct target_sigaltstack {
	abi_ulong ss_sp;
	abi_long ss_flags;
	abi_ulong ss_size;
} target_stack_t;

/*
 * sigaltstack controls
 */
#define TARGET_SS_ONSTACK	1
#define TARGET_SS_DISABLE	2

#define TARGET_MINSIGSTKSZ	4096
#define TARGET_SIGSTKSZ		16384

static inline abi_ulong get_sp_from_cpustate(CPUAlphaState *state)
{
    return state->ir[IR_SP];
}

/* From <asm/gentrap.h>.  */
#define TARGET_GEN_INTOVF      -1      /* integer overflow */
#define TARGET_GEN_INTDIV      -2      /* integer division by zero */
#define TARGET_GEN_FLTOVF      -3      /* fp overflow */
#define TARGET_GEN_FLTDIV      -4      /* fp division by zero */
#define TARGET_GEN_FLTUND      -5      /* fp underflow */
#define TARGET_GEN_FLTINV      -6      /* invalid fp operand */
#define TARGET_GEN_FLTINE      -7      /* inexact fp operand */
#define TARGET_GEN_DECOVF      -8      /* decimal overflow (for COBOL??) */
#define TARGET_GEN_DECDIV      -9      /* decimal division by zero */
#define TARGET_GEN_DECINV      -10     /* invalid decimal operand */
#define TARGET_GEN_ROPRAND     -11     /* reserved operand */
#define TARGET_GEN_ASSERTERR   -12     /* assertion error */
#define TARGET_GEN_NULPTRERR   -13     /* null pointer error */
#define TARGET_GEN_STKOVF      -14     /* stack overflow */
#define TARGET_GEN_STRLENERR   -15     /* string length error */
#define TARGET_GEN_SUBSTRERR   -16     /* substring error */
#define TARGET_GEN_RANGERR     -17     /* range error */
#define TARGET_GEN_SUBRNG      -18
#define TARGET_GEN_SUBRNG1     -19
#define TARGET_GEN_SUBRNG2     -20
#define TARGET_GEN_SUBRNG3     -21
#define TARGET_GEN_SUBRNG4     -22
#define TARGET_GEN_SUBRNG5     -23
#define TARGET_GEN_SUBRNG6     -24
#define TARGET_GEN_SUBRNG7     -25

#endif /* TARGET_SIGNAL_H */


text:
class DeleteFilePacket : public Packet {

  protected:
    virtual int dataSize();
    virtual std::ostream& print(std::ostream&) const;

  public:

    char* pathname;

    DeleteFilePacket(void* buf, ssize_t size);
    DeleteFilePacket(char* pathname);

    friend std::ostream& operator<<(std::ostream& stream, const DeleteFilePacket &packet);
};

#endif //  _DELETE_FILE_PACKET_H_


text:
title: Installation
---

### Installation

You can install the Users module with the `addon:install` command:

    php artisan addon:install anomaly.module.users

> The Users module comes installed with PyroCMS out of the box.{.note}


text:
> PDF merging utility.

- Merge 2 PDFs into a single PDF:

`pdfunite {{path/to/fileA.pdf}} {{path/to/fileB.pdf}} {{path/to/merged_output.pdf}}`

- Merge a folder of PDFs into a single PDF:

`pdfunite {{path/to/directory/*.pdf}} {{path/to/merged_output.pdf}}`


text:
<?php

namespace FOQ\ElasticaBundle\Tests\Doctrine;

use FOQ\ElasticaBundle\Doctrine\RepositoryManager;

class CustomRepository{}

class Entity{}

/**
 * @author Richard Miller <info@limethinking.co.uk>
 */
class RepositoryManagerTest extends \PHPUnit_Framework_TestCase
{
    public function setUp()
    {
       if (!interface_exists('Doctrine\Common\Persistence\ManagerRegistry')) {
           $this->markTestSkipped('Doctrine Common is not available.');
       }
    }

    public function testThatGetRepositoryReturnsDefaultRepository()
    {
        $finderMock = $this->getMockBuilder('FOQ\ElasticaBundle\Finder\TransformedFinder')
            ->disableOriginalConstructor()
            ->getMock();

        $registryMock = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry')
            ->disableOriginalConstructor()
            ->getMock();

        $readerMock = $this->getMockBuilder('Doctrine\Common\Annotations\Reader')
            ->disableOriginalConstructor()
            ->getMock();

        $entityName = 'FOQ\ElasticaBundle\Tests\Manager\Entity';

        $manager = new RepositoryManager($registryMock, $readerMock);
        $manager->addEntity($entityName, $finderMock);
        $repository = $manager->getRepository($entityName);
        $this->assertInstanceOf('FOQ\ElasticaBundle\Repository', $repository);
    }

    public function testThatGetRepositoryReturnsCustomRepository()
    {
        $finderMock = $this->getMockBuilder('FOQ\ElasticaBundle\Finder\TransformedFinder')
            ->disableOriginalConstructor()
            ->getMock();

        $registryMock = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry')
            ->disableOriginalConstructor()
            ->getMock();

        $readerMock = $this->getMockBuilder('Doctrine\Common\Annotations\Reader')
            ->disableOriginalConstructor()
            ->getMock();

        $entityName = 'FOQ\ElasticaBundle\Tests\Manager\Entity';

        $manager = new RepositoryManager($registryMock, $readerMock);
        $manager->addEntity($entityName, $finderMock, 'FOQ\ElasticaBundle\Tests\Manager\CustomRepository');
        $repository = $manager->getRepository($entityName);
        $this->assertInstanceOf('FOQ\ElasticaBundle\Tests\Manager\CustomRepository', $repository);
    }

    /**
     * @expectedException RuntimeException
     */
    public function testThatGetRepositoryThrowsExceptionIfEntityNotConfigured()
    {
        $finderMock = $this->getMockBuilder('FOQ\ElasticaBundle\Finder\TransformedFinder')
            ->disableOriginalConstructor()
            ->getMock();

        $registryMock = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry')
            ->disableOriginalConstructor()
            ->getMock();

        $readerMock = $this->getMockBuilder('Doctrine\Common\Annotations\Reader')
            ->disableOriginalConstructor()
            ->getMock();

        $entityName = 'FOQ\ElasticaBundle\Tests\Manager\Entity';

        $manager = new RepositoryManager($registryMock, $readerMock);
        $manager->addEntity($entityName, $finderMock);
        $manager->getRepository('Missing Entity');
    }

    /**
     * @expectedException RuntimeException
     */
    public function testThatGetRepositoryThrowsExceptionIfCustomRepositoryNotFound()
    {
        $finderMock = $this->getMockBuilder('FOQ\ElasticaBundle\Finder\TransformedFinder')
            ->disableOriginalConstructor()
            ->getMock();

        $registryMock = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry')
            ->disableOriginalConstructor()
            ->getMock();

        $readerMock = $this->getMockBuilder('Doctrine\Common\Annotations\Reader')
            ->disableOriginalConstructor()
            ->getMock();

        $entityName = 'FOQ\ElasticaBundle\Tests\Manager\Entity';

        $manager = new RepositoryManager($registryMock, $readerMock);
        $manager->addEntity($entityName, $finderMock, 'FOQ\ElasticaBundle\Tests\MissingRepository');
        $manager->getRepository('Missing Entity');
    }

    public function testThatGetRepositoryWorksWithShortEntityName()
    {
        $finderMock = $this->getMockBuilder('FOQ\ElasticaBundle\Finder\TransformedFinder')
            ->disableOriginalConstructor()
            ->getMock();

        $registryMock = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry')
            ->disableOriginalConstructor()
            ->getMock();

        $readerMock = $this->getMockBuilder('Doctrine\Common\Annotations\Reader')
            ->disableOriginalConstructor()
            ->getMock();

        $shortEntityName = 'TestBundle:Entity';
        $entityName = 'FOQ\ElasticaBundle\Tests\Manager\Entity';
        $shortPath = 'TestBundle';
        $fullPath = 'FOQ\ElasticaBundle\Tests\Manager';

        $registryMock->expects($this->once())
            ->method('getAliasNamespace')
            ->with($this->equalTo($shortPath))
            ->will($this->returnValue($fullPath));

        $manager = new RepositoryManager($registryMock, $readerMock);
        $manager->addEntity($entityName, $finderMock);
        $repository = $manager->getRepository($shortEntityName);
        $this->assertInstanceOf('FOQ\ElasticaBundle\Repository', $repository);
    }

}


text:
package org.codehaus.plexus.archiver.gzip;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.zip.GZIPInputStream;

import org.codehaus.plexus.components.io.attributes.Java7FileAttributes;
import org.codehaus.plexus.components.io.attributes.PlexusIoResourceAttributes;
import org.codehaus.plexus.components.io.resources.PlexusIoCompressedFileResourceCollection;
import org.codehaus.plexus.util.IOUtil;

import javax.annotation.Nonnull;

/**
 * Abstract base class for compressed files, aka singleton
 * resource collections.
 */
public class PlexusIoGzipResourceCollection
    extends PlexusIoCompressedFileResourceCollection
{
    protected String getDefaultExtension()
    {
        return ".gz";
    }

    @Nonnull
    protected InputStream getInputStream( File file )
        throws IOException
    {
        InputStream fis = new FileInputStream( file );
        try
        {
            InputStream result = new GZIPInputStream( fis );
            fis = null;
            return result;
        }
        finally
        {
            IOUtil.close( fis );
        }
    }

	@Override protected PlexusIoResourceAttributes getAttributes(File file) throws IOException {
        return new Java7FileAttributes(file, new HashMap<Integer, String>(), new HashMap<Integer, String>());
	}
}


text:
'use strict';
/**
 * Created by Alex Levshin on 14/9/16.
 */
var mongoose = require('mongoose');
var Schema = mongoose.Schema;

// initial
// waiting
// running
// completed
var WorktyInstanceStateSchema = new Schema({
    name: {type: String, required: true},
    __v: {type: String, select: false}
});

WorktyInstanceStateSchema.statics.findByName = function (name) {
    return _worktyInstanceStates[name.toLowerCase()];
};

WorktyInstanceStateSchema.statics.getAll = function (cb) {
    if (!cb) {
        return this.find({}).exec();
    }

    this.find({}, function _onWorktyInstanceStatesReturned(err, worktyInstanceStates) {
        if (err) {
            cb(err);
        } else {
            if (!worktyInstanceStates) {
                cb(null, []);
            } else {
                // TODO: update private variable
                cb(null, worktyInstanceStates);
            }
        }
    });
};

var WorktyInstanceState = global.db.model('workty_instance_states', WorktyInstanceStateSchema);

// Cache objects
var _stream = WorktyInstanceState.find({}).stream();
var _worktyInstanceStates = {};
_stream.on('data', function(worktyInstanceState) {
    _worktyInstanceStates[worktyInstanceState.name] = worktyInstanceState;
}).on('error', function(err) {
    // Error handling
}).on('close', function(worktyInstanceState) {
    // All done, results object is ready
    //console.log(_worktyInstanceStates);
});

module.exports.schema = WorktyInstanceStateSchema;
module.exports.defaultModel = WorktyInstanceState;
module.exports.collectionName = 'workty_instance_states';


text:
package evaluation.evalBench.task;

import java.util.ArrayList;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

/**
 * This class represents a collection of tasks (a wrapper of ArrayList for JAXB unmarshalling)
 */
@XmlRootElement
@XmlType(name="taskListType")
public class TaskList {
    private ArrayList<Task> m_tasks = new ArrayList<Task>();

    @XmlElement(name = "task", required=true)
    public ArrayList<Task> getTasks() {

		return m_tasks;
	}

}


text:
using System;
using System.IO;
using System.Linq;
using NUnit.Framework;
using Hyena;

namespace Hyena.Tests
{
    [TestFixture]
    public class StringUtilTests
    {
        private class Map
        {
            public Map (string camel, string under)
            {
                Camel = camel;
                Under = under;
            }

            public string Camel;
            public string Under;
        }

        private Map [] u_to_c_maps = new Map [] {
            new Map ("Hello", "hello"),
            new Map ("HelloWorld", "hello_world"),
            new Map ("HelloWorld", "hello__world"),
            new Map ("HelloWorld", "hello___world"),
            new Map ("HelloWorld", "hello____world"),
            new Map ("HelloWorld", "_hello_world"),
            new Map ("HelloWorld", "__hello__world"),
            new Map ("HelloWorld", "___hello_world_"),
            new Map ("HelloWorldHowAreYou", "_hello_World_HOW_ARE__YOU__"),
            new Map (null, ""),
            new Map ("H", "h")
        };

        [Test]
        public void UnderCaseToCamelCase ()
        {
            foreach (Map map in u_to_c_maps) {
                Assert.AreEqual (map.Camel, StringUtil.UnderCaseToCamelCase (map.Under));
            }
        }

        private Map [] c_to_u_maps = new Map [] {
            new Map ("Hello", "hello"),
            new Map ("HelloWorld", "hello_world"),
            new Map ("HiWorldHowAreYouDoingToday", "hi_world_how_are_you_doing_today"),
            new Map ("SRSLYHowAreYou", "srsly_how_are_you"),
            new Map ("OMGThisShitIsBananas", "omg_this_shit_is_bananas"),
            new Map ("KTHXBAI", "kthxbai"),
            new Map ("nereid.track_view_columns.MusicLibrarySource-Library/composer", "nereid.track_view_columns._music_library_source_-_library/composer"),
            new Map ("", null),
            new Map ("H", "h")
        };

        [Test]
        public void CamelCaseToUnderCase ()
        {
            foreach (Map map in c_to_u_maps) {
                Assert.AreEqual (map.Under, StringUtil.CamelCaseToUnderCase (map.Camel));
            }
        }

        [Test]
        public void DoubleToTenthsPrecision ()
        {
            // Note we are testing with locale = it_IT, hence the commas
            Assert.AreEqual ("15",      StringUtil.DoubleToTenthsPrecision (15.0));
            Assert.AreEqual ("15",      StringUtil.DoubleToTenthsPrecision (15.0334));
            Assert.AreEqual ("15,1",    StringUtil.DoubleToTenthsPrecision (15.052));
            Assert.AreEqual ("15,5",    StringUtil.DoubleToTenthsPrecision (15.5234));
            Assert.AreEqual ("15",      StringUtil.DoubleToTenthsPrecision (14.9734));
            Assert.AreEqual ("14,9",    StringUtil.DoubleToTenthsPrecision (14.92));
            Assert.AreEqual ("0,4",     StringUtil.DoubleToTenthsPrecision (0.421));
            Assert.AreEqual ("0",       StringUtil.DoubleToTenthsPrecision (0.01));
            Assert.AreEqual ("1.000,3", StringUtil.DoubleToTenthsPrecision (1000.32));
            Assert.AreEqual ("9.233",   StringUtil.DoubleToTenthsPrecision (9233));
        }

        [Test]
        public void DoubleToPluralInt ()
        {
            // This method helps us pluralize doubles. Probably a horrible i18n idea.
            Assert.AreEqual (0,     StringUtil.DoubleToPluralInt (0));
            Assert.AreEqual (1,     StringUtil.DoubleToPluralInt (1));
            Assert.AreEqual (2,     StringUtil.DoubleToPluralInt (2));
            Assert.AreEqual (1,     StringUtil.DoubleToPluralInt (0.5));
            Assert.AreEqual (2,     StringUtil.DoubleToPluralInt (1.8));
            Assert.AreEqual (22,    StringUtil.DoubleToPluralInt (21.3));
        }

        [Test]
        public void RemovesNewlines ()
        {
            Assert.AreEqual ("", StringUtil.RemoveNewlines (""));
            Assert.AreEqual (null, StringUtil.RemoveNewlines (null));
            Assert.AreEqual ("foobar", StringUtil.RemoveNewlines (@"foo
bar"));
            Assert.AreEqual ("foobar baz", StringUtil.RemoveNewlines ("foo\nbar \nbaz"));
            Assert.AreEqual ("haswindows newline andunix", StringUtil.RemoveNewlines ("has\nwindows\r\n newline \nandunix"));
        }

        [Test]
        public void RemovesHtml ()
        {
            Assert.AreEqual ("", StringUtil.RemoveHtml (""));
            Assert.AreEqual (null, StringUtil.RemoveHtml (null));
            Assert.AreEqual ("foobar", StringUtil.RemoveHtml ("foobar"));
            Assert.AreEqual ("foobar", StringUtil.RemoveHtml ("foo<baz>bar"));
            Assert.AreEqual ("foobar", StringUtil.RemoveHtml ("foo<baz/>bar"));
            Assert.AreEqual ("foobar", StringUtil.RemoveHtml ("foo</baz>bar"));
            Assert.AreEqual ("foobazbar", StringUtil.RemoveHtml ("foobazbar"));
            Assert.AreEqual ("foobaz foo bar", StringUtil.RemoveHtml (@"foobaz foo bar"));
        }

        [Test]
        public void TestJoin ()
        {
            var s = new string [] { "foo", "bar" };
            Assert.AreEqual ("foo, bar", s.Join (", "));
            Assert.AreEqual ("foobar", s.Join (""));
            Assert.AreEqual ("foobar", s.Join (null));
            Assert.AreEqual ("", new string [] {}.Join (", "));

            s = new string [] { "foo", "bar", "baz" };
            Assert.AreEqual ("foo -- bar -- baz", s.Join (" -- "));
        }

        [Test]
        public void TestSubstringBetween ()
        {
            Assert.AreEqual ("bar", "foobarbaz".SubstringBetween ("foo", "baz"));
            Assert.AreEqual ("barfoobam", "erefoobarfoobambazabc".SubstringBetween ("foo", "baz"));
            Assert.AreEqual (null, "foobar".SubstringBetween ("foo", "baz"));
            Assert.AreEqual (null,  "bar".SubstringBetween ("foo", "baz"));
            Assert.AreEqual (null,  "".SubstringBetween ("foo", "baz"));
        }
    }

    [TestFixture]
    public class SearchKeyTests
    {
        private void AssertSearchKey (string before, string after)
        {
            Assert.AreEqual (after, StringUtil.SearchKey (before));
        }

        [Test]
        public void TestEmpty ()
        {
            AssertSearchKey ("", "");
            AssertSearchKey (null, null);
        }

        // Test that resulting search keys are in lower-case
        [Test]
        public void TestLowercase ()
        {
            AssertSearchKey ("A", "a");
            AssertSearchKey ("\u0104", "a");
        }

        // Test that combining diacritics are removed from Latin characters.
        [Test]
        public void TestRemoveDiacritics ()
        {
            AssertSearchKey ("\u00e9", "e");
            AssertSearchKey ("e\u0301", "e");

            AssertSearchKey ("\u014d", "o");
            AssertSearchKey ("o\u0304", "o");

            AssertSearchKey ("Español", "espanol");
            AssertSearchKey ("30 años de la revolución iraní", "30 anos de la revolucion irani");
            AssertSearchKey ("FRANCÉS", "frances");

            // Polish letters
            AssertSearchKey ("ą", "a");
            AssertSearchKey ("Ą", "a");
            AssertSearchKey ("ć", "c");
            AssertSearchKey ("Ć", "c");
            AssertSearchKey ("ę", "e");
            AssertSearchKey ("Ę", "e");
            AssertSearchKey ("ł", "l");
            AssertSearchKey ("Ł", "l");
            AssertSearchKey ("ń", "n");
            AssertSearchKey ("Ń", "n");
            AssertSearchKey ("ó", "o");
            AssertSearchKey ("Ó", "o");
            AssertSearchKey ("ś", "s");
            AssertSearchKey ("Ś", "s");
            AssertSearchKey ("ź", "z");
            AssertSearchKey ("Ź", "z");
            AssertSearchKey ("ż", "z");
            AssertSearchKey ("Ż", "z");

            // Hiragana
            AssertSearchKey ("\u304c", "\u304b");

            // Cyrillic
            AssertSearchKey ("\u0451", "\u0435");
            AssertSearchKey ("\u0401", "\u0435");
            AssertSearchKey ("\u0439", "\u0438");
            AssertSearchKey ("\u0419", "\u0438");
        }

        // Test that some non-Latin characters are converted to Latin counterparts.
        [Test]
        public void TestEquivalents ()
        {
            AssertSearchKey ("\u00f8", "o");
            AssertSearchKey ("\u0142", "l");
        }

        // Test that some kinds of punctuation are removed.
        [Test]
        public void TestRemovePunctuation ()
        {
            AssertSearchKey ("'", "");
            AssertSearchKey ("\"", "");
            AssertSearchKey ("!", "");
            AssertSearchKey ("?", "");
            AssertSearchKey ("/", "");
        }

        [Test] // http://bugzilla.gnome.org/show_bug.cgi?id=573484
        public void TestCollapseSpaces ()
        {
            AssertSearchKey ("  a  \t  b  ", "a b");
            AssertSearchKey ("100 % techno", "100 techno");

            // Character in the set of special overrides
            AssertSearchKey ("a \u00f8", "a o");

            // Invalid combining character
            AssertSearchKey ("a \u0301", "a");
        }
    }

    [TestFixture]
    public class EscapeFilenameTests
    {
        private void AssertProduces (string input, string output)
        {
            Assert.AreEqual (output, StringUtil.EscapeFilename (input));
        }

        private void AssertProducesSame (string input)
        {
            AssertProduces (input, input);
        }

        [Test]
        public void TestEmpty ()
        {
            AssertProduces (null,   "");
            AssertProduces ("",     "");
            AssertProduces (" ",    "");
            AssertProduces ("   ",  "");
        }

        [Test]
        public void TestNotChanged ()
        {
            AssertProducesSame ("a");
            AssertProducesSame ("aaa");
            AssertProducesSame ("Foo Bar");
            AssertProducesSame ("03-Nur geträumt");
            AssertProducesSame ("你好");
            AssertProducesSame ("nǐ hǎo");
        }

        [Test]
        public void TestStripped ()
        {
            AssertProduces ("Foo*bar", "Foo_bar");
            AssertProduces ("</foo:bar?>", "_foo_bar_");
            AssertProduces ("</:?>", "_");
            AssertProduces ("Greetings! -* 你好?", "Greetings! -_ 你好_");
        }
    }

    [TestFixture]
    public class SortKeyTests
    {
        private void AssertSortKey (string before, object after)
        {
            Assert.AreEqual (after, StringUtil.SortKey (before));
        }

        [Test]
        public void TestNull ()
        {
            AssertSortKey (null, null);
        }

        [Test]
        public void TestEmpty ()
        {
            AssertSortKey ("", new byte[] {1, 1, 1, 1, 0});
        }

        [Test]
        public void TestSortKey ()
        {
            AssertSortKey ("a", new byte[] {14, 2, 1, 1, 1, 1, 0});
            AssertSortKey ("A", new byte[] {14, 2, 1, 1, 1, 1, 0});
            AssertSortKey ("\u0104", new byte[] {14, 2, 1, 27, 1, 1, 1, 0,});
        }
    }

    [TestFixture]
    public class EscapePathTests
    {
        private readonly char dir_sep = Path.DirectorySeparatorChar;

        private void AssertProduces (string input, string output)
        {
            Assert.AreEqual (output, StringUtil.EscapePath (input));
        }

        private void AssertProducesSame (string input)
        {
            AssertProduces (input, input);
        }

        [Test]
        public void TestEmpty ()
        {
            AssertProduces (null,   "");
            AssertProduces ("",     "");
            AssertProduces (" ",    "");
            AssertProduces ("   ",  "");
        }

        [Test]
        public void TestNotChanged ()
        {
            AssertProducesSame ("a");
            AssertProducesSame ("aaa");
            AssertProducesSame ("Foo Bar");
            AssertProducesSame ("03-Nur geträumt");
            AssertProducesSame ("превед");
            AssertProducesSame ("nǐ hǎo");

            AssertProducesSame (String.Format ("a{0}b.ogg", dir_sep));
            AssertProducesSame (String.Format ("foo{0}bar{0}01. baz.ogg", dir_sep));
            AssertProducesSame (String.Format ("{0}foo*?:", dir_sep)); // rooted, shouldn't change
        }

        [Test]
        public void TestStripped ()
        {
            AssertProduces (
                String.Format ("foo*bar{0}ham:spam.ogg", dir_sep),
                String.Format ("foo_bar{0}ham_spam.ogg", dir_sep));
            AssertProduces (
                String.Format ("..lots..{0}o.f.{0}.dots.ogg.", dir_sep),
                String.Format ("lots{0}o.f{0}dots.ogg", dir_sep));
            AssertProduces (
                String.Format ("foo{0}..{0}bar.ogg", dir_sep),
                String.Format ("foo{0}bar.ogg", dir_sep));
            AssertProduces (
                String.Format (". foo{0}01. bar.ogg. ", dir_sep),
                String.Format ("foo{0}01. bar.ogg", dir_sep));
        }
    }

    [TestFixture]
    public class SubstringCountTests
    {
        private void AssertCount (string haystack, string needle, uint expected)
        {
            Assert.AreEqual (expected, StringUtil.SubstringCount (haystack, needle));
        }

        [Test]
        public void TestEmpty ()
        {
            AssertCount ("", "a", 0);
            AssertCount ("a", "", 0);
        }

        [Test]
        public void TestNoMatches ()
        {
            AssertCount ("a", "b", 0);
            AssertCount ("with needle in", "long needle", 0);
        }

        [Test]
        public void TestMatches ()
        {
            AssertCount ("abbcbba", "a", 2);
            AssertCount ("abbcbba", "b", 4);
            AssertCount ("with needle in", "needle", 1);
        }
    }
}

#endif


text:
#include <atma/hash.hpp>

namespace shiny
{
	enum class blending_t : uint
	{
		zero,
		one,
		src_color,
		one_minus_src_color,
		src_alpha,
		one_minus_src_alpha,
		dest_color,
		one_minus_dest_color,
		dest_alpha,
		one_minus_dest_alpha,
	};

	struct rendertarget_blend_state_t
	{
		bool blending_enabled = true;

		blending_t dest_blend       = blending_t::one_minus_src_alpha;
		blending_t dest_blend_alpha = blending_t::zero;
		blending_t src_blend        = blending_t::src_alpha;
		blending_t src_blend_alpha  = blending_t::zero;
	};

	inline auto operator == (rendertarget_blend_state_t const& lhs, rendertarget_blend_state_t const& rhs) -> bool
	{
		return lhs.blending_enabled == rhs.blending_enabled &&
			lhs.dest_blend == rhs.dest_blend &&
			lhs.dest_blend_alpha == rhs.dest_blend_alpha &&
			lhs.src_blend == rhs.src_blend &&
			lhs.src_blend_alpha == rhs.src_blend_alpha;
	}

	struct blend_state_t
	{
		blend_state_t(blending_t dest_blend, blending_t dest_blend_alpha, blending_t src_blend, blending_t src_blend_alpha)
			: multitarget_collapse(true)
		{
			rendertarget[0].blending_enabled = true;
			rendertarget[0].dest_blend = dest_blend;
			rendertarget[0].dest_blend_alpha = dest_blend_alpha;
			rendertarget[0].src_blend = src_blend;
			rendertarget[0].src_blend_alpha = src_blend_alpha;
		}

		static blend_state_t const opaque;

		// all targets use first target's properties
		bool multitarget_collapse;

		rendertarget_blend_state_t rendertarget[8];
	};

	inline auto operator == (blend_state_t const& lhs, blend_state_t const& rhs) -> bool
	{
		return lhs.multitarget_collapse == rhs.multitarget_collapse &&
			lhs.rendertarget[0] == rhs.rendertarget[0] &&
			lhs.rendertarget[1] == rhs.rendertarget[1] &&
			lhs.rendertarget[2] == rhs.rendertarget[2] &&
			lhs.rendertarget[3] == rhs.rendertarget[3] &&
			lhs.rendertarget[4] == rhs.rendertarget[4] &&
			lhs.rendertarget[5] == rhs.rendertarget[5] &&
			lhs.rendertarget[6] == rhs.rendertarget[6] &&
			lhs.rendertarget[7] == rhs.rendertarget[7];
	}
}

namespace atma
{
	template <>
	struct hash_t<shiny::blend_state_t>
	{
		auto operator()(hasher_t& hsh, shiny::blend_state_t const& x) const -> void
		{
			hsh(x.multitarget_collapse);

			hsh(x.rendertarget[0]);
			hsh(x.rendertarget[1]);
			hsh(x.rendertarget[2]);
			hsh(x.rendertarget[3]);
			hsh(x.rendertarget[4]);
			hsh(x.rendertarget[5]);
			hsh(x.rendertarget[6]);
			hsh(x.rendertarget[7]);
		}
	};
}


text:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Python"
        android:id="@+id/textView2"
        android:textColor="@android:color/white"
        android:singleLine="true"
        android:textSize="80sp"
        android:layout_alignParentTop="true"
        android:gravity="center"/>

    <ScrollView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/scrollView"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:layout_alignParentBottom="true"
        android:layout_below="@+id/textView2">

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingTop="40sp"
            android:padding="10dp">

            <LinearLayout
                android:orientation="horizontal"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:onClick="onPythonInterpreterButtonClick"
                android:id="@+id/main_menu_interpreter_button_container">

                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:src="@drawable/python_icon"
                    android:adjustViewBounds="true"
                    android:layout_weight="0.8"
                    android:scaleType="fitCenter"
                    android:contentDescription="@string/content_description_python_icon"/>

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="@string/main_menu_python_interpreter_link"
                    android:layout_weight="0.2"
                    android:paddingLeft="20sp"
                    android:textColor="@android:color/white"
                    android:textSize="30sp"
                    android:paddingTop="10sp"
                    android:paddingBottom="10sp"/>
            </LinearLayout>

            <LinearLayout
                android:orientation="horizontal"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:onClick="onDownloadVersionsButtonClick">

                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:src="@android:drawable/ic_menu_upload"
                    android:adjustViewBounds="true"
                    android:layout_weight="0.8"
                    android:contentDescription="@string/content_description_download_manager_icon"/>

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="@string/main_menu_download_manager_link"
                    android:layout_weight="0.2"
                    android:paddingLeft="20sp"
                    android:textColor="@android:color/white"
                    android:textSize="30sp"
                    android:paddingTop="10sp"
                    android:paddingBottom="10sp"/>
            </LinearLayout>

            <LinearLayout
                android:orientation="horizontal"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:src="@android:drawable/ic_dialog_info"
                    android:adjustViewBounds="true"
                    android:layout_weight="0.8"
                    android:contentDescription="@string/content_description_about_icon"/>

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="@string/main_menu_about_link"
                    android:layout_weight="0.2"
                    android:paddingLeft="20sp"
                    android:textColor="@android:color/white"
                    android:textSize="30sp"
                    android:paddingTop="10sp"
                    android:paddingBottom="10sp"/>
            </LinearLayout>

            <LinearLayout
                android:orientation="horizontal"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:src="@android:drawable/ic_menu_help"
                    android:adjustViewBounds="true"
                    android:layout_weight="0.8"
                    android:contentDescription="@string/content_description_help_icon"/>

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="@string/main_menu_help_link"
                    android:layout_weight="0.2"
                    android:paddingLeft="20sp"
                    android:textColor="@android:color/white"
                    android:textSize="30sp"
                    android:paddingTop="10sp"
                    android:paddingBottom="10sp"/>
            </LinearLayout>

            <LinearLayout
                android:orientation="horizontal"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:clickable="true"
                android:onClick="onSettingsButtonClick">

                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:src="@android:drawable/ic_menu_manage"
                    android:adjustViewBounds="true"
                    android:layout_weight="0.8"
                    android:contentDescription="@string/content_description_settings_icon"/>

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="@string/main_menu_settings_link"
                    android:layout_weight="0.2"
                    android:paddingLeft="20sp"
                    android:textColor="@android:color/white"
                    android:textSize="30sp"
                    android:paddingTop="10sp"
                    android:paddingBottom="10sp"/>
            </LinearLayout>

        </LinearLayout>
    </ScrollView>
</RelativeLayout>


text:
define(["require", "exports"], function (require, exports) {
    function MapperNotAvailableError(name) {
        return new Error("Mapper named " + name + " is not resolved yet");
    }
    exports.default = MapperNotAvailableError;
});


text:
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace HIO.Backup.Interfaces
{
    public interface IDirectoryPathFilter
    {
        bool IsAllowed(string path);
    }
}


text:
ACCEPTED

#### According to
The Catalogue of Life, 3rd January 2011

#### Published in
Docums Mycol. 21(no. 81): 24 (1991)

#### Original name
Boletus umbrinoides J. Blum, 1970

### Remarks
null


text:
(function(module) {
  'use strict';

  CurrentUser.all = {};

  function CurrentUser(ops) {
    Object.keys(ops).forEach(function(e, index, keys) {
      this[e] = ops[e];
    },this);
  }
  //pulls data from Firebase if the user has an id
  CurrentUser.pullData = function(userId) {
    var userInfo = new Firebase('https://blinding-fire-6623.firebaseio.com/web/data/' + userId);
    userInfo.on('value', function(snapshot){
      if(snapshot.val()){
        $('.emergency-contact-plan').remove();
        CurrentUser.all = new CurrentUser(snapshot.val());
        $('#homepage-plan').append(home.render(CurrentUser.all, '#final-emergency-plan-form-template'));
        if (CurrentUser.all.lovedOnes) {
          CurrentUser.all.lovedOnes.forEach(function(a) {$('#homepage-plan').append(home.render(a, '#final-emergency-plan-lovedones-template'));
          });
        }
        $('#homepage-plan').append(home.render(CurrentUser.all, '#final-emergency-plan-rally-template'));
        if (CurrentUser.all.userKit){
          $('#homepage-plan').append(home.render(CurrentUser.all, '#final-emergency-plan-userkit-template'));
        };
        localStorage.setItem('CurrentUser', JSON.stringify(CurrentUser.all));
      }
      else{
        console.log('No existing data');
      }
    }, function(error){
      console.log('Read failed', error);
    });

  };
  //Saves data to Firebase, will overwrite any existing data for the specific user.
  CurrentUser.saveData = function(userId) {
    var userInfo = new Firebase('https://blinding-fire-6623.firebaseio.com/web/data/');
    var storeData = userInfo.child(userId);
    storeData.set(CurrentUser.all);
  };
  //erases the data in firebase for the specific user
  CurrentUser.eraseData = function(userId) {
    if(userId){
      var userData = new Firebase('https://blinding-fire-6623.firebaseio.com/web/data/' + userId);
      userData.remove();
    }
  };

  module.CurrentUser = CurrentUser;
}(window));


text:
#import "NSObject.h"

@class NSString;

@interface FauxUIElement : NSObject
{
    NSString *_role;
    NSString *_identifier;
    id _parent;
}

+ (id)elementWithRole:(id)arg1 parent:(id)arg2 identifier:(id)arg3;
- (id)accessibilityFocusedUIElement;
- (id)accessibilityHitTest:(struct CGPoint)arg1;
- (BOOL)accessibilityIsIgnored;
- (void)accessibilityPerformAction:(id)arg1;
- (id)accessibilityActionDescription:(id)arg1;
- (id)accessibilityActionNames;
- (void)accessibilitySetValue:(id)arg1 forAttribute:(id)arg2;
- (BOOL)accessibilityIsAttributeSettable:(id)arg1;
- (id)accessibilityAttributeValue:(id)arg1;
- (id)accessibilityAttributeNames;
- (id)identifier;
- (unsigned long long)hash;
- (BOOL)isEqual:(id)arg1;
- (void)dealloc;
- (id)initWithRole:(id)arg1 parent:(id)arg2 identifier:(id)arg3;

@end


text:
layout: post
sections: [TALEND]
title:  "Talend Introducción"
date:   2016-10-25
desc: "Herramienta ETL para la migración e integración de datos"
keywords: "Talend,Talend Open Studio, Introducción, Integration"
categories: [talend]
tags: [Talend,TalendOpenStudio]
icon: fas fa-exchange-alt
image: static/img/blog/talend/talend-logo.png
---

# ETL con Talend #

Extract, Transform and Load («extraer, transformar y cargar», frecuentemente abreviado ETL) es el proceso que permite a las organizaciones mover datos desde múltiples fuentes, reformatearlos y limpiarlos, y cargarlos en otra base de datos, data mart, o data warehouse para analizar, o en otro sistema operacional para apoyar un proceso de negocio. Los procesos ETL también se pueden utilizar para la integración con sistemas heredados.

## ¿Qué puedo hacer con Talend? ##

* ETL.
* Sincronización o replicación de bases de datos.
* Migración.
* Transformación de datos.

## ¿Qué ventajas te ofrece trabajar con Talend? ##

* Desarrollo gráfico basado en diagramas de flujo: Esto te permite documentar a la vez que desarrollas.

* Escribir código reutilizable y fiable: Grupos de contexto, repositorio de código de rutinas, componentes personalizados y otros objetos del repositorio.
* Modularidad del trabajo.Se puede cojer una gran tarea y descomponerla en varios trabajos más pequeños que pueden ser orquestados por un maestro.
* Control de errores: Es posible, por ejemplo, referirse a un Objeto null y recibir un NullPointerException. Podemos detectar esta excepción y tratarla, en vez de terminar inmediatamente, ya que esto puede no ser el resultado deseado.
Una tarea puede llamar a un servicio web que no está disponible y recibir un 503 (Servicio no disponible). Esto no va a ser fatal para Talend, pero, de nuevo, es posible que desee tratar con esto de una manera especial y no lanzar una excepción; por ejemplo, es posible que desee volver a intentar la solicitud en un momento posterior.
* Reinicio y recuperación: Al poder manejar los errores, usted está en una posición mucho mejor para hacer frente a su tarea en caso de que reciba un error fatal: Puede su tarea simplemente reiniciarse desde el principio? ¿Es eso posible? ¿O hay que reiniciar el trabajo en un punto de fallo lógico?
* Robustez: Una vez que la arquitectura de su job está lista, los errores se pueden controlar y hay capacidad de recuperación.
* Rendimiento (por lo general significa la velocidad de ejecución) es a menudo un indicador clave de un éxito o el fracaso de una tarea. Hay muchos aspectos a la sintonización de su tarea, incluyendo: diseño de trabajo general, la gestión de memoria, I / O, compartir la carga con entradas y salidas (por ejemplo, bases de datos) y el paralelismo. También hay factores que pueden no estar bajo el control directo del desarrollador Talend, como el rendimiento de la red y la configuración de fuentes externas y ends points. Todos ellos deben ser tomados en consideración.
* Logging: Por último, es una buena práctica registrar información sobre la ejecución de su trabajo, a través del tiempo. Esto ayuda con la optimización del rendimiento y resolución de problemas.

## Talend Open Studio Data Integration ##

Es una herramienta open-source (licencia GPL) que permite de forma visual modelar transformaciones de datos generando código Java. Ofrece un diseñador visual (basado en Eclipse RCP) que permite definir todo el flujo de transformaciones en base a componentes predefinidos (más de 400, también se pueden crear y ampliar).

Este diseñador proporciona una vista gráfica de los procesos, con componentes arrastrables que permiten: mappings, transformaciones, etc; funciones especializadas como data filtering, data multiplexing, o ELT; y soporte para RDBMS, file formats, LDAP directories, etc.

Podéis descargar Talend Open Studio desde [aquí](https://www.talend.com/download/talend-open-studio#t4 "Talend Open Studio Data Integration").

## Referencias ##

[https://www.talend.com/](https://www.talend.com/ "https://www.talend.com/")


text:
/** @type {import("../../../../").Configuration} */
module.exports = {
	mode: "production",
	cache: true,
	output: {
		chunkFilename: "[contenthash].js"
	}
};


text:
package org.powermock.api.mockito.repackaged.cglib.core;

import org.powermock.api.mockito.repackaged.asm.ClassVisitor;

public interface ClassGenerator {
    void generateClass(ClassVisitor v) throws Exception;
}


text:
require 'faraday' # HTTP Client
require 'faraday-cookie_jar'
require 'faraday_middleware'
require 'fastlane/version'
require 'logger'
require 'spaceship/babosa_fix'
require 'spaceship/helper/net_http_generic_request'
require 'spaceship/helper/plist_middleware'
require 'spaceship/ui'
require 'tmpdir'
require 'cgi'

Faraday::Utils.default_params_encoder = Faraday::FlatParamsEncoder

if ENV["SPACESHIP_DEBUG"]
  require 'openssl'
  # this has to be on top of this file, since the value can't be changed later
  OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
end

module Spaceship
  class Client
    PROTOCOL_VERSION = "QH65B2"
    USER_AGENT = "Spaceship #{Fastlane::VERSION}"

    attr_reader :client

    # The user that is currently logged in
    attr_accessor :user

    # The logger in which all requests are logged
    # /tmp/spaceship[time]_[pid].log by default
    attr_accessor :logger

    attr_accessor :csrf_tokens

    # Base class for errors that want to present their message as
    # preferred error info for fastlane error handling. See:
    # fastlane_core/lib/fastlane_core/ui/fastlane_runner.rb
    class BasicPreferredInfoError < StandardError
      TITLE = 'The request could not be completed because:'.freeze

      def preferred_error_info
        message ? [TITLE, message] : nil
      end
    end

    # Invalid user credentials were provided
    class InvalidUserCredentialsError < BasicPreferredInfoError; end

    # Raised when no user credentials were passed at all
    class NoUserCredentialsError < BasicPreferredInfoError; end

    # User doesn't have enough permission for given action
    class InsufficientPermissions < BasicPreferredInfoError
      TITLE = 'Insufficient permissions for your Apple ID:'.freeze

      def preferred_error_info
        message ? [TITLE, message] : nil
      end

      # We don't want to show similar GitHub issues, as the error message
      # should be pretty clear
      def show_github_issues
        false
      end
    end

    class UnexpectedResponse < StandardError
      attr_reader :error_info

      def initialize(error_info = nil)
        super(error_info)
        @error_info = error_info
      end

      def preferred_error_info
        return nil unless @error_info.kind_of?(Hash) && @error_info['resultString']

        [
          "Apple provided the following error info:",
          @error_info['resultString'],
          @error_info['userString']
        ].compact.uniq # sometimes 'resultString' and 'userString' are the same value
      end
    end

    # Raised when 302 is received from portal request
    class AppleTimeoutError < BasicPreferredInfoError; end

    # Raised when 401 is received from portal request
    class UnauthorizedAccessError < BasicPreferredInfoError; end

    # Authenticates with Apple's web services. This method has to be called once
    # to generate a valid session. The session will automatically be used from then
    # on.
    #
    # This method will automatically use the username from the Appfile (if available)
    # and fetch the password from the Keychain (if available)
    #
    # @param user (String) (optional): The username (usually the email address)
    # @param password (String) (optional): The password
    #
    # @raise InvalidUserCredentialsError: raised if authentication failed
    #
    # @return (Spaceship::Client) The client the login method was called for
    def self.login(user = nil, password = nil)
      instance = self.new
      if instance.login(user, password)
        instance
      else
        raise InvalidUserCredentialsError.new, "Invalid User Credentials"
      end
    end

    def self.hostname
      raise "You must implemented self.hostname"
    end

    def initialize
      options = {
       request: {
          timeout:       (ENV["SPACESHIP_TIMEOUT"] || 300).to_i,
          open_timeout:  (ENV["SPACESHIP_TIMEOUT"] || 300).to_i
        }
      }
      @cookie = HTTP::CookieJar.new
      @client = Faraday.new(self.class.hostname, options) do |c|
        c.response :json, content_type: /\bjson$/
        c.response :xml, content_type: /\bxml$/
        c.response :plist, content_type: /\bplist$/
        c.use :cookie_jar, jar: @cookie
        c.adapter Faraday.default_adapter

        if ENV['SPACESHIP_DEBUG']
          # for debugging only
          # This enables tracking of networking requests using Charles Web Proxy
          c.proxy "https://127.0.0.1:8888"
        end

        if ENV["DEBUG"]
          puts "To run _spaceship_ through a local proxy, use SPACESHIP_DEBUG"
        end
      end
    end

    # The logger in which all requests are logged
    # /tmp/spaceship[time]_[pid].log by default
    def logger
      unless @logger
        if ENV["VERBOSE"]
          @logger = Logger.new(STDOUT)
        else
          # Log to file by default
          path = "/tmp/spaceship#{Time.now.to_i}_#{Process.pid}.log"
          @logger = Logger.new(path)
        end

        @logger.formatter = proc do |severity, datetime, progname, msg|
          "[#{datetime.strftime('%H:%M:%S')}]: #{msg}\n"
        end
      end

      @logger
    end

    ##
    # Return the session cookie.
    #
    # @return (String) the cookie-string in the RFC6265 format: https://tools.ietf.org/html/rfc6265#section-4.2.1
    def cookie
      @cookie.map(&:to_s).join(';')
    end

    def store_cookie(path: nil)
      path ||= persistent_cookie_path
      FileUtils.mkdir_p(File.expand_path("..", path))

      # really important to specify the session to true
      # otherwise myacinfo and more won't be stored
      @cookie.save(path, :yaml, session: true)
      return File.read(path)
    end

    # This is a duplicate method of fastlane_core/fastlane_core.rb#fastlane_user_dir
    def fastlane_user_dir
      path = File.expand_path(File.join("~", ".fastlane"))
      FileUtils.mkdir_p(path) unless File.directory?(path)
      return path
    end

    # Returns preferred path for storing cookie
    # for two step verification.
    def persistent_cookie_path
      if ENV["SPACESHIP_COOKIE_PATH"]
        path = File.expand_path(File.join(ENV["SPACESHIP_COOKIE_PATH"], "spaceship", self.user, "cookie"))
      else
        [File.join(self.fastlane_user_dir, "spaceship"), "~/.spaceship", "/var/tmp/spaceship", "#{Dir.tmpdir}/spaceship"].each do |dir|
          dir_parts = File.split(dir)
          if directory_accessible?(File.expand_path(dir_parts.first))
            path = File.expand_path(File.join(dir, self.user, "cookie"))
            break
          end
        end
      end

      return path
    end

    #####################################################
    # @!group Automatic Paging
    #####################################################

    # The page size we want to request, defaults to 500
    def page_size
      @page_size ||= 500
    end

    # Handles the paging for you... for free
    # Just pass a block and use the parameter as page number
    def paging
      page = 0
      results = []
      loop do
        page += 1
        current = yield(page)

        results += current

        break if (current || []).count < page_size # no more results
      end

      return results
    end

    #####################################################
    # @!group Login and Team Selection
    #####################################################

    # Authenticates with Apple's web services. This method has to be called once
    # to generate a valid session. The session will automatically be used from then
    # on.
    #
    # This method will automatically use the username from the Appfile (if available)
    # and fetch the password from the Keychain (if available)
    #
    # @param user (String) (optional): The username (usually the email address)
    # @param password (String) (optional): The password
    #
    # @raise InvalidUserCredentialsError: raised if authentication failed
    #
    # @return (Spaceship::Client) The client the login method was called for
    def login(user = nil, password = nil)
      if user.to_s.empty? or password.to_s.empty?
        require 'credentials_manager'

        keychain_entry = CredentialsManager::AccountManager.new(user: user, password: password)
        user ||= keychain_entry.user
        password = keychain_entry.password
      end

      if user.to_s.strip.empty? or password.to_s.strip.empty?
        raise NoUserCredentialsError.new, "No login data provided"
      end

      self.user = user
      @password = password
      begin
        do_login(user, password)
      rescue InvalidUserCredentialsError => ex
        raise ex unless keychain_entry

        if keychain_entry.invalid_credentials
          login(user)
        else
          puts "Please run this tool again to apply the new password"
        end
      end
    end

    # This method is used for both the Apple Dev Portal and iTunes Connect
    # This will also handle 2 step verification
    def send_shared_login_request(user, password)
      # First we see if we have a stored cookie for 2 step enabled accounts
      # this is needed as it stores the information on if this computer is a
      # trusted one. In general I think spaceship clients should be trusted
      load_session_from_file
      # If this is a CI, the user can pass the session via environment variable
      load_session_from_env

      data = {
        accountName: user,
        password: password,
        rememberMe: true
      }

      begin
        # The below workaround is only needed for 2 step verified machines
        # Due to escaping of cookie values we have a little workaround here
        # By default the cookie jar would generate the following header
        #   DES5c148...=HSARM.......xaA/O69Ws/CHfQ==SRVT
        # However we need the following
        #   DES5c148...="HSARM.......xaA/O69Ws/CHfQ==SRVT"
        # There is no way to get the cookie jar value with " around the value
        # so we manually modify the cookie (only this one) to be properly escaped
        # Afterwards we pass this value manually as a header
        # It's not enough to just modify @cookie, it needs to be done after self.cookie
        # as a string operation
        important_cookie = @cookie.store.entries.find { |a| a.name.include?("DES") }
        if important_cookie
          modified_cookie = self.cookie # returns a string of all cookies
          unescaped_important_cookie = "#{important_cookie.name}=#{important_cookie.value}"
          escaped_important_cookie = "#{important_cookie.name}=\"#{important_cookie.value}\""
          modified_cookie.gsub!(unescaped_important_cookie, escaped_important_cookie)
        end

        response = request(:post) do |req|
          req.url "https://idmsa.apple.com/appleauth/auth/signin?widgetKey=#{itc_service_key}"
          req.body = data.to_json
          req.headers['Content-Type'] = 'application/json'
          req.headers['X-Requested-With'] = 'XMLHttpRequest'
          req.headers['Accept'] = 'application/json, text/javascript'
          req.headers["Cookie"] = modified_cookie if modified_cookie
        end
      rescue UnauthorizedAccessError
        raise InvalidUserCredentialsError.new, "Invalid username and password combination. Used '#{user}' as the username."
      end

      # get woinst, wois, and itctx cookie values
      request(:get, "https://itunesconnect.apple.com/WebObjects/iTunesConnect.woa/wa")

      case response.status
      when 403
        raise InvalidUserCredentialsError.new, "Invalid username and password combination. Used '#{user}' as the username."
      when 200
        return response
      else
        location = response["Location"]
        if location && URI.parse(location).path == "/auth" # redirect to 2 step auth page
          handle_two_step(response)
          return true
        elsif (response.body || "").include?('invalid="true"')
          # User Credentials are wrong
          raise InvalidUserCredentialsError.new, "Invalid username and password combination. Used '#{user}' as the username."
        elsif (response['Set-Cookie'] || "").include?("itctx")
          raise "Looks like your Apple ID is not enabled for iTunes Connect, make sure to be able to login online"
        else
          info = [response.body, response['Set-Cookie']]
          raise TunesClient::ITunesConnectError.new, info.join("\n")
        end
      end
    end

    def itc_service_key
      return @service_key if @service_key

      # Check if we have a local cache of the key
      itc_service_key_path = "/tmp/spaceship_itc_service_key.txt"
      return File.read(itc_service_key_path) if File.exist?(itc_service_key_path)

      # Some customers in Asia have had trouble with the CDNs there that cache and serve this content, leading
      # to "buffer error (Zlib::BufError)" from deep in the Ruby HTTP stack. Setting this header requests that
      # the content be served only as plain-text, which seems to work around their problem, while not affecting
      # other clients.
      #
      # https://github.com/fastlane/fastlane/issues/4610
      headers = { 'Accept-Encoding' => 'identity' }
      # We need a service key from a JS file to properly auth
      js = request(:get, "https://itunesconnect.apple.com/itc/static-resources/controllers/login_cntrl.js", nil, headers)
      @service_key = js.body.match(/itcServiceKey = '(.*)'/)[1]

      # Cache the key locally
      File.write(itc_service_key_path, @service_key)

      return @service_key
    rescue => ex
      puts ex.to_s
      raise AppleTimeoutError.new, "Could not receive latest API key from iTunes Connect, this might be a server issue."
    end

    #####################################################
    # @!group Helpers
    #####################################################

    def with_retry(tries = 5, &_block)
      return yield
    rescue Faraday::Error::ConnectionFailed, Faraday::Error::TimeoutError, AppleTimeoutError => ex # New Faraday version: Faraday::TimeoutError => ex
      tries -= 1
      unless tries.zero?
        logger.warn("Timeout received: '#{ex.message}'. Retrying after 3 seconds (remaining: #{tries})...")
        sleep 3 unless defined? SpecHelper
        retry
      end
      raise ex # re-raise the exception
    rescue UnauthorizedAccessError => ex
      if @loggedin && !(tries -= 1).zero?
        msg = "Auth error received: '#{ex.message}'. Login in again then retrying after 3 seconds (remaining: #{tries})..."
        puts msg if $verbose
        logger.warn msg

        if self.class.spaceship_session_env.to_s.length > 0
          raise UnauthorizedAccessError.new, "Authentication error, you passed an invalid session using the environment variable FASTLANE_SESSION or SPACESHIP_SESSION"
        end

        do_login(self.user, @password)
        sleep 3 unless defined? SpecHelper
        retry
      end
      raise ex # re-raise the exception
    end

    # memorize the last csrf tokens from responses
    def csrf_tokens
      @csrf_tokens || {}
    end

    def request(method, url_or_path = nil, params = nil, headers = {}, &block)
      headers.merge!(csrf_tokens)
      headers['User-Agent'] = USER_AGENT

      # Before encoding the parameters, log them
      log_request(method, url_or_path, params)

      # form-encode the params only if there are params, and the block is not supplied.
      # this is so that certain requests can be made using the block for more control
      if method == :post && params && !block_given?
        params, headers = encode_params(params, headers)
      end

      response = send_request(method, url_or_path, params, headers, &block)

      log_response(method, url_or_path, response)

      return response
    end

    def parse_response(response, expected_key = nil)
      if response.body
        # If we have an `expected_key`, select that from response.body Hash
        # Else, don't.

        # the returned error message and info, is html encoded ->  "issued" -> make this readable ->  "issued"
        response.body["userString"] = CGI.unescapeHTML(response.body["userString"]) if response.body["userString"]
        response.body["resultString"] = CGI.unescapeHTML(response.body["resultString"]) if response.body["resultString"]

        content = expected_key ? response.body[expected_key] : response.body
      end
      if content.nil?
        # Check if the failure is due to missing permissions (iTunes Connect)
        if response.body && response.body["messages"] && response.body["messages"]["error"].include?("Forbidden")
          raise_insuffient_permission_error!
        end
        raise UnexpectedResponse, response.body
      elsif content.kind_of?(Hash) && (content["resultString"] || "").include?("NotAllowed")
        # example content when doing a Developer Portal action with not enough permission
        # => {"responseId"=>"e5013d83-c5cb-4ba0-bb62-734a8d56007f",
        #    "resultCode"=>1200,
        #    "resultString"=>"webservice.certificate.downloadNotAllowed",
        #    "userString"=>"You are not permitted to download this certificate.",
        #    "creationTimestamp"=>"2017-01-26T22:44:13Z",
        #    "protocolVersion"=>"QH65B2",
        #    "userLocale"=>"en_US",
        #    "requestUrl"=>"https://developer.apple.com/services-account/QH65B2/account/ios/certificate/downloadCertificateContent.action",
        #    "httpCode"=>200}
        raise_insuffient_permission_error!(additional_error_string: content["userString"])
      else
        store_csrf_tokens(response)
        content
      end
    end

    # This also gets called from subclasses
    def raise_insuffient_permission_error!(additional_error_string: nil)
      # get the method name of the request that failed
      # `block in` is used very often for requests when surrounded for paging or retrying blocks
      # The ! is part of some methods when they modify or delete a resource, so we don't want to show it
      # Using `sub` instead of `delete` as we don't want to allow multiple matches
      calling_method_name = caller_locations(2, 2).first.label.sub("block in", "").delete("!").strip
      begin
        team_id = "(Team ID #{self.team_id}) "
      rescue
        # Showing the team ID is something that's nice to have, however it might cause an exception
        # when the user doesn't have any permission at all (e.g. failing at login)
        # we still want the error message to show the actual string, but without the team_id in that case
        team_id = ""
      end
      error_message = "User #{self.user} #{team_id}doesn't have enough permission for the following action: #{calling_method_name}"
      error_message += " (#{additional_error_string})" if additional_error_string.to_s.length > 0
      raise InsufficientPermissions, error_message
    end

    private

    def directory_accessible?(path)
      Dir.exist?(File.expand_path(path))
    end

    def do_login(user, password)
      @loggedin = false
      ret = send_login_request(user, password) # different in subclasses
      @loggedin = true
      ret
    end

    # Is called from `parse_response` to store the latest csrf_token (if available)
    def store_csrf_tokens(response)
      if response and response.headers
        tokens = response.headers.select { |k, v| %w(csrf csrf_ts).include?(k) }
        if tokens and !tokens.empty?
          @csrf_tokens = tokens
        end
      end
    end

    def log_request(method, url, params)
      params_to_log = Hash(params).dup # to also work with nil
      params_to_log.delete(:accountPassword) # Dev Portal
      params_to_log.delete(:theAccountPW) # iTC
      params_to_log = params_to_log.collect do |key, value|
        "{#{key}: #{value}}"
      end
      logger.info(">> #{method.upcase}: #{url} #{params_to_log.join(', ')}")
    end

    def log_response(method, url, response)
      body = response.body.kind_of?(String) ? response.body.force_encoding(Encoding::UTF_8) : response.body
      logger.debug("<< #{method.upcase}: #{url}: #{body}")
    end

    # Actually sends the request to the remote server
    # Automatically retries the request up to 3 times if something goes wrong
    def send_request(method, url_or_path, params, headers, &block)
      with_retry do
        response = @client.send(method, url_or_path, params, headers, &block)
        resp_hash = response.to_hash
        if resp_hash[:status] == 401
          msg = "Auth lost"
          logger.warn msg
          raise UnauthorizedAccessError.new, "Unauthorized Access"
        end

        if response.body.to_s.include?("<title>302 Found</title>")
          raise AppleTimeoutError.new, "Apple 302 detected"
        end
        return response
      end
    end

    def encode_params(params, headers)
      params = Faraday::Utils::ParamsHash[params].to_query
      headers = { 'Content-Type' => 'application/x-www-form-urlencoded' }.merge(headers)
      return params, headers
    end
  end
end

require 'spaceship/two_step_client'


text:
from docker_tasks import build_image

def test_build_image():
    """
    requires docker and docker-registry to be started
    """
    build_image(
        build_image="buildroot-fedora",
        git_url="https://github.com/TomasTomecek/docker-hello-world.git",
        local_tag="fedora-celery-build",
    )


text:
name             'datasmart_erl'
maintainer       'evalonlabs'
maintainer_email 'epappas@evalonlabs.com'
license          'All rights reserved'
description      'Installs/Configures datasmart_erl'
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version          '0.1.0'

depends 'build-essential'
depends 'openssl'
depends 'erlang'
# depends 'couchdb'
# depends 'nodejs'
# depends 'redisio'
# depends 'chef-client'
depends 'git'