作者:chenj

Oracle调度程序

调度程序体系结构:

使用dbms_scheduler包来管理调度程序

dba_scheduler_jobs查询所有调度程序作业

cjq0后台进程调度作业执行

job_queue_processes限制调度作业的最大数,设置为0将不会运行调度程序

需要角色SCHEDULER_ADMIN     

调度程序可以是存储过程,也可以是shell脚本和操作系统命令

dbms_scheduler.create_job创建作业

dbms_scheduler.create_program创建程序 

dbms_scheduler.create_schedule创建时间表

dbms_scheduler.create_job_class创建作业类

dbms_scheduler.create_window创建窗口

阅读更多

Oracle 在Centos上的安装步骤

1.内存和磁盘空间检查

至少 1.0 GB 的物理内存

grep MemTotal /proc/meminfo

交换分区要求如下

grep SwapTotal /proc/meminfo

/tmp 需求:

 至少1.0 GB大小

2.安装oracle运行需要的软件包

yum -y  install binutils

yum -y install compat*

yum -y install gcc* 

yum -y install glibc*

yum -y install elfutils-libelf 

yum -y install ksh 

yum -y install libgcc*

阅读更多

.Net爬虫代码

        /// <summary>
        /// 异步创建爬虫
        /// </summary>
        /// <param name="uri">爬虫URL地址</param>
        /// <param name="proxy">代理服务器</param>
        /// <returns>网页源代码</returns>
        public async Task<string> Start(Uri uri, string proxy = null)
        {
            return await Task.Run(() =>
            {
                var pageSource = string.Empty;
                try
                {
                    if (this.OnStart != null) this.OnStart(this, new OnStartEventArgs(uri));
                    var watch = new Stopwatch();
                    watch.Start();
                    var request = (HttpWebRequest)WebRequest.Create(uri);
                    request.Accept = "*/*";
                    request.ServicePoint.Expect100Continue = false;//加快载入速度
                    request.ServicePoint.UseNagleAlgorithm = false;//禁止Nagle算法加快载入速度
                    request.AllowWriteStreamBuffering = false;//禁止缓冲加快载入速度
                    request.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip,deflate");//定义gzip压缩页面支持
                    request.ContentType = "application/x-www-form-urlencoded";//定义文档类型及编码
                    request.AllowAutoRedirect = false;//禁止自动跳转
                    //设置User-Agent,伪装成Google Chrome浏览器
                    Random rm = new Random();
                    int i = rm.Next(UserAgent.Count);//随机伪造浏览器
                    request.UserAgent = UserAgent[i];// "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36";
                    request.Timeout = 5000;//定义请求超时时间为5秒
                    request.KeepAlive = true;//启用长连接
                    request.Method = "GET";//定义请求方式为GET              
                    if (proxy != null) request.Proxy = new WebProxy(proxy);//设置代理服务器IP,伪装请求地址
                    request.CookieContainer = this.CookiesContainer;//附加Cookie容器
                    request.ServicePoint.ConnectionLimit = int.MaxValue;//定义最大连接数

                    using (var response = (HttpWebResponse)request.GetResponse())
                    {//获取请求响应

                        foreach (Cookie cookie in response.Cookies) this.CookiesContainer.Add(cookie);//将Cookie加入容器,保存登录状态

                        if (response.ContentEncoding.ToLower().Contains("gzip"))//解压
                        {

                            using (GZipStream stream = new GZipStream(response.GetResponseStream(), CompressionMode.Decompress))
                            {
                                var encoding = response.CharacterSet;//判断解决乱码
                                Encoding encode = Encoding.Default;
                                switch (encoding)
                                {
                                    case "utf-8":
                                        encode = Encoding.UTF8;
                                        break;
                                    case "gb2312":
                                        encode = Encoding.GetEncoding("gb2312");
                                        break;
                                    default:
                                        break;
                                }
                                using (StreamReader reader = new StreamReader(stream, encode))
                                {

                                    pageSource = reader.ReadToEnd();
                                }
                            }
                        }
                        else if (response.ContentEncoding.ToLower().Contains("deflate"))//解压
                        {
                            using (DeflateStream stream = new DeflateStream(response.GetResponseStream(), CompressionMode.Decompress))
                            {
                                var encoding = response.CharacterSet;//判断解决乱码
                                Encoding encode = Encoding.Default;
                                switch (encoding)
                                {
                                    case "utf-8":
                                        encode = Encoding.UTF8;
                                        break;
                                    case "gb2312":
                                        encode = Encoding.GetEncoding("gb2312");
                                        break;
                                    default:
                                        break;
                                }
                                using (StreamReader reader = new StreamReader(stream, encode))
                                {
                                    pageSource = reader.ReadToEnd();
                                }

                            }
                        }
                        else
                        {
                            using (Stream stream = response.GetResponseStream())//原始
                            {
                                using (StreamReader reader = new StreamReader(stream, Encoding.UTF8))
                                {

                                    pageSource = reader.ReadToEnd();
                                }
                            }
                        }
                    }
                    request.Abort();
                    watch.Stop();
                    var threadId = System.Threading.Thread.CurrentThread.ManagedThreadId;//获取当前任务线程ID
                    var milliseconds = watch.ElapsedMilliseconds;//获取请求执行时间
                    if (this.OnCompleted != null) this.OnCompleted(this, new OnCompletedEventArgs(uri, threadId, milliseconds, pageSource));
                }
                catch (Exception ex)
                {
                    if (this.OnError != null) this.OnError(this, new OnErrorEventArgs(uri, ex));
                }
                return pageSource;
            });
        }

