Skip to content

Instantly share code, notes, and snippets.

View bmeurer's full-sized avatar

Benedikt Meurer bmeurer

View GitHub Profile
@bmeurer
bmeurer / UILabel+BMRoundedRectAdditions.h
Created June 13, 2011 15:05
Category on UILabel which adds a property showsRoundedRect, which, if set to YES, causes the label to be drawn on a rounded rect, similar to the emblem shown for the number of new mails in the iPhone Mail app.
/*-
* Copyright (c) 2011, Benedikt Meurer <[email protected]>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
@bmeurer
bmeurer / gist:1026439
Created June 15, 2011 03:51
Nice transition from splash screen to main application screen using fade out and zoom in animation. Change the -application:didFinishLaunchingWithOptions: method of your application delegate class like this (assuming your splash image is named Default.png
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Put necessary initialization steps here...
// Add imageView overlay with fade out and zoom in animation
UIImageView *imageView = [[UIImageView alloc] initWithFrame:self.window.frame];
imageView.image = [UIImage imageNamed:@"Default"]; // assuming your splash image is "Default.png" or "[email protected]"
[self.window addSubview:imageView];
[self.window bringSubviewToFront:imageView];
[UIView transitionWithView:self.window
@bmeurer
bmeurer / ocaml-git-sync.sh
Created August 18, 2011 14:17
Sync the ~/git/ocaml.git repository with the master Subversion repository at Inria and upload the changes to GitHub at bmeurer/ocaml.
#!/bin/sh
# ~/bin/ocaml-git-sync.sh: Sync the ~/git/ocaml.git repository with the master
# Subversion repository at Inria and upload the changes
# to GitHub at bmeurer/ocaml.
# Copyright (c) 2011 Benedikt Meurer <[email protected]>
#
# Repository location
GIT_DIR="$HOME/git/ocaml.git"
export GIT_DIR

Converting an array of char codes to a String

There's currently String.fromCharCode and String.fromCodePoint in EcmaScript to convert a (sequence of) character code(s)/code point(s) to a String, but this only works if the input codes are passed as parameters to these String builtins. So a common pattern in JavaScript to construct a String from the bytes in an ArrayBuffer (that was read from a file or fetched from some server) is to either use

@bmeurer
bmeurer / destructuring-performance-test.js
Last active November 17, 2016 06:09
Destructuring performace (V8 ToT 2016/11/16)
/////////////////////////////////////////////////////////////////////////////
// Test framework:
// Warmup
for (var i = 0; i < 1000; ++i) test(data);
function time(test, a) {
let startTime = Date.now();
// Using F.p.apply here to prevent inlining, so we can really
// just measure the performance of test stand-alone.
function fibonacci(num){
var a = 1, b = 0, temp;
while (num >= 0){
temp = a;
a = a + b;
b = temp;
--num;
}
const todo = (state = {}, action) => {
switch (action.type) {
case 'ADD_TODO':
return {
id: action.id,
text: action.text,
completed: false
}
case 'TOGGLE_TODO':
if (state.id !== action.id) {
const s1 = todo({}, {
type: 'ADD_TODO',
id: 1,
text: "Finish blog post"
});
const s2 = todo(s1, {
type: 'TOGGLE_TODO',
id: 1
});
let a = {x:1, y:2, z:3};
let b = {};
b.x = 1;
b.y = 2;
b.z = 3;
console.log("a is", a);
console.log("b is", b);
console.log("a and b have same map:", %HaveSameMap(a, b));
let a = {x:1, y:2, z:3};
let b = Object.assign({}, a);
console.log("a is", a);
console.log("b is", b);
console.log("a and b have same map:", %HaveSameMap(a, b));