Skip to content

Instantly share code, notes, and snippets.

View mech's full-sized avatar
🏠
Working from home

mech mech

🏠
Working from home
  • Career Pacific / Jobline
  • Singapore, Tampines
View GitHub Profile
#!/usr/bin/env python2
# Quick and dirty demonstration of CVE-2014-0160 by Jared Stafford (jspenguin@jspenguin.org)
# The author disclaims copyright to this source code.
import sys
import struct
import socket
import time
import select
# Nginx+Unicorn best-practices congifuration guide. Heartbleed fixed.
# We use latest stable nginx with fresh **openssl**, **zlib** and **pcre** dependencies.
# Some extra handy modules to use: --with-http_stub_status_module --with-http_gzip_static_module
#
# Deployment structure
#
# SERVER:
# /etc/init.d/nginx (1. nginx)
# /home/app/public_html/app_production/current (Capistrano directory)
#
{
"query": {
"function_score": {
"query": {
"bool": {
"must": {
"multi_match": {"query": "Renaissance", "fields": ["name", "company"]},
"term": {"features": "disability_access"},
},
"should": {
@mech
mech / exercise.js
Last active August 29, 2015 14:21 — forked from ryanflorence/exercise.js
import React from 'react'
import assign from 'object-assign'
var styles = {}
class Autocomplete extends React.Component {
static propTypes = {
initialValue: React.PropTypes.any,
onChange: React.PropTypes.func,
#!/bin/bash
# Unattended REE/Passenger installation
# Source: http://weblog.brightlight-ict.nl/2008/12/unattended-passenger-ruby-enterprise-installation-on-ubuntu-8/
# 15/03/09 Updated to use latest r.e.e. and passenger 2.1 and rewrote bits thanks to the comments left on my blog. Thanks guys
if [ "$(whoami)" != "root" ]; then
echo "You need to be root to run this!"
exit 2
fi
class ActiveRecord::Base
def self.find_values opts
sql = self.send(:construct_finder_sql, opts)
self.connection.select_values(sql)
end
end
>> Tagging.find_values(:select => :taggable_id, :limit => 30, :order => 'tagged_at asc')
=> ["1", "3", "6", "6", "6", "10", "10", "10", "11", "11", "11", "10", "10", "10", "10", "10", "13", "13", "13", "13", "13", "13", "15", "15", "15", "15", "15", "15", "15", "15"]
@mech
mech / gist:137597
Created June 29, 2009 12:25 — forked from dhh/gist:29752
config.action_controller.asset_host = Proc.new do |source, request|
non_ssl_host = "http://asset#{source.hash % 4}.backpackit.com"
ssl_host = "https://asset1.backpackit.com"
if request.ssl?
case
when source =~ /\.js$/
ssl_host
when request.headers["USER_AGENT"] =~ /(Safari)/
non_ssl_host
# download and git methods swiped from http://github.com/Sutto/rails-template/blob/07b044072f3fb0b40aea27b713ca61515250f5ec/rails_template.rb
require 'open-uri'
def download(from, to = from.split("/").last)
#run "curl -s -L #{from} > #{to}"
file to, open(from).read
rescue
puts "Can't get #{from} - Internet down?"
exit!
desc 'Print out all defined routes in match order, with names. Target specific controller with CONTROLLER=x.'
task :routes => :environment do
all_routes = ENV['CONTROLLER'] ? ActionController::Routing::Routes.routes.select { |route| route.defaults[:controller] == ENV['CONTROLLER'] } : ActionController::Routing::Routes.routes
routes = all_routes.collect do |route|
name = ActionController::Routing::Routes.named_routes.routes.index(route).to_s
verb = route.conditions[:method].to_s.upcase
segs = route.segments.inject("") { |str,s| str << s.to_s }
segs.chop! if segs.length > 1
reqs = route.requirements.empty? ? "" : route.requirements.inspect
{:name => name, :verb => verb, :segs => segs, :reqs => reqs}
# download, from_repo, and commit_state methods swiped from
# http://github.com/Sutto/rails-template/blob/07b044072f3fb0b40aea27b713ca61515250f5ec/rails_template.rb
require 'open-uri'
def download(from, to = from.split("/").last)
#run "curl -s -L #{from} > #{to}"
file to, open(from).read
rescue
puts "Can't get #{from} - Internet down?"