失业的打击就像一场毫无征兆的秋雨,打湿了曾经那个自命不凡地自己。人生的所有曲折似乎在此时此刻彼此呼应,而今天我的处境,可能也正是许多人正要面临的窘境。

对于我来说,失业不仅仅是经济上的挫折,更是一次被迫的自我审视。在经历从收入丰厚到陷入困顿的转变后,内心的煎熬远比金钱的缺乏更加难以承受。

失业带来的心理冲击

即使已经读过无数“如何应对失业”的建议,但当失业真正发生在自己身上时,却都显得苍白无力。当面对家庭的琐事和压力,每天醒来发现生活依旧难题重重时,难免开始怀疑。

同时,现实不可能因你的积极心态而变好,也不会因为学习了新技能就马上能获得一个能养家糊口的工作。此时,可能会让你更加的怀疑人生。

未来的路该怎么走?甚至是,自己是否具备应对新挑战的能力?开始陷入无尽的自我怀疑中……

打破舒适区的陷阱

无论30岁还是40岁,人生各阶段都有不同的难关。尽管艰难,但往往只能靠自己一步步挺过来。你感到焦虑、迷茫的原因,或许在于失去经济来源带来的家庭压力,让生活变得更加艰难。失业切断了收入的来源,这是对任何人来说都难以承受的考验。

失业期间,你可能会怀疑自己的价值,担心未来,但请记得,这些情绪都是正常的。也许,失业未必完全是坏事。许多人在职场上看似忙碌,实则原地踏步,甚至不断退步。一直得过且过,逐渐失去斗志。而失业反倒可能成为一次新的开始。

尽管这是一个痛苦的过程,却也是促使我成长的必经之路。无论是创业,还是借助朋友的帮助,先解决眼前的燃眉之急。假如回顾人脉网络,发现周围的朋友并不可靠,甚至阻碍你前行,或许更深层的问题并不只是失业,而是要重新审视自己与他人关系的本质。

永不放弃寻找新的开始

失业可能会带来沮丧和压力,但最令人绝望的并非失去工作,而是放弃寻找新的可能性。朋友,务必要坚持下去,竭尽全力地拯救自己,不管过程多么艰难,都不要轻易放弃。妥协和退缩只会让人困于泥潭,而充满勇气的挣扎才能带来希望和成长。

陌生的朋友,祝好。

在AI兴起之前,一直在用的代码,分享给盆友们~

Mozilla Readability.js 的 PHP 端口。解析 html(通常是新闻和文章)返回标题、作者、主图像和文本内容(最新版可用属性)。分析每个节点,给它们打分,并确定哪些是相关的,哪些可以丢弃。

算法原作者:https://github.com/mingcheng/php-readability/

算法新版:https://github.com/andreskrey/readability.php(该项目已经废弃)

算法最新版:https://github.com/fivefilters/readability.php

require 'Readability.php';
$html = "整个html页面";
$Readability     = new Readability($html);
$ReadabilityData = $Readability->getContent();

//var_dump($ReadabilityData);
echo "<h1>".$ReadabilityData['title']."</h1>";
echo $ReadabilityData['content'];

Readability.php

class Readability {
	// 保存判定结果的标记位名称
	const ATTR_CONTENT_SCORE = "contentScore";

	// DOM 解析类目前只支持 UTF-8 编码
	const DOM_DEFAULT_CHARSET = "utf-8";

	// 当判定失败时显示的内容
	const MESSAGE_CAN_NOT_GET = "Readability was unable to parse this page for content.";

	// DOM 解析类(PHP5 已内置)
	protected $DOM = null;

	// 需要解析的源代码
	protected $source = "";

	// 章节的父元素列表
	private $parentNodes = array();

	// 需要删除的标签
	// Note: added extra tags from https://github.com/ridcully
	private $junkTags = Array("style", "form", "iframe", "script", "button", "input", "textarea", 
								"noscript", "select", "option", "object", "applet", "basefont",
								"bgsound", "blink", "canvas", "command", "menu", "nav", "datalist",
								"embed", "frame", "frameset", "keygen", "label", "marquee", "link");

