Skip to content

Instantly share code, notes, and snippets.

@raecoo
raecoo / .gitconfig
Created November 17, 2015 22:42 — forked from bimlas/.gitconfig
Using of variables in Git aliases
# Simplify the similar aliases in .gitconfig by using variables instead of
# copying the same flags.
[alias]
flags = "!FLAG_LOG='--graph --decorate --find-renames --date-order'; \
FLAG_DIFF='--patch --stat --ignore-blank-lines';"
glog = "!git flags; git log $FLAG_LOG --name-status"
gslog = "!git flags; git log $FLAG_LOG --stat"
slog = "!git flags; git log $FLAG_LOG --date=short --format='%C(auto)%h%C(auto)%d %C(bold blue)%ad %an%n %s%C(reset)'"
df = "!git flags; git diff $FLAG_DIFF"
@raecoo
raecoo / aws-multipartUpload.js
Created December 26, 2015 15:54 — forked from sevastos/aws-multipartUpload.js
Example AWS S3 Multipart Upload with aws-sdk for Node.js - Retries to upload failing parts
// Based on Glacier's example: http://docs.aws.amazon.com/AWSJavaScriptSDK/guide/examples.html#Amazon_Glacier__Multi-part_Upload
var fs = require('fs');
var AWS = require('aws-sdk');
AWS.config.loadFromPath('./aws-config.json');
var s3 = new AWS.S3();
// File
var fileName = '5.pdf';
var filePath = './' + fileName;
var fileKey = fileName;
@raecoo
raecoo / Restoring_Purchases.swift
Created January 5, 2016 14:21 — forked from mhomol/Restoring_Purchases.swift
Bag Labs Post - In-App Purchases - Restoring Purchases Section
//Start by conforming to the SKPaymentTransactionObserver
//Restore button pressed
@IBAction func restorePurchasesBtnPressed(sender: AnyObject)
{
SKPaymentQueue.defaultQueue().addTransactionObserver(self)
SKPaymentQueue.defaultQueue().restoreCompletedTransactions()
}
//MARK: SKPaymentTransactionObserver methods
@raecoo
raecoo / YouTubePlayerViaTVJS.swift
Created January 5, 2016 14:22 — forked from nickv2002/YouTubePlayerViaTVJS.swift
Swift code to play YouTube videos on AppleTV tvOS via a TVJS call using XCDYouTubeKit
//
// Created by Nick Vance on 12/4/15.
// Copyright © 2015 ToWatchList. All rights reserved.
//
import AVKit
import XCDYouTubeKit
import TVMLKit
class YTPlayerViewController: AVPlayerViewController, AVPlayerViewControllerDelegate {
@raecoo
raecoo / gc-cow.rb
Created February 26, 2016 05:30 — forked from wr0ngway/gc-cow.rb
test to see if GC in ruby 2 is truly copy on write friendly
#!/usr/bin/env ruby
rss = '.+?Rss:\s+(\d+)'
share = '.+?Shared_Clean:\s+(\d+)'
share << '.+?Shared_Dirty:\s+(\d+)'
priv = '.+?Private_Clean:\s+(\d+)'
priv << '.+?Private_Dirty:\s+(\d+)'
MEM_REGEXP = /\[heap\]#{rss}#{share}#{priv}/m
def mem_usage_linux
@raecoo
raecoo / active_admin.rb
Created March 2, 2016 03:21 — forked from stereoscott/active_admin.rb
Stream CSV exports in ActiveAdmin in Rails 4
# if you want to monkey patch every controller, put this in initializers/active_admin.rb
ActiveAdmin::ResourceController.class_eval do
include ActiveAdmin::CSVStream
end
@raecoo
raecoo / README.md
Created March 4, 2016 04:19 — forked from derwiki/README.md
Ruby module that you can use in a `before_action` on sensitive controllers for which you'd like a usage audit trail

Adding an audit log to your Rails app

If you have any sort of administrative interface on your web site, you can easily imagine an intruder gaining access and mucking about. How do you know the extent of the damage? Adding an audit log to your app is one quick solution. An audit log should record a few things:

  • controller entry points with parameter values
  • permanent information about the user, like user_id
  • transient information about the user, like IP and user_agent

Using the Rails framework, this is as simple as adding a before_action to your admin controllers. Here’s a basic version that I’m using in production.

require 'ostruct'
class JsonStruct < OpenStruct
def initialize(hash=nil)
@table = {}
@hash_table = {}
if hash
recurse = Proc.new do |item|
@raecoo
raecoo / base.rb
Created May 2, 2016 15:55 — forked from bensie/base.rb
Sinatra API Helpers
require "sinatra/base"
require "sinatra/namespace"
require "multi_json"
require "api/authentication"
require "api/error_handling"
require "api/pagination"
module Api
class Base < ::Sinatra::Base
@raecoo
raecoo / Naive-VPN.md
Created May 11, 2016 01:35 — forked from klzgrad/Naive-VPN.md
朴素VPN:一个纯内核级静态隧道

朴素VPN:一个纯内核级静态隧道

由于路由管控系统的建立,实时动态黑洞路由已成为最有效的封锁手段,TCP连接重置和DNS污染成为次要手段,利用漏洞的穿墙方法已不再具有普遍意义。对此应对方法是多样化协议的VPN来抵抗识别。这里介绍一种太简单、有时很朴素的“穷人VPN”。

朴素VPN只需要一次内核配置(Linux内核),即可永久稳定运行,不需要任何用户态守护进程。所有流量转换和加密全部由内核完成,原生性能,开销几乎没有。静态配置,避免动态握手和参数协商产生指纹特征导致被识别。并且支持NAT,移动的内网用户可以使用此方法。支持广泛,基于L2TPv3标准,Linux内核3.2+都有支持,其他操作系统原则上也能支持。但有两个局限:需要root权限;一个隧道只支持一个用户。

朴素VPN利用UDP封装的静态L2TP隧道实现VPN,内核XFRM实现静态IPsec。实际上IP-in-IP隧道即可实现VPN,但是这种协议无法穿越NAT,因此必须利用UDP封装。内核3.18将支持Foo-over-UDP,在UDP里面直接封装IP,与静态的L2TP-over-UDP很类似。

创建一个朴素VPN