Skip to content

Instantly share code, notes, and snippets.

View zhuowei's full-sized avatar

zhuowei

View GitHub Profile
@mahmoudimus
mahmoudimus / python-monkey-patch-built-ins.py
Created February 4, 2010 22:20
pythonic monkey patching built-in types
# found this from Armin R. on Twitter, what a beautiful gem ;)
import ctypes
from types import DictProxyType, MethodType
# figure out side of _Py_ssize_t
if hasattr(ctypes.pythonapi, 'Py_InitModule4_64'):
_Py_ssize_t = ctypes.c_int64
else:
_Py_ssize_t = ctypes.c_int
@fnichol
fnichol / README.md
Created March 12, 2011 20:52
Download a cacert.pem for RailsInstaller

Why?

There is a long standing issue in Ruby where the net/http library by default does not check the validity of an SSL certificate during a TLS handshake. Rather than deal with the underlying problem (a missing certificate authority, a self-signed certificate, etc.) one tends to see bad hacks everywhere. This can lead to problems down the road.

From what I can see the OpenSSL library that Rails Installer delivers has no certificate authorities defined. So, let's go fetch some from the curl website. And since this is for ruby, why don't we download and install the file with a ruby script?

Installation

The Ruby Way! (Fun)

@klange
klange / _.md
Last active December 2, 2023 20:36
It's a résumé, as a readable and compilable C source file. Since Hacker News got here, this has been updated to be most of my actual résumé. This isn't a serious document, just a concept to annoy people who talk about recruiting and the formats they accept résumés in. It's also relatively representative of my coding style.

Since this is on Hacker News and reddit...

  • No, I don't distribute my résumé like this. A friend of mine made a joke about me being the kind of person who would do this, so I did (the link on that page was added later). My actual résumé is a good bit crazier.
  • I apologize for the use of _t in my types. I spend a lot of time at a level where I can do that; "reserved for system libraries? I am the system libraries".
  • Since people kept complaining, I've fixed the assignments of string literals to non-const char *s.
  • My use of type * name, however, is entirely intentional.
  • If you're using an older compiler, you might have trouble with the anonymous unions and the designated initializers - I think gcc 4.4 requires some extra braces to get them working together. Anything reasonably recent should work fine. Clang and gcc (newer than 4.4, at le
@machinamentum
machinamentum / print_j.asm
Last active December 14, 2015 02:09
This is the simplest, smallest program to print a letter to the display. It was written in response to zhuowei's "i" program at https://github.com/zhuowei/i Unfortunately, due to the fact that this must be run as a boot sector, it must be bloated to 512 bytes. However, it takes up only 5 bytes of data itself, requires no bloated Operating System…
mov ax, 0x0E6A
int 0x10
times 510-($-$$) db 0
db 0x55 ; required for some BIOS's
db 0xAA
As you read this electronic message; I don't want you to feel sorry for me
because I believe everyone will die someday, please don't ignore it as I
am composing this message to you with heavy tears In my eyes and great sorrow
in my heart. I only have few days to be in this world according to my
medical doctor for the cause that I am contaminated with stroke and
cancer.
I need you to carry out a specific good work,
Contact my lawyer with the specified email address below:
@armadsen
armadsen / ORSSerialPort+Attributes.m
Last active July 11, 2018 13:44
Example code to get USB device properties for a given instance of ORSSerialPort. Will only work for USB-to-serial adapters, not internal serial ports. Based on https://gist.github.com/rhwood/4124251.
#import <Foundation/Foundation.h>
#import <IOKit/usb/USBSpec.h>
#import "ORSSerialPort.h"
@interface ORSSerialPort (Attributes)
@property (nonatomic, readonly) NSDictionary *ioDeviceAttributes;
@property (nonatomic, readonly) NSNumber *vendorID;
@property (nonatomic, readonly) NSNumber *productID;
@steipete
steipete / PSPDFUIKitMainThreadGuard.m
Last active March 10, 2024 19:23
This is a guard that tracks down UIKit access on threads other than main. This snippet is taken from the commercial iOS PDF framework http://pspdfkit.com, but relicensed under MIT. Works because a lot of calls internally call setNeedsDisplay or setNeedsLayout. Won't catch everything, but it's very lightweight and usually does the job.You might n…
// Taken from the commercial iOS PDF framework http://pspdfkit.com.
// Copyright (c) 2014 Peter Steinberger, PSPDFKit GmbH. All rights reserved.
// Licensed under MIT (http://opensource.org/licenses/MIT)
//
// You should only use this in debug builds. It doesn't use private API, but I wouldn't ship it.
// PLEASE DUPE rdar://27192338 (https://openradar.appspot.com/27192338) if you would like to see this in UIKit.
#import <objc/runtime.h>
#import <objc/message.h>
@steventroughtonsmith
steventroughtonsmith / gist:6763213
Created September 30, 2013 12:39
Non-opaque application windows in iOS 7, with optional blur. Shows the user's wallpaper under the app, with Parallax if supported.
typedef enum _UIBackgroundStyle {
UIBackgroundStyleDefault,
UIBackgroundStyleTransparent,
UIBackgroundStyleLightBlur,
UIBackgroundStyleDarkBlur,
UIBackgroundStyleDarkTranslucent
} UIBackgroundStyle;
@interface UIApplication (UIBackgroundStyle)
-(void)_setBackgroundStyle:(UIBackgroundStyle)style;
@landonf
landonf / xcode-gripes.md
Last active August 21, 2020 09:06
Every time I hit something that annoys me in Xcode, I add the feature/UX improvement/change I'd like to the list.

Xcode Wish List:

Legacy Support

  • Additional optional downloads:
    • Older SDKs, eg, for building ancient projects.
    • Older compilers (for same).
  • Either ship gcc/llvm-gcc or don't. Don't ship clang and call it 'gcc', that just breaks anyone who actually needs GCC and finds your not-gcc in the PATH.

UX

Project/File Navigation

@winocm
winocm / mispy.c
Created January 28, 2014 23:11
Happy birthday @M1sp! <3
#include <stdio.h>
#include <stdint.h>
#include <strings.h>
#include <stdlib.h>
#define __t uint32_t
#define __r return
typedef struct _$n{union{struct{__t o:5;__t rt:4;__t ra:4;__t z:4;__t sreg:8;__t _rs$v:7;}____;__t e;}u;} _$n;typedef struct _$i {
union{struct{__t o:5;__t z:4;__t _:16;__t __:7;}____;__t e;}u;}_$i;typedef struct _$l {union{struct{__t o:5;__t rt:4;__t ra:4;