	// 需要删除的属性
	private $junkAttrs = Array("style", "class", "onclick", "onmouseover", "align", "border", "margin", "id", "contentScore");


	/**
	 * 构造函数
	 *	  @param $input_char 字符串的编码。默认 utf-8,可以省略
	 */
	function __construct($source, $input_char = "utf-8") {
		$this->source = $source;

		// DOM 解析类只能处理 UTF-8 格式的字符
		$source = mb_convert_encoding($source, 'HTML-ENTITIES', $input_char);

		// 预处理 HTML 标签,剔除冗余的标签等
		$source = $this->preparSource($source);

		// 生成 DOM 解析类
		$this->DOM = new DOMDocument('1.0', $input_char);
		try {
			//libxml_use_internal_errors(true);
			// 会有些错误信息,不过不要紧 :^)
			if (!@$this->DOM->loadHTML('<?xml encoding="'.Readability::DOM_DEFAULT_CHARSET.'">'.$source)) {
				throw new Exception("Parse HTML Error!");
			}

			foreach ($this->DOM->childNodes as $item) {
				if ($item->nodeType == XML_PI_NODE) {
					$this->DOM->removeChild($item); // remove hack
				}
			}

			// insert proper
			$this->DOM->encoding = Readability::DOM_DEFAULT_CHARSET;
		} catch (Exception $e) {
			// ...
		}
	}


	/**
	 * 预处理 HTML 标签,使其能够准确被 DOM 解析类处理
	 *
	 * @return String
	 */
	private function preparSource($string) {
		// 剔除多余的 HTML 编码标记,避免解析出错
		preg_match("/charset=([\w|\-]+);?/", $string, $match);
		if (isset($match[1])) {
			$string = preg_replace("/charset=([\w|\-]+);?/", "", $string, 1);
		}

		// Replace all doubled-up <BR> tags with <P> tags, and remove fonts.
		$string = preg_replace("/<br\/?>[ \r\n\s]*<br\/?>/i", "</p><p>", $string);
		$string = preg_replace("/<\/?font[^>]*>/i", "", $string);

		// @see https://github.com/feelinglucky/php-readability/issues/7
		//   - from http://stackoverflow.com/questions/7130867/remove-script-tag-from-html-content
		$string = preg_replace("#<script(.*?)>(.*?)</script>#is", "", $string);

		return trim($string);
	}


	/**
	 * 删除 DOM 元素中所有的 $TagName 标签
	 *
	 * @return DOMDocument
	 */
	private function removeJunkTag($RootNode, $TagName) {
		
		$Tags = $RootNode->getElementsByTagName($TagName);
		
		//Note: always index 0, because removing a tag removes it from the results as well.
		while($Tag = $Tags->item(0)){
			$parentNode = $Tag->parentNode;
			$parentNode->removeChild($Tag);
		}
		
		return $RootNode;
		
	}

	/**
	 * 删除元素中所有不需要的属性
	 */
	private function removeJunkAttr($RootNode, $Attr) {
		$Tags = $RootNode->getElementsByTagName("*");

		$i = 0;
		while($Tag = $Tags->item($i++)) {
			$Tag->removeAttribute($Attr);
		}

		return $RootNode;
	}

