Skip to content

Instantly share code, notes, and snippets.

@tomgibara
tomgibara / SquareGridLayout.java
Created November 27, 2010 01:22
Square grid layout for Android
package com.tomgibara.android.util;
import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
/**
* A layout that arranges views into a grid of same-sized squares.
@micho
micho / nginx.conf
Last active September 29, 2023 16:38 — forked from unixcharles/nginx.conf
nginx config for http/https proxy to localhost:3000
First, install nginx for mac with "brew install nginx".
Then follow homebrew's instructions to know where the config file is.
1. To use https you will need a self-signed certificate: https://devcenter.heroku.com/articles/ssl-certificate-self
2. Copy it somewhere (use full path in the example below for server.* files)
3. sudo nginx -s reload
4. Access https://localhost/
Edit /usr/local/etc/nginx/nginx.conf:
@jexchan
jexchan / multiple_ssh_setting.md
Created April 10, 2012 15:00
Multiple SSH keys for different github accounts

Multiple SSH Keys settings for different github account

create different public key

create different ssh key according the article Mac Set-Up Git

$ ssh-keygen -t rsa -C "your_email@youremail.com"
@cjaoude
cjaoude / gist:fd9910626629b53c4d25
Last active July 22, 2024 11:08
Test list of Valid and Invalid Email addresses
Use: for testing against email regex
ref: http://codefool.tumblr.com/post/15288874550/list-of-valid-and-invalid-email-addresses
List of Valid Email Addresses
email@example.com
firstname.lastname@example.com
email@subdomain.example.com
firstname+lastname@example.com
@axldyb
axldyb / UIImage crop to square
Created April 29, 2015 09:42
Extension for cropping an UIImage to a square.
extension UIImage {
func cropsToSquare() -> UIImage {
let refWidth = CGFloat(CGImageGetWidth(self.CGImage))
let refHeight = CGFloat(CGImageGetHeight(self.CGImage))
let cropSize = refWidth > refHeight ? refHeight : refWidth
let x = (refWidth - cropSize) / 2.0
let y = (refHeight - cropSize) / 2.0
let cropRect = CGRectMake(x, y, cropSize, cropSize)
@ivanbruel
ivanbruel / SnakeCase.swift
Last active March 19, 2023 16:42
Camel case to snake case in Swift
extension String {
func snakeCased() -> String? {
let pattern = "([a-z0-9])([A-Z])"
let regex = try? NSRegularExpression(pattern: pattern, options: [])
let range = NSRange(location: 0, length: self.characters.count)
return regex?.stringByReplacingMatches(in: self, options: [], range: range, withTemplate: "$1_$2").lowercased()
}
}
@SeanLintern
SeanLintern / gist:3a78b3b40ee25561eb46f4e2044f5d26
Created April 28, 2017 14:17
AVCaptureAudioDataOutput Demo
import UIKit
import AVKit
import AVFoundation
import AssetsLibrary
func synchronized(_ object: AnyObject, block: () -> Void) {
objc_sync_enter(object)
block()
objc_sync_exit(object)
}
enum Foo: String, Codable {
case a
case b
case c
}
extension RawRepresentable where RawValue == String, Self: Codable {
init(from decoder: Decoder) throws {
var container = try decoder.unkeyedContainer()
let rawValue = try container.decode(String.self)
@yusuke024
yusuke024 / ViewController.swift
Created November 16, 2018 03:15
Recording video with AVAssetWriter
import UIKit
import AVFoundation
class ViewController: UIViewController {
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
switch AVCaptureDevice.authorizationStatus(for: .video) {
case .notDetermined:
@vinaywadhwa
vinaywadhwa / adb_wifi_connect_all.sh
Created December 27, 2019 06:59
Android Debug Bridge (adb) Wireless Debugging Over Wi-Fi - Switch on wifi debugging in ALL devices connected (via USB, with USB debugging enabled) to your computer (tested on Mac OS)
for line in `adb devices | grep -v "List" |grep -v ":" | awk '{print $1}'`
do
device=`echo $line | awk '{print $1}'`
echo "Running commands for $device"
echo "Restarting $device in TCP mode on port 5555..."
adb -s "$device" tcpip 5555
echo "Waiting for $device to switch to TCP mode..."
sleep 7
ip_addr=$(adb -s "$device" shell ip route | grep wlan| grep -o ' 192.*$' | awk '{print $1":5555"}')
echo "Connecting to Device via WIFI on $ip_addr"