Skip to content

Instantly share code, notes, and snippets.

@kascote
kascote / app.js
Created June 23, 2014 21:14 — forked from skypanther/app.js
var Utils = {
/* modified version of https://gist.github.com/1243697
* adds detection of file extension rather than hard-coding .jpg as in the original
*/
_getExtension: function(fn) {
// from http://stackoverflow.com/a/680982/292947
var re = /(?:\.([^.]+))?$/;
var tmpext = re.exec(fn)[1];
return (tmpext) ? tmpext : '';
},
@kascote
kascote / Rakefile
Created August 9, 2014 22:34 — forked from fstrube/Rakefile
# Include all rake files in the tasks directory
Dir.glob('tasks/*.rake').each { |r| import r }
# Read configuration from tasks/config.yaml
require 'yaml'
CONFIG = YAML.load_file('tasks/config.yaml')[ENV['env'] || 'development']
# Default utility functions available in all tasks
def ok_failed(condition)
if (condition)
#encoding: UTF-8
require 'rubygems'
require "pismo"
require 'punkt-segmenter'
require 'htmlentities'
require './markov.rb'
CLEAN_TEXT = <<-EOF
@kascote
kascote / .pryrc
Created August 28, 2014 18:36 — forked from justin808/.pryrc
## Useful Collections
def a_array
(1..6).to_a
end
def a_hash
{hello: "world", free: "of charge"}
end
@kascote
kascote / color_luminance
Created March 14, 2015 18:48
Calculate Lighter or Darker Hex Colors
#
# Examples:
# color_luminance("#69c", 0); # returns "#6699cc"
# color_luminance("6699CC", 0.2); # "#7ab8f5" - 20% lighter
# color_luminance("69C", -0.5); # "#334d66" - 50% darker
# color_luminance("000", 1); # "#000000" - true black cannot be made lighter!
#
# based on code from
# http://www.sitepoint.com/javascript-generate-lighter-darker-color/
#
# Natively, Enumerators get JSONized like "#<Enumerator::Lazy:0x007f8714807080>", or they explode, either of which is a problem.
# We want them to make an array, and do it lazily so we don't have to keep the items in memory!
class Enumerator
def to_json(state)
state.depth += 1
string = "[\n"
first_item = true
self.each do |item|
@kascote
kascote / full_text_search.sql
Last active February 16, 2016 22:02
Postgres Full Text Search
CREATE TABLE messages (
title text,
body text,
tsv tsvector
);
CREATE TRIGGER tsvectorupdate BEFORE INSERT OR UPDATE
ON messages FOR EACH ROW EXECUTE PROCEDURE
tsvector_update_trigger(tsv, 'english', title, body);
@kascote
kascote / config.ru
Created November 2, 2016 20:35
Rails 2.3.x. config.ru to use with passenger for example
# Reference: http://guides.rubyonrails.org/v2.3.11/rails_on_rack.html#rackup
#
ENV["RAILS_ENV"] ||= ENV["RACK_ENV"]
# Require your environment file to bootstrap Rails
require ::File.dirname(__FILE__) + '/config/environment'
# Serve static assets from RAILS_ROOT/public directory
# use Rails::Rack::Static
# Dispatch the request
run ActionController::Dispatcher.new
@kascote
kascote / sql.sh
Created May 24, 2017 19:15
Parse Rails's database.yml and start psql
#!/bin/bash
parse_yaml() {
local prefix=$2
local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @|tr @ '\034')
sed -ne "s|^\($s\)\($w\)$s:$s\"\(.*\)\"$s\$|\1$fs\2$fs\3|p" \
-e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $1 |
awk -F$fs '{
indent = length($1)/2;
vname[indent] = $2;
@kascote
kascote / dnsmasq
Last active July 22, 2017 22:39
add TLD to local dnsmask
# /etc/NetworkManager/dnsmasq.d/hosts.conf
address=/dev/127.0.0.1
address=/spk/192.168.1.98
address=/nfx/192.168.1.99
address=/spk2/192.168.1.97