Skip to content

Instantly share code, notes, and snippets.

View ruan65's full-sized avatar
🎯
Focusing

Andrew ruan65

🎯
Focusing
View GitHub Profile
#!/bin/bash
export DISPLAY=:0
ts="$(date +%Y-%m-%d_%H:%M:%S)"
/usr/bin/notify-send -t 5000 "Ok. hi" $ts
#spd-say hello_my_friend
@ruan65
ruan65 / Helpers.swift
Created February 22, 2017 15:01
Frequently used static functions for iOs app (swift 3)
import Foundation
import UIKit
struct H {
static func showOneBtnAlert(_ ctx: UIViewController, header: String, msg: String) {
let alert = UIAlertController(title: header, message: msg, preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: Btn.ok, style: UIAlertActionStyle.default, handler: nil))
@ruan65
ruan65 / swiftActivityIndicator.swift
Created March 6, 2017 14:31
iOs swift activity indicator
var spinner: UIActivityIndicatorView!
func setupSpinner(){
spinner = UIActivityIndicatorView(frame: CGRect(x: 0, y: 0, width: 40, height:40))
spinner.color = UIColor.gray
self.spinner.center = CGPoint(x:UIScreen.main.bounds.size.width / 2, y:UIScreen.main.bounds.size.height / 2)
self.view.addSubview(spinner)
spinner.hidesWhenStopped = true
}
@ruan65
ruan65 / stringSubscript.swift
Created March 7, 2017 22:35
swift better work with strings
extension String {
subscript (i: Int) -> String? {
if characters.count > i && i >= 0 {
return String(Array(self.characters)[i])
}
return nil
}
subscript (r: Range<Int>) -> String? {
jar {
manifest {
attributes(
'Class-Path': configurations.compile.collect { it.getName() }.join(' '),
'Main-Class': 'App'
)
}
}
@ruan65
ruan65 / addConstraintsWithFormat.swift
Last active March 25, 2021 08:05
Swift. Useful UIView extension for adding constraints with format
extension UIView {
func addConstraintsWithFormat(format: String, views: UIView...) {
var viewsDict = [String: UIView]()
for (index, view) in views.enumerated() {
view.translatesAutoresizingMaskIntoConstraints = false
viewsDict["v\(index)"] = view
@ruan65
ruan65 / http_allow.xml
Created May 7, 2017 22:45
Xcode allow http
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
// Needed in AndroidManifest:
<!-- Permission for using NFC hardware -->
<uses-permission android:name="android.permission.NFC"/>
<!-- Forcing device to have NFC hardware -->
<uses-feature android:name="android.hardware.nfc" android:required="true"/>
<!-- Registering app for receiving NFC's TAG_DISCOVERED intent -->
<intent-filter>
<action android:name="android.nfc.action.TAG_DISCOVERED"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
@ruan65
ruan65 / Scrolled.swift
Created July 2, 2017 15:39
Method for catching CollectionView scroll to top or bottom in Swift
override func scrollViewDidScroll(_ scrollView: UIScrollView) {
if (scrollView.contentOffset.y < -250){
//reach top
print("Topppppppppppppppppppp")
}
@ruan65
ruan65 / c_exp.c
Created July 16, 2017 23:24
playing with clang
#import <stdio.h>
typedef unsigned char *pointer;
void show_bytes(pointer start, int len) {
int i;
for(i = 0; i < len; i++) {
printf("%p\t0x%.4x\n", start + i, start[i]);