首页 文章 精选 留言 我的

精选列表

搜索[验证码识别],共10000篇文章
优秀的个人博客,低调大师

GitHub 推出 Python 安全警告,识别依赖包的安全漏洞

GitHub宣布了Python安全警告,使Python用户可以访问依赖图,并在他们的库所依赖的包存在安全漏洞时收到警告。 安全警告首次发布是在2017年10月,为了跟踪Ruby和JavaScript程序包中的安全漏洞。据GitHub介绍,从那时起,数以百万计的漏洞被发现,推动了许多补丁的发布。 GitHub会根据MITRE的公共漏洞列表(CVE)来跟踪Ruby gems、NPM和Python程序包中的公共安全漏洞。CVE是一个条目列表;每个条目都包含一个标识号、一段描述以及至少一项公共参考。这非常有助于促使管理员快速响应、通过移除易受攻击的依赖或迁移到安全版本来修复漏洞。 当GitHub收到新发布的漏洞通知,它就会扫描公共库(已经选择加入的私有库也会被扫描)。当发现漏洞时,就会向受影响的库的所有者和有管理员权限的用户发送安全警告。在默认情况下,用户每周都会收到一封邮件,其中包含多达10个库的安全警告。用户也可以自己选择通过电子邮件、每日摘要电子邮件、Web通知或GitHub用户界面来接收安全警告。用户可以在通知设置页面调整通知频率。 在某些情况下,对于发现的每个漏洞,GitHub会尝试使用机器学习提供修复建议。针对易受攻击的依赖的安全警告包含一个安全级别和一个指向项目受影响文件的链接,如果有的话,它还会提供CVE记录的链接和修复建议。通用漏洞评分系统(CVSS)定义了四种可能的等级,分别是低、中、高和严重。 据GitHub介绍,开始的时候,安全警告只会涵盖最新的漏洞,并在接下来的数周内添加更多Python历史漏洞。此外,GitHub永远不会公开披露任何库中发现的漏洞。 依赖图列出了项目的所有依赖,用户可以从中看出安全警告影响的项目。要查看依赖图,在项目中点击Insights,然后点击Dependency graph。 要在Python项目中使用依赖图,需要在requirements.txt或pipfile.lock文件中定义项目依赖。GitHub强烈建议用户在requirements.txt文件中定义依赖。 要了解更多信息,请查看GitHub文档。 来源:raincent

优秀的个人博客,低调大师

Hadoop WordCount改进实现正确识别单词以及词频降序排序

