Skip to content

Instantly share code, notes, and snippets.

View imwilsonxu's full-sized avatar

Wilson imwilsonxu

View GitHub Profile
@imwilsonxu
imwilsonxu / demo.js
Created October 31, 2016 05:58
Auto highlight selected value for bootstrap-select.
(function() {
$(".selectpicker").on("loaded.bs.select", function(e) {
if ($(this).val() > 0) {
$(this).selectpicker('setStyle', 'btn-warning', 'add');
}
}).on("changed.bs.select", function(e) {
if ($(this).val() > 0) {
$(this).selectpicker('setStyle', 'btn-warning', 'add');
} else {
$(this).selectpicker('setStyle', 'btn-warning', 'remove');
@imwilsonxu
imwilsonxu / app.py
Last active May 13, 2019 03:41
[极验验证 + 云片短信 + Flask + WTForms] #flask
# -*- coding: utf-8 -*-
import re, requests, httplib, urllib, json
from flask import Flask, render_template, session, request, jsonify, current_app
from flask_wtf import Form
from wtforms import Field, StringField, SubmitField
from wtforms.validators import DataRequired, Regexp
from wtforms.widgets import TextInput, HTMLString
@imwilsonxu
imwilsonxu / app.py
Last active February 16, 2023 04:57
[Flask + Wtforms + Select2] #flask
# -*- coding: utf-8 -*-
from flask import Flask, request, render_template, current_app
from flask_wtf import Form
from wtforms.validators import DataRequired
from wtforms import SelectField, SelectMultipleField, SubmitField
app = Flask(__name__)
@imwilsonxu
imwilsonxu / SetTimeOfDayColors.vim
Created July 19, 2013 16:04
Set Vim colorscheme by time of day, an example from book Learning Vi and Vim.
function SetTimeOfDayColors()
let g:Favcolorschemes = ["darkblue", "morning", "shine", "evening"]
let g:CurrentHour = (strftime("%H") + 0) / 6
if g:colors_scheme !~ g:Favcolorschemes[g:CurrentHour]
execute "colorscheme " . g:Favcolorschemes[g:CurrentHour]
redraw
endif
endfunction
@imwilsonxu
imwilsonxu / count-word-freq.sh
Last active October 18, 2016 07:52
Extended Doug McIlroy's program from book "Classic Shell Scripting" to process a text file, and output a list of the n most-frequent words, with counts of their frequency of occurrence, sorted by descending count.
#! /bin/sh -
# Read a text stream on standard input, and output a list of
# the n (default: 25) most frequently occurring words and
# their frequency counts, in order of descending counts, on
# standard output.
#
# Usage:
# wf [n]
tr -cs A-Za-z\' '\n' | # Replace nonletters with newlines
import pyPdf
from StringIO import StringIO
#----------------------------------------------------------------------
def mergePDFs(pdfOne, pdfTwo):
"""
Merge PDFs
"""
tmp = StringIO()
@imwilsonxu
imwilsonxu / compare-md5-with-bcrypt.rb
Created September 24, 2012 09:16
Compare md5 with bcrypt
require 'benchmark'
require 'bcrypt'
password = 'Shh...'
amount = 100
Benchmark.bmbm(20) do |run|
run.report("Bcrypt(10)") do
amount.times do
@imwilsonxu
imwilsonxu / gmail.rb
Created August 22, 2012 07:52
Send Email With Ruby
# -*- coding: utf-8 -*-
# Usage:
# export gmail_username=xxx
# export gmail_password=yyy
# ruby gmail.rb
require 'rubygems'
require 'mail'