This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$MY_PHONE_NUMBERS = [] #Fill this out! | |
if RAILS_ENV != "production" | |
require 'twilio' | |
Twilio::Call.class_eval do | |
alias_method :old_make, :make | |
def make(caller, callee, url, options = {}) | |
unless $MY_PHONE_NUMBERS.map {|num| num.gsub(/[^0-9+]/, "")}.include? callee.gsub(/[^0-9+]/, "") | |
raise "Trying to call a number which you do not own. (Safety measure for non-production environments.)" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Hiya guys, | |
#I'm Patrick McKenzie (patio11 on HN) and I'm doing this just out of joy of programming puzzles. | |
#Not really looking for a job at the moment. | |
# | |
#I've taken some liberty with standard Ruby programming conventions to make this one file without | |
#dependencies, for the ease of you actually running it. It is the result of a very hack-in-progress | |
#sort of workflow. A git repo showing my work in stages might be more interesting but, well, | |
#hard to submit that into the form. | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#This code is MIT licensed. | |
module ActionView | |
module Helpers | |
module AssetTagHelper | |
require 'jsminlib' #Google it. Paste into RAILS_ROOT/libs. Note: not MIT license (has a "This code should be used for good, not evil" rider -- ask your lawyers if they care). | |
def compress_css(source) | |
source.gsub!(/\s+/, " ") # collapse space | |
source.gsub!(/\/\*(.*?)\*\/ /, "") # remove comments |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// When I was working on our React/Flummox app I got to the point where, per the docs, I had ~100 lines of code | |
// which were substantially predictable boilerplate, so I used some JS metaprogramming to condense them by 80%. | |
// Flummox docs: http://acdlite.github.io/flummox | |
// I use underscore.js below for utility but you can also just do a for loop. | |
class AppFlux extends Flux { | |
constructor() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def open_flash_chart(height, width, data_url, div_name = nil) | |
options = {} | |
options[:height] = height | |
options[:width] = width | |
options[:swf_file_name] = "flash/open-flash-chart.swf" | |
options[:div_name] = div_name unless div_name.nil? | |
open_flash_chart_object_from_hash(data_url, options) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#This solves the maze using regular expressions, because I am too | |
#lazy to worry about arrays, darn it. It is inefficient as heck and designed | |
#purely to demonstrate perversion of sound CS principals. | |
# | |
# Code by Patrick McKenzie, 2010. I release this work unto the public domain. | |
class Maze | |
def initialize(maze_string) | |
@width = maze_string.split("\n")[0].length #width of maze in characters | |
@guts = maze_string.gsub("\n", "") #maze as a flat string -- no newlines |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
hoge = "これは例である。" | |
puts hoge[1] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* robotMaze.js | |
* | |
* The blue key is inside a labyrinth, and extracting | |
* it will not be easy. | |
* | |
* It's a good thing that you're a AI expert, or | |
* we would have to leave empty-handed. | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The wrong way to do things: | |
for { | |
switch { | |
case <- channelA: | |
doSomething() | |
case <- channelB: | |
doSomethingElse() | |
default: | |
// Do nothing. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#The task is replacing the port number in the URL string | |
//in golang | |
import "fmt" | |
import "strings" | |
func main() { | |
url := "http://localhost:8080/foo/bar" | |
fmt.Println(strings.Replace(url, "8080", "8181", -1)) | |
} |