Skip to content

Instantly share code, notes, and snippets.

@wtaysom
wtaysom / where_is.rb
Created September 23, 2011 08:57
A little Ruby module for finding the source location where class and methods are defined.
module Where
class <<self
attr_accessor :editor
def is_proc(proc)
source_location(proc)
end
def is_method(klass, method_name)
source_location(klass.method(method_name))
@STAR-ZERO
STAR-ZERO / FontFitTextView.java
Created June 15, 2012 03:18
【Android】横幅に合わせてテキストサイズを調整するTextView
import android.content.Context;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.widget.TextView;
/**
* サイズ自動調整TextView
*
*/
@JakeWharton
JakeWharton / dex.sh
Last active March 25, 2024 13:54
`classes.dex` method count helpers. Requires smali/baksmali from https://code.google.com/p/smali/ and dexdump from the build-tools in the Android SDK be on your PATH.
function dex-method-count() {
cat $1 | head -c 92 | tail -c 4 | hexdump -e '1/4 "%d\n"'
}
function dex-method-count-by-package() {
dir=$(mktemp -d -t dex)
baksmali $1 -o $dir
for pkg in `find $dir/* -type d`; do
smali $pkg -o $pkg/classes.dex
count=$(dex-method-count $pkg/classes.dex)
name=$(echo ${pkg:(${#dir} + 1)} | tr '/' '.')
#!/usr/bin/ruby
# Create display override file to force Mac OS X to use RGB mode for Display
# see http://embdev.net/topic/284710
require 'base64'
data=`ioreg -l -d0 -w 0 -r -c AppleDisplay`
edids=data.scan(/IODisplayEDID.*?<([a-z0-9]+)>/i).flatten
vendorids=data.scan(/DisplayVendorID.*?([0-9]+)/i).flatten
@huonw
huonw / blackmagic.rs
Created January 15, 2014 12:42
do-while loops in Rust
while {
let x = foo();
bar(x);
x != 0
} {}
import Cocoa
protocol AXUIWindow {
var title : String { get }
var size : NSSize { get set }
var origin: NSPoint{ get set }
var frame : NSRect { get set }
}
protocol AXUIWindowArray {
@ttdoda
ttdoda / pyonpyon.rb
Last active August 4, 2017 18:56
あぁ^~端末がぴょんぴょんするんじゃぁ^~
#!/usr/bin/env ruby
#
# License: CC0
#
gravity = 3
require 'timeout'
include Math
$stdout.sync = 1

Rust Error Handling Cheatsheet - Result handling functions

Introduction to Rust error handling

Rust error handling is nice but obligatory. Which makes it sometimes plenty of code.

Functions return values of type Result that is "enumeration". In Rust enumeration means complex value that has alternatives and that alternative is shown with a tag.

Result is defined as Ok or Err. The definition is generic, and both alternatives have