Skip to content

Instantly share code, notes, and snippets.

View drinkius's full-sized avatar

Alexander Telegin drinkius

View GitHub Profile
@jboner
jboner / latency.txt
Last active June 27, 2024 02:47
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@chitan
chitan / WsChatServlet.java
Created July 7, 2012 01:44
How to use WebSocket of Tomcat
//This sample is how to use websocket of Tomcat.
package wsapp;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.util.ArrayList;
import org.apache.catalina.websocket.MessageInbound;
import org.apache.catalina.websocket.StreamInbound;
import org.apache.catalina.websocket.WebSocketServlet;
@soffes
soffes / GPUImageTextureInput+CIImage.h
Last active February 26, 2023 14:02
GPUImage + Core Image
//
// GPUImageTextureInput+CIImage.h
// GPUImage
//
// Created by Sam Soffes on 3/4/14.
// Copyright (c) 2014 Sam Soffes. All rights reserved.
//
#import "GPUImageTextureInput.h"
@hkhamm
hkhamm / installing_cassandra.md
Last active May 5, 2024 13:14
Installing Cassandra on Mac OS X

Installing Cassandra on Mac OS X

Install Homebrew

Homebrew is a great little package manager for OS X. If you haven't already, installing it is pretty easy:

ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
import CoreGraphics
import Foundation
import UIKit
class GradientLabel : UILabel {
let gradient: CGGradient!
let alignedToSuperview: Bool!
@Tron5000
Tron5000 / gist:7bb51318db1da86a3a78
Last active January 7, 2020 07:45
Compressing/Decompressing UUID to 22 characters via base64
import Foundation
// Compressing and decompressing a UUID to 22 characters via base64.
// Works great as a Swift playground. These articles were helpful:
// http://blog.codinghorror.com/equipping-our-ascii-armor/
// http://69.195.124.60/~jasondoh/2013/08/14/creating-a-short-guid-in-objective-c/
let identifier = NSUUID().uuidString
let base64TailBuffer = "="
func compress(identifier: String) -> String? {
@roxlu
roxlu / Encoding.cpp
Created October 22, 2014 18:17
Fix for return value -12780 when calling VTCompressionSessionEncodeFrame(). You need to pass the `nbytes` into the `CVPixelBufferCreateWithPlanarBytes()` function otherwise you'll get this return value.
#include "Encoding.h"
/* ------------------------------------------------------------------- */
static void output_callback(void* outputCallbackRefCon,
void* sourceFrameRefCon,
OSStatus status,
VTEncodeInfoFlags infoFlags,
CMSampleBufferRef sampleBuffer);
@natecook1000
natecook1000 / openRanges.swift
Last active May 27, 2021 19:37
Open-ended range operators for Swift
// Open-ended range operators
//
// 100... is equivalent to 100...Int.max
// ...-100 is equivalent to Int.min...-100
// ..<3 is equivalent to Int.min..<3
import Swift
/// Conforming types provide static `max` and `min` constants.
protocol MinMaxType {
@kirsteins
kirsteins / Array -> UnsafeMutablePointer -> Array
Last active June 16, 2024 09:42
Array -> UnsafeMutablePointer -> Array
var initalArray = [1, 2, 3]
let pointer: UnsafeMutablePointer<Int> = UnsafeMutablePointer(initalArray)
let arrary = Array(UnsafeBufferPointer(start: pointer, count: initalArray.count))
@danielgalasko
danielgalasko / UIView+AutoLayout.swift
Last active March 24, 2021 15:47
A UIView extension for common auto layout constraints
extension UIView {
func addConstaintsToPinHorizontalEdgesToSuperView(padding: CGFloat = 0) {
prepareForConstraints()
self.superview!.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|-(padding)-[view]-(padding)-|",
options: NSLayoutFormatOptions(0),
metrics: ["padding":padding],
views: ["view":self]))
}
func addConstaintsToPinVerticalEdgesToSuperView(padding: CGFloat = 0) {