Skip to content

Instantly share code, notes, and snippets.

@DougEverly
DougEverly / gist:3341851
Created August 13, 2012 15:26
Open current Safari URL in Webkit
property theURL : ""
tell application "Safari"
set theURL to URL of current tab of window 1
end tell
tell application "WebKit"
make new document
set URL of document 1 to theURL
activate
end tell
@DougEverly
DougEverly / gist:3966598
Created October 27, 2012 22:08
First .coffee
class Car
constructor: (@make) ->
make: -> @make
drive: (m) -> "went #{m} miles"
taurus= new Car("ford")
console.log(taurus.make)
@DougEverly
DougEverly / gist:4360672
Created December 22, 2012 19:47
In PHP, instance variables (properties) and instance methods (functions) can have same names. Getter function names can be the same as the private instance variable.
<?php
class Test
{
private $m = "this is property m\n";
public function m()
{
return $this->m;
}
@DougEverly
DougEverly / gist:6663883
Created September 22, 2013 21:14
jruby semaphore using java
sem = java.util.concurrency.Semaphore.new 10
irb(main):024:0> sem.to_s
=> "java.util.concurrent.Semaphore@79f1a8a[Permits = 10]"
irb(main):025:0> sem.acquire
=> nil
irb(main):026:0> sem.to_s
=> "java.util.concurrent.Semaphore@79f1a8a[Permits = 9]"
irb(main):027:0> sem.acquire
@DougEverly
DougEverly / gist:8448129
Created January 16, 2014 01:22
Some Ruby code to read a script using character voices. Works in Mac OS X. Some voices may need to be downloaded in System Prefs.
#!/bin/env/ruby
@script = <<THE_END
Veronica Corningstone: Excuse me.
Ron Burgundy: What are you doing?
Veronica Corningstone: I need this machine so I can watch a tape for a story.
Ron Burgundy: I'm using the tape. I'm showing Jeffrey my Emmy tape. We are watching history.
Veronica Corningstone: Mr. Burgundy, I'm a professional, and I would like to be able to do my job.
Ron Burgundy: Big deal. I am very professional.
Veronica Corningstone: Mr. Burgundy, you are acting like a baby.
<?php
/**
* UUID class
*
* The following class generates VALID RFC 4211 COMPLIANT
* Universally Unique IDentifiers (UUID) version 3, 4 and 5.
*
* UUIDs generated validates using OSSP UUID Tool, and output
* for named-based UUIDs are exactly the same. This is a pure
* PHP implementation.
@DougEverly
DougEverly / restart_children.rb
Last active August 29, 2015 14:16
Restart children if they die
#!/usr/bin/env ruby
@jobs = [
"sleep 1",
"sleep 2",
"sleep 3",
"sleep 4"
]
@running_jobs = Hash.new
@DougEverly
DougEverly / restart_children_wait.rb
Created March 2, 2015 18:33
Restart children if they die using Process.wait2
#!/usr/bin/env ruby
@jobs = [
"sleep 1",
"sleep 2",
"sleep 3",
"sleep 4"
]
@running_jobs = Hash.new
@DougEverly
DougEverly / curl.cr
Created May 1, 2015 20:42
Crystal calling libcurl
@[Link("curl")]
lib LibCurl
type CURL = Void*
type CURLoption = Int32
fun create = curl_easy_init(): CURL
fun set_opt = curl_easy_setopt(CURL, Int32, UInt8*)
fun get = curl_easy_perform(CURL)
fun cleanup = curl_easy_cleanup(CURL)
@DougEverly
DougEverly / heart_pyramid.rb
Created February 14, 2016 17:14
Happy Valentine's Day!
50.times do |i|
width = 50
rest = width - i
first = rest / 2
first += 1 if (i % 2 == 1)
last = rest /2
puts ("💙" * first) + ("💚" * i) + ("💜" * last)
end