	/**
	 * 根据评分获取页面主要内容的盒模型
	 *	  判定算法来自:http://code.google.com/p/arc90labs-readability/   
	 *	  这里由郑晓博客转发
	 * @return DOMNode
	 */
	private function getTopBox() {
		// 获得页面所有的章节
		$allParagraphs = $this->DOM->getElementsByTagName("p");

		// Study all the paragraphs and find the chunk that has the best score.
		// A score is determined by things like: Number of <p>'s, commas, special classes, etc.
		$i = 0;
		while($paragraph = $allParagraphs->item($i++)) {
			$parentNode   = $paragraph->parentNode;
			$contentScore = intval($parentNode->getAttribute(Readability::ATTR_CONTENT_SCORE));
			$className	= $parentNode->getAttribute("class");
			$id		   = $parentNode->getAttribute("id");

			// Look for a special classname
			if (preg_match("/(comment|meta|footer|footnote)/i", $className)) {
				$contentScore -= 50;
			} else if(preg_match(
				"/((^|\\s)(post|hentry|entry[-]?(content|text|body)?|article[-]?(content|text|body)?)(\\s|$))/i",
				$className)) {
				$contentScore += 25;
			}

			// Look for a special ID
			if (preg_match("/(comment|meta|footer|footnote)/i", $id)) {
				$contentScore -= 50;
			} else if (preg_match(
				"/^(post|hentry|entry[-]?(content|text|body)?|article[-]?(content|text|body)?)$/i",
				$id)) {
				$contentScore += 25;
			}

			// Add a point for the paragraph found
			// Add points for any commas within this paragraph
			if (strlen($paragraph->nodeValue) > 10) {
				$contentScore += strlen($paragraph->nodeValue);
			}

			// 保存父元素的判定得分
			$parentNode->setAttribute(Readability::ATTR_CONTENT_SCORE, $contentScore);

			// 保存章节的父元素,以便下次快速获取
			array_push($this->parentNodes, $parentNode);
		}

		$topBox = null;
		
		// Assignment from index for performance. 
		//	 See http://www.peachpit.com/articles/article.aspx?p=31567&seqNum=5 
		for ($i = 0, $len = sizeof($this->parentNodes); $i < $len; $i++) {
			$parentNode	  = $this->parentNodes[$i];
			$contentScore	= intval($parentNode->getAttribute(Readability::ATTR_CONTENT_SCORE));
			$orgContentScore = intval($topBox ? $topBox->getAttribute(Readability::ATTR_CONTENT_SCORE) : 0);

			if ($contentScore && $contentScore > $orgContentScore) {
				$topBox = $parentNode;
			}
		}
		
		// 此时,$topBox 应为已经判定后的页面内容主元素
		return $topBox;
	}


	/**
	 * 获取 HTML 页面标题
	 *
	 * @return String
	 */
	public function getTitle() {
		$split_point = ' - ';
		$titleNodes = $this->DOM->getElementsByTagName("title");

		if ($titleNodes->length 
			&& $titleNode = $titleNodes->item(0)) {
			// @see http://stackoverflow.com/questions/717328/how-to-explode-string-right-to-left
			$title  = trim($titleNode->nodeValue);
			$result = array_map('strrev', explode($split_point, strrev($title)));
			return sizeof($result) > 1 ? array_pop($result) : $title;
		}

		return null;
	}


	/**
	 * Get Leading Image Url
	 *
	 * @return String
	 */
	public function getLeadImageUrl($node) {
		$images = $node->getElementsByTagName("img");

		if ($images->length && $leadImage = $images->item(0)) {
			return $leadImage->getAttribute("src");
		}

		return null;
	}


	/**
	 * 获取页面的主要内容(Readability 以后的内容)
	 *
	 * @return Array
	 */
	public function getContent() {
		if (!$this->DOM) return false;

		// 获取页面标题
		$ContentTitle = $this->getTitle();

		// 获取页面主内容
		$ContentBox = $this->getTopBox();
		
		//Check if we found a suitable top-box.
		if($ContentBox === null)
			throw new RuntimeException(Readability::MESSAGE_CAN_NOT_GET);
		
		// 复制内容到新的 DOMDocument
		$Target = new DOMDocument;
		$Target->appendChild($Target->importNode($ContentBox, true));

		// 删除不需要的标签
		foreach ($this->junkTags as $tag) {
			$Target = $this->removeJunkTag($Target, $tag);
		}

		// 删除不需要的属性
		foreach ($this->junkAttrs as $attr) {
			$Target = $this->removeJunkAttr($Target, $attr);
		}

		$content = mb_convert_encoding($Target->saveHTML(), Readability::DOM_DEFAULT_CHARSET, "HTML-ENTITIES");

		// 多个数据,以数组的形式返回
		return Array(
			'lead_image_url' => $this->getLeadImageUrl($Target),
			'word_count' => mb_strlen(strip_tags($content), Readability::DOM_DEFAULT_CHARSET),
			'title' => $ContentTitle ? $ContentTitle : null,
			'content' => $content
		);
	}

