Skip to content

Instantly share code, notes, and snippets.

var request = require('request');
var cheerio = require('cheerio');
request('http://thehackernews.com/', function(error, response, html) {
if (!error && response.statusCode == 200) {
var $ = cheerio.load(html);
var parseResult = [];
$(".post").each(function(i, element) {
var title = $(this).find("h1").text();
var date = $(this).find("span.dtstamp.author").attr("title");

element vertical center

position the element vertical center with pure CSS skill from Front-End Developer Taiwan Group

A Pen by kpman on CodePen.

License.

function compareNumbers(x, y) {
return x-y;
}
var numbers = [1,4,3,2];
numbers.sort(compareNumbers);
@kpman
kpman / Preferences.sublime-settings
Last active March 16, 2019 10:52
Sublime Text 3 with Seti-UI theme setting
{
"Seti_pad_5": true,
"Seti_tabs_med": true,
"auto_upgrade_ignore":
[
"Seti_UI"
],
"caret_extra_width": 0,
"color_scheme": "Packages/JavaScriptNext - ES6 Syntax/Monokai Phoenix.tmTheme",
"fade_fold_buttons": false,
@kpman
kpman / Seti_monokai.tmTheme
Last active August 29, 2015 14:15
Seti_monokai.tmTheme (Custom version)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>name</key>
<string>Seti_Monokai</string>
<key>settings</key>
<array>
<dict>
<key>settings</key>
@kpman
kpman / .tmux.conf
Created June 21, 2016 14:01
Change tmux default setting to use Ctrl + a (same as Screen)
# $Id: screen-keys.conf,v 1.7 2010-07-31 11:39:13 nicm Exp $
#
# By Nicholas Marriott. Public domain.
#
# This configuration file binds many of the common GNU screen key bindings to
# appropriate tmux key bindings. Note that for some key bindings there is no
# tmux analogue and also that this set omits binding some commands available in
# tmux but not in screen.
#
# Note this is only a selection of key bindings and they are in addition to the
@kpman
kpman / current-dir-in-iterm-tab-title.sh
Last active May 7, 2018 19:54 — forked from phette23/current-dir-in-iterm-tab-title.sh
Set the iTerm tab title to the current directory, not full path.
# put this in your .bash_profile
if [ $ITERM_SESSION_ID ]; then
export PROMPT_COMMAND='echo -ne "\033];${PWD##*/}\007"; ':"$PROMPT_COMMAND";
fi
###########################
# ~/.zshrc
precmd() {
# sets the tab title to current dir
@kpman
kpman / product.js
Created August 28, 2016 05:09 — forked from cybercase/product.js
Python-like itertools.product function in javascript
function product() {
var args = Array.prototype.slice.call(arguments); // makes array from arguments
return args.reduce(function tl (accumulator, value) {
var tmp = [];
accumulator.forEach(function (a0) {
value.forEach(function (a1) {
tmp.push(a0.concat(a1));
});
});
return tmp;
@kpman
kpman / week-2.md
Last active March 7, 2017 13:39 — forked from chentsulin/week-2.md
Week 2 - After class

Week 2

Homework Assignment

繳交方式

  • Deadline: 10/12 中午 12:00
  • 把檔案寄至 chentsulin@gmail.com,標題寫 [作業二/ 電機X XXX] (如果你已經會用 github 也可以寄 repo 連結過來)

1. 寫一個判斷並回傳型別的 function getType

@kpman
kpman / nvm-update.sh
Last active December 6, 2017 10:54
Update node version to LTS with nvm
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | bash # update to nvm@0.32.1
nvm install stable # v8.9.2 is LTS
nvm alias default stable # default -> stable (-> v8.9.2)