Skip to content

Instantly share code, notes, and snippets.

View dwickwire's full-sized avatar

Derek Wickwire dwickwire

View GitHub Profile
'''
Problem:
Given a set of points on a cartesian plane with x,y points, find the number of rectangles among the points given.
Clarifications:
- Rectangles can include squares.
- Rectangles must span more than one row or column.
- Rectangles can be angled at 45, 90 and 135 degrees.
- Each unique rectangle should only be counted once.
import os
import requests
for file in os.listdir('.'):
if not file.endswith('.txt'):
continue
with open(file, 'r') as f:
base = f.readlines()
@dwickwire
dwickwire / selectize_no_results.js
Last active February 27, 2024 11:38 — forked from mudassir0909/selectize_no_results.js
A selectize plugin to display "No results found." message.
$(document).ready(function() {
/*
https://github.com/brianreavis/selectize.js/issues/470
Selectize doesn't display anything to let the user know there are no results.
This plugin allows us to render a no results message when there are no
results are found to select for.
*/
Selectize.define( 'no_results', function( options ) {
var self = this;
@dwickwire
dwickwire / spelling.py
Created January 28, 2014 05:39
Spelling algorithm by Peter Norvig.
# Probability of a spelling correction, c =
# Probability(c is a word) *
# Probability(original is a typo for c)
# Best correction =
# one with highest probability
# Probability(c is a word) =
# estimated by counting
# Probability(original is a typo for c) =
# proportional to number of changes
@dwickwire
dwickwire / segmentation.py
Last active November 5, 2018 10:02
Word segmentation from Peter Norvig.
# Probability of a segmentation =
# Probability(first word) * Probability(rest)
# Best segmentation =
# one with highest probability
# Probability(word)
# estimated by counting
# Eg. Best segmentation("nowisthetime...")
# Pf("n") * Pr("owisthetime...") = .003% * 10^-30% = 10^-34%
# Pf("no") * Pr("wisthetime...") = .26% * 10^-26% = 10^-29%
@dwickwire
dwickwire / .gitconfig
Created December 6, 2013 15:41
Git config for coloring and so on, goes into ~/.gitconfig
[alias]
co = checkout
br = branch
ci = commit
st = status
deploytag = "!git tag deploy-`date \"+%Y%m%d%H%M\"` && git push --tags"
switch = !legit switch \"$@\"
branches = !legit branches
sprout = !legit sprout \"$@\"
unpublish = !legit unpublish \"$@\"
#!/bin/sh
# Converts a mysqldump file into a Sqlite 3 compatible file. It also extracts the MySQL `KEY xxxxx` from the
# CREATE block and create them in separate commands _after_ all the INSERTs.
# Awk is choosen because it's fast and portable. You can use gawk, original awk or even the lightning fast mawk.
# The mysqldump file is traversed only once.
# Usage: $ ./mysql2sqlite mysqldump-opts db-name | sqlite3 database.sqlite
# Example: $ ./mysql2sqlite --no-data -u root -pMySecretPassWord myDbase | sqlite3 database.sqlite
@dwickwire
dwickwire / recursive_traversal.rb
Last active December 10, 2015 00:59
This method can iterate over a big diverse data-set and return the hash which matches the field value.
@fields = [{
:foo => [
1,
2,
[
3,
{:field => 'oranges', :options =>{ :label => "Oranges"}}
],
{:a => {:zaz => 42}},
[
require 'awesome_print'
hash = {
"key_one" => {
"sub_key_one_a" => {
"sub_sub_key_one_a" => "hello I'm sub sub key one a"
},
"sub_key_one_b" => {
"sub_sub_key_one_b" => "hello I'm sub sub key one b",
"sub_sub_sub_key_one_b" => {
def select_lookup(val, select)
return nil if val.nil? || val.blank?
from_select = select.find{|s| s.include? val}
return (!from_select.nil?) ? from_select[0] : val
end