	function __destruct() { }
}


在使用Typecho时,文章浏览次数统计算是最常用到的功能,把下面这段代码加到主题 functions.php 中,直接调用即可。代码加入了Cookie防刷新,这样文章浏览次数更真实。

function get_views($archive) {
    $db = Typecho_Db::get();
    $cid = $archive->cid;
    //添加 table.contents.views 字段
    if (!array_key_exists('views', $db->fetchRow($db->select()->from('table.contents')))) {
        $db->query('ALTER TABLE `'.$db->getPrefix().'contents` ADD `views` INT(10) DEFAULT 0;');
    }
    $row = $db->fetchRow($db->select('views')->from('table.contents')->where('cid = ?', $cid));
    $views = (int)$row['views'];
    if ($archive->is('single')) {
        $cookie = Typecho_Cookie::get('extend_views');
        $cookie = $cookie ? explode(',', $cookie) : array();
        if (!in_array($cid, $cookie)) {
            $db->query($db->update('table.contents')->rows(array('views' => $views+1))->where('cid = ?', $cid));
            $views = $views+1;
            array_push($cookie, $cid);
            $cookie = implode(',', $cookie);
            Typecho_Cookie::set('extend_views', $cookie);
        }
    }
    echo $views == 0 ? '暂无阅读' :'阅读量:' . $views;
}

调用代码:

<?php get_views($this) ?>

想要实现左右div等高,可以使用CSS的Flexbox布局或者Grid布局来实现。以下是2种方法的示例:

使用Flexbox布局:

<div class="container">
	<div class="left">左边内容</div>
	<div class="right">右边内容<br>右边内容</div>
</div>
<style>
.container {
	display: flex;
}
.left {
	background-color: red;
}
.right {
	background-color: Blue;
}
</style>

在上述示例中,通过将容器设置为Flexbox布局,并将左右两个子元素的flex属性设置为1,可以使它们平均分配容器的宽度,从而实现高度相等。

使用Grid布局:

<div class="container">
	<div class="left">左边内容</div>
	<div class="right">右边内容<br>右边内容</div>
</div>
<style>
.container {
	display: grid;
	grid-template-columns: 1fr 1fr;
}
.left, .right {
	height: 100%;
}
.left {
	background-color: red;
}
.right {
	background-color: Blue;
}
</style>

以上两种方法都可以实现左右两边的div高度相等,具体选择哪种方法取决于项目需求,本站主题使用的Flexbox布局!

id是网站中经常出现的,它一般是数字,但是我们发现现在的网站很多ID都是字母了,比如YouTube的视频播放页它的URL类似 /watch?v=bTT4lmzlFuE。下面是一个生成字母id,并可以逆转回数字id的方法,而且还可设置秘钥。示例:

