Skip to content

Instantly share code, notes, and snippets.

View ruan65's full-sized avatar
🎯
Focusing

Andrew ruan65

🎯
Focusing
View GitHub Profile
@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 / 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))
#!/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 / hidden_keyboard.xml
Created November 1, 2016 15:15
android editText hide keyboard
<activity
android:name=".ui.activity.MainActivity"
android:label="@string/mainactivity"
android:windowSoftInputMode="stateHidden"
/>
@ruan65
ruan65 / getDeviceId.java
Created October 9, 2016 16:18
Get android device id
public static String getDeviceId(Context ctx) {
TelephonyManager tm = (TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE);
String deviceId;
if (tm.getDeviceId() != null) {
deviceId = tm.getDeviceId();
} else {
@ruan65
ruan65 / GetAndroidDeviceUid.java
Created October 8, 2016 15:50
Get Android device unique id
public static String getDeviceId(Context ctx) {
TelephonyManager tm = (TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE);
String deviceId;
if (tm.getDeviceId() != null) {
deviceId = tm.getDeviceId();
} else {
#!/usr/bin/python
n = 11
while n != 1:
print n
if n % 2 == 0:
n /= 2
else:
n = 3 * n + 1
@ruan65
ruan65 / playMarketOpen.java
Last active September 22, 2016 09:35
Static method to open Play Market by package name
public static void openPlayMarketByPackageName(Context ctx, String packageName) {
try {
ctx.startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse("market://details?id=" + packageName)));
} catch (android.content.ActivityNotFoundException anfe) {
ctx.startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse("https://play.google.com/store/apps/details?id=" + packageName)));
} catch (Exception ex) {
ex.printStackTrace();
@ruan65
ruan65 / bash.sh
Last active September 4, 2016 19:09
ssh root@MachineB 'bash -s' < local_script.sh
PID=`ps -ef | grep rest-ser | grep -v grep | awk '{print $2}'`
#!/bin/bash
PID=`ps -ef | grep rest-ser | grep -v grep | awk '{print $2}'`
echo $PID
@ruan65
ruan65 / backarrowActionBarHandling.java
Created August 15, 2016 10:29
Back Arrow in the Action Bar override
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
Toast.makeText(getApplicationContext(),"Back button clicked", Toast.LENGTH_SHORT).show();
break;
}
return true;
}