EF Core通用基础类

using System;
using System.Linq;
using System.Linq.Expressions;
using Microsoft.EntityFrameworkCore;
using Sys.Reponsitory;
using Sys.Reponsitory.Core;
using Sys.Reponsitory.Interface;
using Z.EntityFramework.Plus;

namespace Sys.Reponsitory
{
    public class BaseReponsitory<T> : IReponsitory<T> where T : Entity
    {
        private SysDbContext _context;

        public BaseReponsitory(SysDbContext context)
        {
            _context = context;
        }


        /// <summary>
        /// 根据过滤条件,获取记录
        /// </summary>
        /// <param name="exp">The exp.</param>
        public IQueryable<T> Find(Expression<Func<T, bool>> exp = null)
        {
            return Filter(exp);
        }

        public bool IsExist(Expression<Func<T, bool>> exp)
        {
            return _context.Set<T>().Any(exp);
        }

        /// <summary>
        /// 查找单个,且不被上下文所跟踪
        /// </summary>
        public T FindSingle(Expression<Func<T, bool>> exp)
        {
            return _context.Set<T>().AsNoTracking().FirstOrDefault(exp);
        }

        /// <summary>
        /// 得到分页记录
        /// </summary>
        /// <param name="pageindex">The pageindex.</param>
        /// <param name="pagesize">The pagesize.</param>
        /// <param name="orderby">排序</param>
        public IQueryable<T> Find<S>(int pageindex, int pagesize, Expression<Func<T, S>> orderByLambda, Expression<Func<T, bool>> exp = null)
        {
            if (pageindex < 1)
                pageindex = 1;

            return Filter(exp).OrderBy(orderByLambda).Skip(pagesize * (pageindex - 1)).Take(pagesize);
        }

        /// <summary>
        /// 根据过滤条件获取记录数
        /// </summary>
        public int GetCount(Expression<Func<T, bool>> exp = null)
        {
            return Filter(exp).Count();
        }

        public void Add(T entity)
        {
            if (string.IsNullOrEmpty(entity.Id))
            {
                entity.Id = Guid.NewGuid().ToString();
            }
            _context.Set<T>().Add(entity);
            Save();
            _context.Entry(entity).State = EntityState.Detached;
        }

        /// <summary>
        /// 批量添加
        /// </summary>
        /// <param name="entities">The entities.</param>
        public void BatchAdd(T[] entities)
        {
            foreach (var entity in entities)
            {
                entity.Id = Guid.NewGuid().ToString();
            }
            _context.Set<T>().AddRange(entities);
            Save();
        }

        public void Update(T entity)
        {
            var entry = this._context.Entry(entity);
            entry.State = EntityState.Modified;
            foreach (System.Reflection.PropertyInfo p in entity.GetType().GetProperties())
            {
                string type = p.PropertyType.Name.ToString();
                if (p.Name == type)
                {
                    continue;
                }
                if (p.GetValue(entity) == null)
                {
                    if (this._context.Entry(entity).Property(p.Name).IsModified)
                    {
                        this._context.Entry(entity).Property(p.Name).IsModified = false;
                    }

                }
            }

            //如果数据没有发生变化
            if (!this._context.ChangeTracker.HasChanges())
            {
                return;
            }

            Save();
        }

        public void Delete(T entity)
        {
            _context.Set<T>().Remove(entity);
            Save();
        }


        /// <summary>
        /// 实现按需要只更新部分更新
        /// <para>如:Update(u =>u.Id==1,u =>new User{Name="ok"});</para>
        /// </summary>
        /// <param name="where">The where.</param>
        /// <param name="entity">The entity.</param>
        public void Update(Expression<Func<T, bool>> where, Expression<Func<T, T>> entity)
        {
            _context.Set<T>().Where(where).Update(entity);
        }

        public virtual void Delete(Expression<Func<T, bool>> exp)
        {
            _context.Set<T>().Where(exp).Delete();
        }

        public void Save()
        {
            _context.SaveChanges();
        }

        private IQueryable<T> Filter(Expression<Func<T, bool>> exp)
        {
            var dbSet = _context.Set<T>().AsNoTracking().AsQueryable();
            if (exp != null)
                dbSet = dbSet.Where(exp);
            return dbSet;
        }

        public int ExecuteSql(string sql)
        {
            return _context.Database.ExecuteSqlCommand(sql);
        }
    }
}

CMD命令实现数字雨

@echo off
title digitalrain
color 0b
setlocal ENABLEDELAYEDEXPANSION
for /l %%i in (0) do (
set “line=”
for /l %%j in (1,1,80) do (
set /a Down%%j-=2
set “x=!Down%%j!”
if !x! LSS 0 (
set /a Arrow%%j=!random!%%3
set /a Down%%j=!random!%%15+10
)
set “x=!Arrow%%j!”
if “!x!” == “2” (
set “line=!line!!random:~-1! “
) else (set “line=!line! “)
)
set /p=!line!<nul
)