0.参考资料: http://radarradar.javaeye.com/blog/289257 http://blog.chinaunix.net/u3/99156/showart_2157576.html 1.思路: 1.1过滤 MapReduce的第一操作就是要读取文件,不过我们经常会发现一个文本中会有一些我们不需要的字符,比如特殊字符。一般需要进行词频统计的都是单词或者是数字,所以那些非0-9,a-z,A-Z的字符基本都是垃圾字符,我们需要进行统计,这是我们可以通过一个正则表达式来进行过滤,当每次多去一行文字的时候,我们将所有非0-9,a-z,A-Z的垃圾字符都替换为空格,这样就清楚了垃圾字符。在我们最后的词频统计结果中,就不会出现这些特殊字符了。 1.2降序 定义一个用户排序比较的静态内部类,通过这个类来控制词频统计最后的排序结果。我们这里所使用的静态内部类是IntWritableDecreasingComparator。需要注意的是必须在main函数中主动声明使用这个比较器。 2.代码实例 package org.apache.hadoop.examples; import java.io.IOException; import java.util.Random; import java.util.StringTokenizer; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; import org.apache.hadoop.io.IntWritable; import org.apache.hadoop.io.Text; import org.apache.hadoop.io.WritableComparable; import org.apache.hadoop.mapreduce.Job; import org.apache.hadoop.mapreduce.Mapper; import org.apache.hadoop.mapreduce.Reducer; import org.apache.hadoop.mapreduce.lib.input.FileInputFormat; import org.apache.hadoop.mapreduce.lib.input.SequenceFileInputFormat; import org.apache.hadoop.mapreduce.lib.map.InverseMapper; import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat; import org.apache.hadoop.mapreduce.lib.output.SequenceFileOutputFormat; import org.apache.hadoop.util.GenericOptionsParser; public class WordCount2 { public static class TokenizerMapper extends Mapper<Object, Text, Text, IntWritable> { private final static IntWritable one = new IntWritable(1); private Text word = new Text(); private String pattern = "[^//w]"; // 正则表达式,代表不是0-9, a-z, A-Z的所有其它字符,其中还有下划线 public void map(Object key, Text value, Context context) throws IOException, InterruptedException { String line = value.toString().toLowerCase(); // 全部转为小写字母 line = line.replaceAll(pattern, " "); // 将非0-9, a-z, A-Z的字符替换为空格 StringTokenizer itr = new StringTokenizer(line); while (itr.hasMoreTokens()) { word.set(itr.nextToken()); context.write(word, one); } } } public static class IntSumReducer extends Reducer<Text, IntWritable, Text, IntWritable> { private IntWritable result = new IntWritable(); public void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException { int sum = 0; for (IntWritable val : values) { sum += val.get(); } result.set(sum); context.write(key, result); } } private static class IntWritableDecreasingComparator extends IntWritable.Comparator { public int compare(WritableComparable a, WritableComparable b) { return -super.compare(a, b); } public int compare(byte[] b1, int s1, int l1, byte[] b2, int s2, int l2) { return -super.compare(b1, s1, l1, b2, s2, l2); } } public static void main(String[] args) throws Exception { Configuration conf = new Configuration(); String[] otherArgs = new GenericOptionsParser(conf, args) .getRemainingArgs(); if (otherArgs.length != 2) { System.err.println("Usage: wordcount <in> <out>"); System.exit(2); } Path tempDir = new Path("wordcount-temp-" + Integer.toString( new Random().nextInt(Integer.MAX_VALUE))); //定义一个临时目录 Job job = new Job(conf, "word count"); job.setJarByClass(WordCount2.class); try{ job.setMapperClass(TokenizerMapper.class); job.setCombinerClass(IntSumReducer.class); job.setReducerClass(IntSumReducer.class); job.setOutputKeyClass(Text.class); job.setOutputValueClass(IntWritable.class); FileInputFormat.addInputPath(job, new Path(otherArgs[0])); FileOutputFormat.setOutputPath(job, tempDir);//先将词频统计任务的输出结果写到临时目 //录中, 下一个排序任务以临时目录为输入目录。 job.setOutputFormatClass(SequenceFileOutputFormat.class); if(job.waitForCompletion(true)) { Job sortJob = new Job(conf, "sort"); sortJob.setJarByClass(WordCount2.class); FileInputFormat.addInputPath(sortJob, tempDir); sortJob.setInputFormatClass(SequenceFileInputFormat.class); /*InverseMapper由hadoop库提供,作用是实现map()之后的数据对的key和value交换*/ sortJob.setMapperClass(InverseMapper.class); /*将 Reducer 的个数限定为1, 最终输出的结果文件就是一个。*/ sortJob.setNumReduceTasks(1); FileOutputFormat.setOutputPath(sortJob, new Path(otherArgs[1])); sortJob.setOutputKeyClass(IntWritable.class); sortJob.setOutputValueClass(Text.class); /*Hadoop 默认对 IntWritable 按升序排序,而我们需要的是按降序排列。 * 因此我们实现了一个 IntWritableDecreasingComparator 类, * 并指定使用这个自定义的 Comparator 类对输出结果中的 key (词频)进行排序*/ sortJob.setSortComparatorClass(IntWritableDecreasingComparator.class); System.exit(sortJob.waitForCompletion(true) ? 0 : 1); } }finally{ FileSystem.get(conf).deleteOnExit(tempDir); } } } 本文转自xwdreamer博客园博客,原文链接:http://www.cnblogs.com/xwdreamer/archive/2011/01/07/2297044.html,如需转载请自行联系原作者

优秀的个人博客,低调大师

使用Hive UDF和GeoIP库为Hive加入IP识别功能

