Skip to content

Instantly share code, notes, and snippets.

@ZHocean123
ZHocean123 / DataTable.tsx
Created January 21, 2025 05:13 — forked from joshkay/DataTable.tsx
TanStack cell selection
"use client";
import {
type ColumnDef,
flexRender,
getCoreRowModel,
useReactTable,
getPaginationRowModel,
getSortedRowModel,
getFilteredRowModel,
@ZHocean123
ZHocean123 / getRealPathFromUri.java
Last active March 4, 2019 06:37
getRealPathFromUri (when accessing a content in android memory)
public String getRealPathFromUri(final Uri uri) {
// DocumentProvider
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && DocumentsContract.isDocumentUri(this, uri)) {
// ExternalStorageProvider
if (isExternalStorageDocument(uri)) {
final String docId = DocumentsContract.getDocumentId(uri);
final String[] split = docId.split(":");
final String type = split[0];
if ("primary".equalsIgnoreCase(type)) {
@ZHocean123
ZHocean123 / react-native问题记录.md
Last active February 18, 2019 09:44
react-native问题记录
  1. node: command not found

    Oh, yeah sorry that's probably because when you run /bin/sh from your terminal it's picking up the PATH from the parent shell, which allows node to work.

    Different approach then, try (from your usual terminal where node is working):

    ln -s $(which node) /usr/local/bin/node

    That should put a symlink to node somewhere in the PATH that sh uses. If it already exists, I'm stumped.

@ZHocean123
ZHocean123 / SharedPreferenceLiveData.kt
Created November 7, 2018 05:46 — forked from rharter/SharedPreferenceLiveData.kt
Creates LiveData objects that observe a value in SharedPreferences while they have active listeners.
import android.arch.lifecycle.LiveData
import android.content.SharedPreferences
abstract class SharedPreferenceLiveData<T>(val sharedPrefs: SharedPreferences,
val key: String,
val defValue: T) : LiveData<T>() {
private val preferenceChangeListener = SharedPreferences.OnSharedPreferenceChangeListener { sharedPreferences, key ->
if (key == this.key) {
value = getValueFromPreferences(key, defValue)
import React from 'react';
import { TextInput as Input } from 'react-native';
export default class TextInput extends React.Component {
static defaultProps = {
onFocus: () => { },
}
constructor(props) {
super(props);
@ZHocean123
ZHocean123 / custom-error.js
Created November 29, 2017 08:32 — forked from justmoon/custom-error.js
Creating custom Error classes in Node.js
'use strict';
module.exports = function CustomError(message, extra) {
Error.captureStackTrace(this, this.constructor);
this.name = this.constructor.name;
this.message = message;
this.extra = extra;
};
require('util').inherits(module.exports, Error);
class MyClass {
}
private var key: Void?
extention MyClass {
var title: String? {
get {
return objc_getAssociatedObject(self, &key) as? String
}
@ZHocean123
ZHocean123 / SwiftOption.swift
Last active November 21, 2017 06:18
SwiftOption
struct SwiftOption: OptionSet {
let rawValue: UInt
static let none = SwiftOption(rawValue: 0)
static let option1 = SwiftOption(rawValue: 1)
static let option2 = SwiftOption(rawValue: 1 << 1)
}
@ZHocean123
ZHocean123 / TextEffectView.swift
Created October 12, 2017 02:01 — forked from mergesort/TextEffectView.swift
A playground for TextEffectView updated for Swift 3
//
// TextEffectView.swift
// TextEffects
//
// Created by Ben Scheirman on 2/15/16.
// Copyright © 2016 NSScreencast. All rights reserved.
//
import UIKit
import CoreText