Skip to content

Instantly share code, notes, and snippets.

View rudolph9's full-sized avatar

Kurt Robert Rudolph rudolph9

  • Portland, OR, USA
View GitHub Profile
@rudolph9
rudolph9 / wait.js
Last active July 8, 2018 01:57
A simple wait function that returns and promise and puts the waiting macro task queue
const wait = callback => new Promise((resolve, reject) => {
const end = () => {
try {
if (callback()) {
resolve(true);
} else {
setImmediate(end);
}
} catch (error) {
reject(error);
@rudolph9
rudolph9 / example.js
Created April 26, 2018 00:41
showing awit is not synchronous
class Foo {
constructor(foo) {
this.foo = foo
}
async execUntilStop(callback) {
const timeoutLoopCallback = () => {
if (this.stopExec) return;
callback({ data: 'data' });
setTimeout(timeoutLoopCallback, 10);
@rudolph9
rudolph9 / gist:908a23019ad471ef86d3
Last active August 29, 2015 14:06
A good example of javascript prototypal functions.
> Node = function(){};
[Function]
> Node.pro
Node.propertyIsEnumerable
Node.prototype
> Node.prototype.foo = {bar: 'hello world'};
{ bar: 'hello world' }
> node = new Node();

Iterating Iteratively

Given a forward linked list, define an iterator wich traverses each node in the linked list calling next function repeatively?

com.write_message( ("\x02" + 6.chr + "AE5X:W" + ("AE5X:W" ^ 6.chr) + "\x03").force_encoding("ASCII-8BIT"))
class ::String
###
# @return the first charater in the string as an integer
def byte
self.bytes[0]
end
###
@rudolph9
rudolph9 / gist:5784015
Created June 14, 2013 18:09
reverses a string
#include <stdio.h>
#include <string.h>
int main ()
{
char str0[]="Hello world";
char str1[40];
int str0_length = strlen(str0);
int i;
for( i = 1 ; i <= str0_length ; i++)
@rudolph9
rudolph9 / gist:5751446
Created June 10, 2013 19:22
MicroAeth
>>> microAeth = serial.Serial('/dev/ttyUSB1', 500000, timeout=1, parity=serial.PARITY_MARK)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/serial/serialutil.py", line 261, in __init__
self.open()
File "/usr/local/lib/python2.7/dist-packages/serial/serialposix.py", line 282, in open
self._reconfigurePort()
File "/usr/local/lib/python2.7/dist-packages/serial/serialposix.py", line 376, in _reconfigurePort
raise ValueError('Invalid parity: %r' % self._parity)
ValueError: Invalid parity: 'M'
def link_to(text, address)
"<a href='#{ address }'>#{ text }</a>"
end
def content_tag tag, &block
"<#{ tag.to_s }>#{ block.call }</#{ tag.to_s}>"
end
@rudolph9
rudolph9 / pig_latin.rb
Last active December 14, 2015 17:48
PigLatin
def translate string
string.gsub( /((?:(?:qu))*[^aeiou]*)(\w*)/, '\2\1') + 'ay'
end
@rudolph9
rudolph9 / method_overloading
Created September 27, 2012 14:45
Ruby Method Overloading Example
[1] pry(main)> puts "hello world!"
hello world!
=> nil
[2] pry(main)> class << self
[2] pry(main)* def puts string
[2] pry(main)* print "overloaded! " + string + "\n"
[2] pry(main)* end
[2] pry(main)* end
=> nil
[3] pry(main)> puts "hello world!"