Skip to content

Instantly share code, notes, and snippets.

@kylekyle
kylekyle / status.py
Last active January 23, 2016 18:39
Return a health monitoring status
''' Add to jupyter_notebook_config.py
import sys
sys.path.append("/root/.jupyter/extensions/")
c.NotebookApp.reraise_server_extension_failures = True
c.NotebookApp.server_extensions = ['status']
'''
from notebook.utils import url_path_join
from notebook.base.handlers import IPythonHandler
@kylekyle
kylekyle / integration.js
Created January 24, 2016 00:58
A remote script for Jupyter
Jupyter.notification_area.get_widget("notebook").set_message("Extension loaded!");
@kylekyle
kylekyle / jupyter_kernel.js
Last active March 1, 2016 05:09
How to communicate with a Jupyter kernel directly
Jupyter.notebook.kernel.execute("puts 'hello world'", {
iopub : {
output : function(response) {
console.log(response);
}
}
});
@kylekyle
kylekyle / doc.rb
Created March 4, 2016 06:27
Dynamically generate docs from a gem
require 'zlib'
require 'yard'
require 'tmpdir'
require 'stringio'
require 'fileutils'
require 'archive/tar/minitar'
io = StringIO.new File.read('sequel-4.32.0.gem')
catch :finished do

The following block renders as ruby even though no language is specified:

def method
  puts "a method!"
end
 :~$ This text is always clobbered by the YARD parser
# https://porkrind.org/missives/calling-applescript-from-ruby/
def osascript(script)
system 'osascript', *script.split(/\n/).map { |line| ['-e', line] }.flatten
end
# http://stackoverflow.com/questions/5292204/macosx-get-foremost-window-title
osascript <<-END
global frontApp, frontAppName, windowTitle
set windowTitle to ""
{
"*" : [
["exec", "echo 'exec works!'"],
["eval", "puts 'eval works!'"]
],
"iruby" : [
["eval", "puts 'gems work!'"],
["gem", "metaid"]
],
"metaid": [
def cropPicture(picture):
smallPic = makeEmptyPicture(186,100)
smallX = 0
smallY = 0
for x in range(59,244):
smallX +=1
smallY = 0
for y in range(25,125):
pixel = getPixel(picture,x,y)
smallPicPixl = getPixel(smallPic,smallX,smallY)
@kylekyle
kylekyle / mypki-xpe.rb
Created January 21, 2018 21:46
How to attach information to a TCPSocket for the OpenSSL context later on
require 'socket'
class TCPSocket
class << self
def new host, *args, &block
socket = super host, *args, &block
# check whitelist, set indicator
socket.instance_variable_set :@mypki, true # or false
# return socket
socket
@kylekyle
kylekyle / pull_posts.rb
Last active March 19, 2018 20:38
Pull all of a friends Facebook posts
require 'json'
require 'watir'
require 'seconds'
if ARGS.empty?
warn 'Please provide the Facebook user number and query string that will appear in every post (first name usually works)'
exit
end
b = Watir::Browser.new