导读:Hive是基于Hadoop的数据管理系统,作为分析人员的即时分析工具和ETL等工作的执行引擎,对于如今的大数据管理与分析、处理有着非常大的意义。GeoIP是一套IP映射库系统,它定时更新,并且提供了各种语言的API,非常适合在做地域相关数据分析时的一个数据源。 Hive是基于Hadoop的数据管理系统,作为分析人员的即时分析工具和ETL等工作的执行引擎,对于如今的大数据管理与分析、处理有着非常大的意义。GeoIP是一套IP映射库系统,它定时更新,并且提供了各种语言的API,非常适合在做地域相关数据分析时的一个数据源。 UDF是Hive提供的用户自定义函数的接口,通过实现它可以扩展Hive目前已有的内置函数。而为Hive加入一个IP映射函数,我们只需要简单地在UDF中调用GeoIP的Java API即可。 GeoIP的数据文件可以从这里下载:http://www.maxmind.com/download/geoip/database/,由于需要国家和城市的信息,我这里下载的是http://www.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz GeoIP的各种语言的API可以从这里下载:http://www.maxmind.com/download/geoip/api/ 查看文本 copy to clipboard 打印 ? importjava.io.IOException; importorg.apache.hadoop.hive.ql.exec.UDF; importcom.maxmind.geoip.Location; importcom.maxmind.geoip.LookupService; importjava.util.regex.*; publicclassIPToCCextendsUDF{ privatestaticLookupServicecl=null; privatestaticStringipPattern="\\d+\\.\\d+\\.\\d+\\.\\d+"; privatestaticStringipNumPattern="\\d+"; staticLookupServicegetLS()throwsIOException{ Stringdbfile="GeoLiteCity.dat"; if(cl==null) cl=newLookupService(dbfile,LookupService.GEOIP_MEMORY_CACHE); returncl; } /** *@paramstrlike"114.43.181.143" **/ publicStringevaluate(Stringstr){ try{ LocationAl=null; MatchermIP=Pattern.compile(ipPattern).matcher(str); MatchermIPNum=Pattern.compile(ipNumPattern).matcher(str); if(mIP.matches()) Al=getLS().getLocation(str); elseif(mIPNum.matches()) Al=getLS().getLocation(Long.parseLong(str)); returnString.format("%s\t%s",Al.countryName,Al.city); }catch(Exceptione){ e.printStackTrace(); if(cl!=null) cl.close(); returnnull; } } } import java.io.IOException; import org.apache.hadoop.hive.ql.exec.UDF; import com.maxmind.geoip.Location; import com.maxmind.geoip.LookupService; import java.util.regex.*; public class IPToCC extends UDF { private static LookupService cl = null; private static String ipPattern = "\\d+\\.\\d+\\.\\d+\\.\\d+"; private static String ipNumPattern = "\\d+"; static LookupService getLS() throws IOException{ String dbfile = "GeoLiteCity.dat"; if(cl == null) cl = new LookupService(dbfile, LookupService.GEOIP_MEMORY_CACHE); return cl; } /** * @param str like "114.43.181.143" * */ public String evaluate(String str) { try{ Location Al = null; Matcher mIP = Pattern.compile(ipPattern).matcher(str); Matcher mIPNum = Pattern.compile(ipNumPattern).matcher(str); if(mIP.matches()) Al = getLS().getLocation(str); else if(mIPNum.matches()) Al = getLS().getLocation(Long.parseLong(str)); return String.format("%s\t%s", Al.countryName, Al.city); }catch(Exception e){ e.printStackTrace(); if(cl != null) cl.close(); return null; } } } 使用上也非常简单,将以上程序和GeoIP的API程序,一起打成JAR包iptocc.jar,和数据文件(GeoLiteCity.dat)一起放到Hive所在的服务器的一个位置。然后打开Hive执行以下语句: 查看文本 copy to clipboard 打印 ? addfile/tje/path/to/GeoLiteCity.dat; addjar/the/path/to/iptocc.jar; createtemporaryfunctionip2ccas'your.company.udf.IPToCC'; add file /tje/path/to/GeoLiteCity.dat; add jar /the/path/to/iptocc.jar; create temporary function ip2cc as 'your.company.udf.IPToCC'; 然后就可以在Hive的CLI中使用这个函数了,这个函数接收标准的IPv4地址格式的字符串,返回国家和城市信息;同样这个函数也透明地支持长整形的IPv4地址表示格式。如果想在每次启动Hive CLI的时候都自动加载这个自定义函数,可以在hive命令同目录下建立.hiverc文件,在启动写入以上三条语句,重新启动Hive CLI即可;如果在这台服务器上启动Hive Server,使用JDBC连接,执行以上三条语句之后,也可以正常使用这个函数;但是唯一一点不足是,HUE的Beeswax不支持注册用户自定义函数。 虽然不尽完美,但是加入这样一个函数,对于以后做地域相关的即时分析总是提供了一些方便的,还是非常值得加入的。 本文转自茄子_2008博客园博客,原文链接:http://www.cnblogs.com/xd502djj/p/3253411.html,如需转载请自行联系原作者。

资源下载

更多资源
Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

用户登录
用户注册