Skip to content

Instantly share code, notes, and snippets.

View zhanglintc's full-sized avatar
🐦
Working from home

Lane zhanglintc

🐦
Working from home
View GitHub Profile
@fnichol
fnichol / README.md
Created March 12, 2011 20:52
Download a cacert.pem for RailsInstaller

Why?

There is a long standing issue in Ruby where the net/http library by default does not check the validity of an SSL certificate during a TLS handshake. Rather than deal with the underlying problem (a missing certificate authority, a self-signed certificate, etc.) one tends to see bad hacks everywhere. This can lead to problems down the road.

From what I can see the OpenSSL library that Rails Installer delivers has no certificate authorities defined. So, let's go fetch some from the curl website. And since this is for ruby, why don't we download and install the file with a ruby script?

Installation

The Ruby Way! (Fun)

@markhuge
markhuge / bottle-jsonp.py
Created March 2, 2013 21:56
Dynamically Serving JSONP with bottle.py
# This will return either JSON or JSONP depending on the existence of a callback.
def jsonp(request, dictionary):
if (request.query.callback):
return "%s(%s)" % (request.query.callback, dictionary)
return dictionary
@route('/something')
def something():
return jsonp(dict(success="It worked"))
@viliampucik
viliampucik / pgrep.pl
Created March 21, 2013 12:39
Perl's zgrep
#!/usr/bin/env perl
use strict;
use warnings;
use PerlIO::gzip;
my $pattern = $ARGV[0];
my $file = $ARGV[1];
open my $z, '<:gzip', $file or die "gunzip failed: $!\n";
while ( <$z> ) {
print if /$pattern/i;
@jwilm
jwilm / mongodb.service
Created June 22, 2013 22:49
MongoDB systemd service unit configuration
[Unit]
Description=MongoDB Database Service
Wants=network.target
After=network.target
[Service]
Type=forking
PIDFile=/var/run/mongodb/mongod.pid
ExecStart=/usr/local/bin/mongod --config /etc/mongod.conf
ExecReload=/bin/kill -HUP $MAINPID
@fpfeng
fpfeng / v2ex_auto_login.py
Last active June 10, 2023 16:54
登录 V2EX 领取每日奖励
# -*- coding: utf-8 -*-
from bs4 import BeautifulSoup
import requests
username = '' ###账号###
password = '' ###密码###
login_url = 'http://v2ex.com/signin' ###如V2EX设置了使用 SSL,必须改 https###
index_url = 'http://v2ex.com' ###同上###
mission_url = 'http://www.v2ex.com/mission/daily' ###同上###
UA = "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) \
@joyrexus
joyrexus / README.md
Last active June 8, 2024 00:43
Perl one-liners

Hi:

perl -e 'print "hello world!\n"'

A simple filter:

perl -ne 'print if /REGEX/'

Filter out blank lines (in place):

@TakahikoKawasaki
TakahikoKawasaki / sinatra+thin+ssl.rb
Last active October 19, 2023 14:38
Sinatra + Thin + SSL
#!/usr/bin/env ruby
#
# This code snippet shows how to enable SSL in Sinatra+Thin.
#
require 'sinatra'
require 'thin'
class MyThinBackend < ::Thin::Backends::TcpServer
def initialize(host, port, options)