Skip to content

Instantly share code, notes, and snippets.

@UniIsland
UniIsland / simple-cors-http-server.py
Created February 10, 2018 14:30
Simple Python HTTP server with CORS (or other custom) header.
#!/usr/bin/env python
# Attribution: https://stackoverflow.com/questions/21956683/enable-access-control-on-simple-http-server
try:
# Python 3
from http.server import HTTPServer, SimpleHTTPRequestHandler, test as test_orig
import sys
def test (*args):
test_orig(*args, port=int(sys.argv[1]) if len(sys.argv) > 1 else 8000)
@UniIsland
UniIsland / moving_average.r
Created February 10, 2018 16:36
Calculate Moving Average with R
## calculating moving average
## x: data vector
## n: use how many samples
## s: 1 - with lag; 2 - symmetrically
f.ma <- function(x,n=5,s=2){filter(x,rep(1/n,n), sides=s)}
@UniIsland
UniIsland / linode_dns_updater.rb
Created February 10, 2018 16:39
update linode dns record with ruby
#!/usr/bin/env ruby
require 'rubygems'
require 'linode'
api_key = '<API_KEY_STRING>'
domain_id = 123456 # Domain ID
resource_id = 7654321 # Resource ID
new_ip = `ifconfig | grep "inet " | grep -v '127.0.0'`.split(' ')[1]
@UniIsland
UniIsland / zhihu-topic_bind_shortcut.js
Created February 10, 2018 16:45
Tampermonkey Script for 知乎话题快捷绑定(知乎问答页改版后已不再可用)
// ==UserScript==
// @name zhihu - 快捷话题绑定
// @namespace http://www.zhihu.com/
// @version 0.1
// @description enter something useful
// @match http://www.zhihu.com/question/*
// @copyright 2012+, You
// ==/UserScript==
var topics = [[220,'知乎社区'],[33917,'个人咨询'],[87436,'成人内容'],[1309,'调查类问题']];
@UniIsland
UniIsland / xargs_with_function.sh
Last active October 10, 2023 11:05
use xargs with bash function
#!/bin/bash
parse_and_echo() {
echo "\$1:$1 \$2:$2 \$3:$3 \$4:$4"
echo newline
}
export -f parse_and_echo
# `_' is placeholder for $0