This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def swap_array(a: Array[Int]) = { | |
for (i <- 0 until a.length) { | |
if ((i % 2 == 0) && (i+1) < a.length) { | |
val t = a(i) | |
a(i) = a(i+1) | |
a(i+1) = t | |
} | |
} | |
a | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env coffee | |
request = require "request" | |
argv = require('yargs') | |
.option('u', { | |
alias : 'url', | |
demand: true, | |
describe: 'Keystone auth url, just specify controller ip address', | |
type: 'string' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Your init script | |
# | |
# Atom will evaluate this file each time a new window is opened. It is run | |
# after packages are loaded/activated and after the previous editor state | |
# has been restored. | |
# | |
# An example hack to log to the console when each text editor is saved. | |
# | |
# atom.workspace.observeTextEditors (editor) -> | |
# editor.onDidSave -> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ps -aux | sort -nr -k 6 | head -10 | awk '{printf "%dM %s\n", $6/1024, $11}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env coffee | |
request = require "request" | |
require "colors" | |
URL = "http://www.commandlinefu.com/commands/browse/sort-by-votes/json" | |
request URL, (error, response, body) -> | |
if error | |
console.log("Got error: " + error.message) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
ipsource=$(curl -s www.123cha.com | grep "您的ip") | |
ip=$(echo $ipsource | grep -oP "\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}" | head -1) | |
location=$(echo $ipsource | grep -o "来自: .*++" | sed -e 's/来自: //g' -e 's/ /-/g' -e 's/-++//g') | |
echo "$ip $location" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var quickSort = function(arr) { | |
if (!Array.isArray(arr)) throw new Error("arguments should be an array"); | |
if (arr.length <= 1) { return arr; } | |
var pivotIndex = Math.floor(arr.length / 2); | |
var pivot = arr.splice(pivotIndex, 1)[0]; | |
var left = []; | |
var right = []; | |
for (var i = 0; i < arr.length; i++){ | |
if (arr[i] < pivot) { | |
left.push(arr[i]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket, select | |
EOL1 = b'\n\n' | |
EOL2 = b'\n\r\n' | |
response = b'HTTP/1.0 200 OK\r\nDate: Mon, 1 Jan 1996 01:01:01 GMT\r\n' | |
response += b'Content-Type: text/plain\r\nContent-Length: 13\r\n\r\n' | |
response += b'Hello, world!' | |
serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
serversocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fs = require "fs" | |
request = require "request" | |
URLS = ("http://www.fanjian.net/page/#{i}" for i in [1..50]) | |
for url in URLS | |
pos = url.lastIndexOf "/" | |
n = url.slice pos + 1 | |
console.log n | |
request(url).pipe(fs.createWriteStream("output/#{n}.html")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
** client.c -- a stream socket client demo | |
*/ | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <unistd.h> | |
#include <errno.h> | |
#include <string.h> | |
#include <netdb.h> |