Skip to content

Instantly share code, notes, and snippets.

View ruan65's full-sized avatar
🎯
Focusing

Andrew ruan65

🎯
Focusing
View GitHub Profile
@ruan65
ruan65 / java_write_to_file_exampe.java
Last active January 19, 2018 10:18
java write to file exampe
@RequestMapping(value = "/change/text", method = RequestMethod.POST)
public OutputMessage changeText(@RequestBody InputMessage msg) {
String fileName = "/home/a/temp/writtenByJava.txt";
System.out.println("Writing to file " + fileName);
writeToFileHelper(fileName, msg.getText());
return new OutputMessage(msg.getFrom(), msg.getText() + " - this is response!", new Date().toString());
// MARK: TextViewDelegate methods for hiding keyboard by tapping anywhere and restrincting 500 chars
extension UIViewController {
@objc func textViewDidBeginEditing(_ textView: UITextView) {
}
@objc func textViewDidEndEditing(_ textView: UITextView) {
@ruan65
ruan65 / exclude_rgex.txt
Created July 19, 2017 10:32
Exclude text in the android logcat
^(?!.*(Choreographer)).*$
@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]);
@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")
}
// 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 / http_allow.xml
Created May 7, 2017 22:45
Xcode allow http
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
@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
jar {
manifest {
attributes(
'Class-Path': configurations.compile.collect { it.getName() }.join(' '),
'Main-Class': 'App'
)
}
}
@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? {