alphaID(12354); //会将数字转换为字母ID
alphaID('PpQXn7COf', true); //会将字母ID转换为对应的数字ID
alphaID(12354, false, 6, "passKey"); //带秘钥指定生成字母ID的长度为6
alphaID('PpQXn7COf', true, 6, "passKey"); //带秘钥将字母ID转换为对应的数字ID
/**
 * Translates a number to a short alhanumeric version
 *
 * Translated any number up to 9007199254740992
 * to a shorter version in letters e.g.:
 * 9007199254740989 --> PpQXn7COf
 *
 * specifiying the second argument true, it will
 * translate back e.g.:
 * PpQXn7COf --> 9007199254740989
 *
 * this function is based on any2dec && dec2any by
 * fragmer[at]mail[dot]ru
 * see: http://nl3.php.net/manual/en/function.base-convert.php#52450
 *
 * If you want the alphaID to be at least 3 letter long, use the
 * $pad_up = 3 argument
 *
 * In most cases this is better than totally random ID generators
 * because this can easily avoid duplicate ID's.
 * For example if you correlate the alpha ID to an auto incrementing ID
 * in your database, you're done.
 *
 * The reverse is done because it makes it slightly more cryptic,
 * but it also makes it easier to spread lots of IDs in different
 * directories on your filesystem. Example:
 * $part1 = substr($alpha_id,0,1);
 * $part2 = substr($alpha_id,1,1);
 * $part3 = substr($alpha_id,2,strlen($alpha_id));
 * $destindir = "/".$part1."/".$part2."/".$part3;
 * // by reversing, directories are more evenly spread out. The
 * // first 26 directories already occupy 26 main levels
 *
 * more info on limitation:
 * - http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/165372
 *
 * if you really need this for bigger numbers you probably have to look
 * at things like: http://theserverpages.com/php/manual/en/ref.bc.php
 * or: http://theserverpages.com/php/manual/en/ref.gmp.php
 * but I haven't really dugg into this. If you have more info on those
 * matters feel free to leave a comment.
 *
 * @author  Kevin van Zonneveld <[email protected]>
 * @author  Simon Franz
 * @author  Deadfish
 * @copyright 2008 Kevin van Zonneveld (http://kevin.vanzonneveld.net)
 * @license   http://www.opensource.org/licenses/bsd-license.php New BSD Licence
 * @version   SVN: Release: $Id: alphaID.inc.php 344 2009-06-10 17:43:59Z kevin $
 * @link    http://kevin.vanzonneveld.net/
 *
 * @param mixed   $in    String or long input to translate
 * @param boolean $to_num  Reverses translation when true
 * @param mixed   $pad_up  Number or boolean padds the result up to a specified length
 * @param string  $passKey Supplying a password makes it harder to calculate the original ID
 *
 * @return mixed string or long
 */
function alphaID($in, $to_num = false, $pad_up = false, $passKey = null)
{
  $index = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  if ($passKey !== null) {
    // Although this function's purpose is to just make the
    // ID short - and not so much secure,
    // with this patch by Simon Franz (http://blog.snaky.org/)
    // you can optionally supply a password to make it harder
    // to calculate the corresponding numeric ID
  
    for ($n = 0; $n<strlen($index); $n++) {
      $i&#91;&#93; = substr( $index,$n ,1);
    }
  
    $passhash = hash('sha256',$passKey);
    $passhash = (strlen($passhash) < strlen($index))
      ? hash('sha512',$passKey)
      : $passhash;
  
    for ($n=0; $n < strlen($index); $n++) {
      $p&#91;&#93; =  substr($passhash, $n ,1);
    }
  
    array_multisort($p,  SORT_DESC, $i);
    $index = implode($i);
  }
  
  $base  = strlen($index);
  
  if ($to_num) {
    // Digital number  <<--  alphabet letter code
    $in  = strrev($in);
    $out = 0;
    $len = strlen($in) - 1;
    for ($t = 0; $t <= $len; $t++) {
      $bcpow = bcpow($base, $len - $t);
      $out   = $out + strpos($index, substr($in, $t, 1)) * $bcpow;
    }
  
    if (is_numeric($pad_up)) {
      $pad_up--;
      if ($pad_up > 0) {
        $out -= pow($base, $pad_up);
      }
    }
    $out = sprintf('%F', $out);
    $out = substr($out, 0, strpos($out, '.'));
  } else {
    // Digital number  -->>  alphabet letter code
    if (is_numeric($pad_up)) {
      $pad_up--;
      if ($pad_up > 0) {
        $in += pow($base, $pad_up);
      }
    }
  
    $out = "";
    for ($t = floor(log($in, $base)); $t >= 0; $t--) {
      $bcp = bcpow($base, $t);
      $a   = floor($in / $bcp) % $base;
      $out = $out . substr($index, $a, 1);
      $in  = $in - ($a * $bcp);
    }
    $out = strrev($out); // reverse
  }
  
  return $out;
}

写于 2018年03月25日,由 archive.org 找回