Skip to content

Instantly share code, notes, and snippets.

View dweinstein's full-sized avatar

David Weinstein dweinstein

View GitHub Profile
@dweinstein
dweinstein / async.js
Last active August 29, 2015 14:22
async with generators / promises
// http://pag.forbeslindesay.co.uk/#/22
function async(makeGenerator){
return function (){
var generator = makeGenerator.apply(this, arguments)
function handle(result){ // { done: [Boolean], value: [Object] }
if (result.done) return result.value
return result.value.then(function (res){
return handle(generator.next(res))
# vim:ft=zsh ts=2 sw=2 sts=2
#
# agnoster's Theme - https://gist.github.com/3712874
# A Powerline-inspired theme for ZSH
#
# # README
#
# In order for this theme to render correctly, you will need a
# [Powerline-patched font](https://github.com/Lokaltog/powerline-fonts).
#
@dweinstein
dweinstein / .aliases
Created June 23, 2015 18:22
android apk certificate information signature signed
apk_keyinfo () {
unzip -p "$1" META-INF/CERT.RSA | openssl pkcs7 -inform DER -noout -print_certs -text
}
function sym.subsystem_control_shutdown () {
loc_0x8d4:
push (r4, r5, r6, r7, r8, sb, lr)
r4 = r0
r7 = [pc + 0x240]
sp -= 0x44
r2 = [pc + 0x240]
r0 = 4
r7 += pc
/ (fcn) sym.subsystem_control_shutdown 576
| ;-- sym.subsystem_control_shutdown:
| 0x000008d4 2de9f043 push.w {r4, r5, r6, r7, r8, sb, lr}
| 0x000008d8 0446 mov r4, r0
| 0x000008da 904f ldr r7, [pc, 0x240] ; [0xb1c:4]=0x333 "lize"
| 0x000008dc 91b0 sub sp, 0x44
| 0x000008de 904a ldr r2, [pc, 0x240] ; [0xb20:4]=0x371 "i_unwind_cpp_pr0"
| 0x000008e0 0420 movs r0, 4
| 0x000008e2 7f44 add r7, pc
| 0x000008e4 8f4e ldr r6, [pc, 0x23c] ; [0xb24:4]=0x16ca

This example creates strings in four different ways that all work with the print_me function. The key to making this all work is passing values by reference. Rather than passing owned_string as a String to print_me, we instead pass it as &String. When the compiler sees a &String being passed to a function that takes &str, it coerces the &String into a &str. This same coercion takes places for the reference counted and atomically referenced counted strings. The string variable is already a reference, so no need to use a & when calling print_me(string). Knowing this, we no longer need to have .to_string() calls littering our code.

fn print_me(msg: &str) { println!("msg = {}", msg); }

fn main() {
    let string = "hello world";
    print_me(string);
@dweinstein
dweinstein / cdr.c
Created June 7, 2011 22:04
seek's stream or file before outputting to stdout
/* cdr.c
* David Weinstein (2011)
* offset bytes into a file and write to stdout
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
@dweinstein
dweinstein / app_transport_http_error.md
Last active September 30, 2015 00:06
iOS App Transport No More free HTTP

2015-09-29 19:57:14.354 xxxx[3879:33484] App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist file.

@dweinstein
dweinstein / accessory.h
Created August 20, 2012 00:43
header file for android accessory mode
//
// accessory.h
// AccessoryMode
//
// Created by David Weinstein on 8/3/12.
// Copyright (c) 2012 David Weinstein. All rights reserved.
//
#ifndef AccessoryMode_accessory_h
#define AccessoryMode_accessory_h
@dweinstein
dweinstein / main.cpp
Created August 20, 2012 01:32
main function for interacting with accessory protocol
//
// main.cpp
// AccessoryMode
//
// Created by David Weinstein on 07/30/2012.
// Copyright (c) 2012 David Weinstein. All rights reserved.
// Code based on documentation from apple: Working With USB Device Interfaces
// see https://developer.apple.com/library/mac/documentation/DeviceDrivers/Conceptual/USBBook/index.html
//
// *Important* If your application is sandboxed, it must request the