Skip to content

Instantly share code, notes, and snippets.

View yonran's full-sized avatar

Yonathan Randolph yonran

View GitHub Profile
@yonran
yonran / content_script.js
Created April 21, 2011 18:06 — forked from anonymous/background.html
Message Passing attempt
chrome.extension.onRequest.addListener(
function(request, sender, sendResponse) {
console.log(sender.tab ?
"from a content script:" + sender.tab.url :
"from the extension");
if (request.greeting == "hello")
sendResponse({farewell: "goodbye"});
else
sendResponse({}); // snub them.
});
import static org.junit.Assert.assertEquals;
import java.io.BufferedReader;
import java.io.StringReader;
import java.util.Collection;
import org.junit.Test;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
@yonran
yonran / test.rs
Last active December 24, 2015 02:29
Rust: cannot assign to `(*self).count` because it is borrowed
use std::util;
struct Bar;
struct Foo {
test: bool,
count: int,
bar: Bar,
}
impl Foo {
@yonran
yonran / test.rs
Created October 1, 2013 00:10
Rust: can a struct hold a borrowed reference to its owner?
struct Foo {
bar: ~Bar
// ^~~ error: Illegal anonymous lifetime: anonymous lifetimes are not permitted here
}
struct Bar<'self> {
owner: &'self Foo
// ^~~ error: Illegal anonymous lifetime: anonymous lifetimes are not permitted here
}
// Note that if Bar has _any_ borrowed reference (not just to a Foo),
@yonran
yonran / TestPeripheral.m
Created December 19, 2013 00:35
Bluetooth LE Peripheral Role hello world based on [Performing Common Peripheral Role Tasks](https://developer.apple.com/library/mac/documentation/NetworkingInternetWeb/Conceptual/CoreBluetooth_concepts/PerformingCommonPeripheralRoleTasks/PerformingCommonPeripheralRoleTasks.html). When I run this program on a Mac Mini, the peripheral is advertisi…
#import <Foundation/Foundation.h>
#import <IOBluetooth/IOBluetooth.h>
enum HandlerState {
HandlerStateStarting,
HandlerStateWaitingForServiceToAdd,
HandlerStateWaitingForAdvertisingToStart,
HandlerStateAdvertising,
HandlerStateError,
};
@yonran
yonran / pulse.txt
Created March 17, 2014 16:51
lsusb -v for Livescribe Pulse
Bus 004 Device 043: ID 1cfb:1010
Device Descriptor:
bLength 18
bDescriptorType 1
bcdUSB 2.00
bDeviceClass 2 Communications
bDeviceSubClass 0
bDeviceProtocol 0
bMaxPacketSize0 16
@yonran
yonran / scardstatus_bug.c
Created November 11, 2014 17:43
OSX 10.10 Yosemite SCardStatus bug test
// clang -framework PCSC scardstatus_bug.c -o scardstatus_bug
// Tests SCardStatus bug in OSX 10.10 Yosemite.
// Connects to a smart card and calls SCardStatus.
#include <stdio.h>
#include <strings.h>
#include <stdlib.h>
#include <PCSC/wintypes.h>
#include <PCSC/winscard.h>
#define TEXT(x) x
//! cl.exe /Tp listviwe_setselectionmark.cpp User32.lib ComCtl32.lib Ole32.lib
#define STRICT
#define UNICODE
#define _UNICODE
#include <windows.h>
#include <windowsx.h>
#include <ole2.h>
#include <commctrl.h>
#include <shlwapi.h>
#include <shlobj.h>
//! cl.exe /EHsc /Tp treeview-and-tabcontrol.cpp User32.lib ComCtl32.lib Ole32.lib
// Based on Raymond Chen's scratch program
// http://blogs.msdn.com/b/oldnewthing/archive/2005/04/22/410773.aspx
#define STRICT
#define UNICODE
#define _UNICODE
#include <windows.h>
#include <windowsx.h>
#include <ole2.h>
#include <commctrl.h>
@yonran
yonran / update-configmap-functions.sh
Created November 1, 2017 22:57
Functions to replace kubernetes configmap and secret from directory
#!/usr/bin/env bash
# Convert a directory to a ConfigMap json file as when doing kubectl create configmap --from-file …
#
# Example usage:
# 1. kubectl create cm test-cm --from-file path/to/cmdir
#
# 2. Before running kubectl replace, you should diff the directories:
# dirToCm test-cm path/to/cmdir | cmToDir /tmp/test-cm-new
# kubectl get cm test-cm -o json | cmToDir /tmp/test-cm-orig