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
import "sync" | |
type Channel struct { | |
... | |
messages []*Message | |
listeners []chan *Message | |
sync.Mutex | |
} | |
... |
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
type Account struct { | |
balance float64 | |
... | |
sync.Mutex | |
} | |
func (a *Account) Deposit(amount float64) { | |
a.Lock() | |
defer a.Unlock() |
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
select { | |
case <- messageListener: | |
newData = c.GetMessages(offset) | |
listener <- newData | |
case <- time.After(ChannelTimeoutSec * time.Second): | |
listener <- ReturnDataEmpty | |
} |
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 main(): | |
import aksfjaslkdfj | |
aksfjaslkdfj.blahblah | |
blah + blah2 | |
blah3() |
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
# Configure a canvas element for high-def screens (retina) | |
highDefCanvas = (canvas, context) -> | |
pixel_ratio = window.devicePixelRatio | |
if pixel_ratio | |
width = canvas.width | |
height = canvas.height | |
canvas.width = width * pixel_ratio | |
canvas.height = height * pixel_ratio | |
canvas.style.width = "#{width}px" | |
canvas.style.height = "#{height}px" |
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
""" | |
Groups (clusters) similar lines together from a text file | |
using k-means clustering algorithm. | |
Also does some simple cleaning (such as removing white space and replacing numbers with (N)). | |
Example: | |
python cluster_lines.py --clusters 20 invalid_dates.txt |
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 add_job(self, job_type, job_id=None, on_duplicate='overwrite', | |
timestamp=None, distribute=None, **data): | |
""" | |
Add a new job to execute | |
:param job_type: string with the name of the job | |
:param job_id: job identifier, if not set, then a new random unique id | |
will be generated | |
:param on_duplicate: action on identifier duplicate, can be "overwrite" | |
or "discard" |
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
-- List functions | |
-- | |
-- | |
LIST_DELIM = "~" | |
function list_add(key, value) | |
--- Determine the limit by inspecting if | is in the key | |
local limit = 200 | |
if string.find(key, '|') then |
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
class ModelCounter | |
constructor: (@value=1) -> | |
increaseValue: (delta) => | |
@value += delta | |
class ControllerCounter | |
constructor: (opts) -> |
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
# Store | |
class CounterStore extends EventEmitter | |
constructor: -> | |
@count = 0 | |
@dispatchToken = @registerToDispatcher() | |
increaseValue: (delta) -> | |
@count += 1 |