Skip to content

Instantly share code, notes, and snippets.

@Gevrai
Gevrai / BatteryMonitoring.swift
Created April 13, 2018 19:23
Very simple Singleton that sends a Notification whenever the state or level of the battery changed.
public class BatteryMonitoring {
public static let BatteryDidChangeNotification = Notification.Name(rawValue: "BatteryStateNotifier.BatteryDidChangeNotification")
public static let shared = BatteryMonitoring()
private init() {}
public private(set) var state : WKInterfaceDeviceBatteryState = .unknown
// State will be an int between 0 and 100 if state is not .unknown, else -1
public private(set) var level : Int = -1
@brickgale
brickgale / .htaccess
Last active January 28, 2022 16:24
Laravel force https for Heroku
#add this on public/.htaccess for Laravel
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
@luizcarraro
luizcarraro / open-external-link.js
Created July 27, 2017 11:37
ELECTRON: Open link in external default OS browser
@udezekene
udezekene / O'Reilly Design Books (Free).md
Last active July 24, 2024 16:13 — forked from augbog/Free O'Reilly Books.md
Download the just released O'Reilly Design Books for free without e-mail signup.

Free O'Reilly Design Books and convenient script to just download them.

HUGE thanks to O'Reilly for making this resource free. Visit the design page if you want to learn more about the design resources. Also, they do have FREE resources for other topics like: Data, IoT, Programming, Security, Web Development, and WebOps.

Thanks @augbog for the initial gist. If you are a developer or looking for software engineering books, headover to the source of this fork.

How to use:

  1. Take the download.sh file and put it into a directory where you want the files to be saved.
  2. cd into the directory and make sure that it has executable permissions (chmod +x download.sh should do it)
public class SoftInputAssist {
private View rootView;
private ViewGroup contentContainer;
private ViewTreeObserver viewTreeObserver;
private ViewTreeObserver.OnGlobalLayoutListener listener = () -> possiblyResizeChildOfContent();
private Rect contentAreaOfWindowBounds = new Rect();
private FrameLayout.LayoutParams rootViewLayout;
private int usableHeightPrevious = 0;
public SoftInputAssist(Activity activity) {
@lkoskela
lkoskela / UIColor+Contrast.swift
Created March 30, 2017 11:46
Utility for calculating the relative luminance and contrast ratio of two colors to determine whether they meet the recommendation set forth by the W3's Web Content Accessibility Guidelines 2.0.
import UIKit
extension UIFont {
private var weight: CGFloat {
if let traits = fontDescriptor.object(forKey: UIFontDescriptorTraitsAttribute) as? NSDictionary,
let weight = traits[UIFontWeightTrait] as? CGFloat {
return weight
}
return 0
}
@wonderbit
wonderbit / DockInfo.swift
Created November 28, 2016 19:04
Get the Dock position, size and hidden state in a Cocoa app
//
// DockInfo.swift
//
// Created by Wessley Roche on 28/11/2016.
//
import Foundation
enum WBDockPosition: Int {
case bottom = 0
@Sorix
Sorix / RoundedLabel.swift
Last active July 1, 2022 01:33
IBDesignable UILabel with rounded corners and paddings
import UIKit
@IBDesignable
class RoundedLabel: UILabel {
var edgeInsets: UIEdgeInsets {
if autoPadding {
if cornerRadius == 0 {
return UIEdgeInsets.zero
} else {
@bishalg
bishalg / CoreDataHelper.swift
Last active September 30, 2020 18:05
CoreData Helper to Delete All Entities
//
// CoreDataHelper.swift
// Xcode 8.0
// Swift 3.0
// Subclass of CoreDataStack -
// https://gist.github.com/bishalg/6e3a4fc4020b558f40b02c1d835aad8b
//
import Foundation
import CoreData
@subinkrishna
subinkrishna / MainActivity.java
Created October 1, 2016 21:46
Sample - Height animation using ObjectAnimator
import android.animation.ObjectAnimator;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.util.Property;
import android.view.View;
import android.view.animation.DecelerateInterpolator;
import android.widget.FrameLayout;
public class MainActivity extends AppCompatActivity {