Skip to content

Instantly share code, notes, and snippets.

View kylewelsby's full-sized avatar
🏠
Working from home

Kyle Welsby kylewelsby

🏠
Working from home
View GitHub Profile
module Sequares
module Store
class Redis < Base
attr_accessor :connection
def initialize(connection=::Redis.new)
@connection = connection
end
def filter_events(*klasses)
require 'byebug'
require 'active_support/inflector'
module Sequares
module Store
class Memory < Base
class << self
def cache_key_for(klass, id)
inst = klass.with_history(id, [])
"#{inst.uri}|#{histories}"
end
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<div style="display:none;">
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
function promiseHash (hash) {
var promises = []
Object.keys(hash).map(function (key, index) {
return promises[index] = hash[key]
})
return Promise.all(promises).then(function (resolved) {
var response = {}
Object.keys(hash).map(function (key, index) {
response[key] = resolved[index]
})
@kylewelsby
kylewelsby / promise-when.js
Created September 23, 2015 18:45
wait until condition is met before resolving promise.
// setup
var value = false;
setTimeout(function(){
value = true;
}, 1998);
// code
function promiseWhen(condition, timeout){
if(!timeout){
@kylewelsby
kylewelsby / vnc.sh
Created March 25, 2015 06:18
quick setup vnc server with google chrome
apt-get update
apt-get install xfce4 xfce4-goodies tightvncserver
vncserver
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
apt-get install -f
@kylewelsby
kylewelsby / index.html
Last active October 10, 2016 23:20
postMessage Example
<html>
<head>
<script>
var count=0;
function sendMessage() {
window.parent.postMessage(
JSON.stringify({"greeting": "hello world"}), // A stringified message to send.
"*" // The intended origin, in this example we use the any origin wildcard.
);
}
@kylewelsby
kylewelsby / get_element_detail.js
Last active August 29, 2015 14:01
useful function to get an HTML Element detail as an object.
window.HTMLElementDetail = function(elm) {
var rect = elm.getBoundingClientRect(),
style = window.getComputedStyle(elm, null);
return {
textContent: elm.textContent || elm.innerText,
selector: document.generateSelector([elm]),
css: {
top: (rect.top + window.scrollY) + 'px',
left: (rect.left + window.scrollX) + 'px',
//right: rect.right + 'px',
@kylewelsby
kylewelsby / _README.md
Last active July 25, 2022 06:25
Socket.io joining a room

I client connects to a sever specifying a room they wish to join, that client is then binded to that one and only room.

The server broadcasts a event to the room, forwarding the message on to any other connected clients.

In the below example connected_client.js is listening to any messages, and will log the output.

[message]: {"room": "anything", "greeting": "Hello world"}

Keybase proof

I hereby claim:

  • I am kylewelsby on github.
  • I am kylewelsby (https://keybase.io/kylewelsby) on keybase.
  • I have a public key whose fingerprint is BAE4 5523 FA41 030F E676 E750 3962 1A0D 2656 03A4

To claim this, I am signing this object: