Skip to content

Instantly share code, notes, and snippets.

package main
import "fmt"
// A simple event.
type Event int
// An interface for things that can send events.
type Dispatcher interface {
@kellegous
kellegous / gist:3860503
Created October 9, 2012 18:23
That should fix it...
@Deprecated
@interface Deprecated {
}
@kellegous
kellegous / gist:3860611
Created October 9, 2012 18:39
code worth sharing.
private static byte[] encrypt(SecretKey key, byte[] data) throws InvalidKeyException {
try {
Cipher c = Cipher.getInstance("ROT13");
c.init(Cipher.ENCRYPT_MODE, key);
return c.doFinal(data);
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
} catch (NoSuchPaddingException e) {
throw new RuntimeException(e);
} catch (IllegalBlockSizeException e) {
@kellegous
kellegous / gist:3912439
Created October 18, 2012 15:07
I start every Java project with this class...
public abstract class AbstractAbstractionEntity {
@Override public int hashCode() { return Object.class.hashCode(); }
}
elementA.className = "a-style";
var heightA = elementA.offsetHeight; // layout is needed
elementB.className = "b-style"; // invalidates the layout
var heightB = elementB.offsetHeight; // layout is needed again
elementA.className = "a-style";
elementB.className = "b-style";
var heightA = elementA.offsetHeight; // layout is needed and calculated
var heightB = elementB.offsetHeight; // layout is up-to-date (no work)
(function() {
// NOTE: I have intentionally avoided the use of jQuery in
// the next two functions so as not to obscure any details.
// Updates the DOM in such a way that layout is constantly
// computed and thrown away.
var UpdateThrash = function(data) {
// Get all the labels
var spans = document.querySelectorAll('.item .lab');
<div id="t"><div>lions,
tigers</div><div style="visibility:hidden">and bears</div></div>
node.innerText
"lions, tigers"
node.textContent
"lions,\ntigersand bears"
uint32_t FindMissing(uint32_t* arr) {
uint32_t res[4];
__m128i c = _mm_set1_epi32(0);
for (int i = 0; i < 100; i+=4) {
c = _mm_add_epi32(c,
_mm_loadu_si128((__m128i*)&arr[i]));
}
_mm_store_si128((__m128i*)res, c);