Skip to content

Instantly share code, notes, and snippets.

@deskid
deskid / Mac OS X 10_5_ Windows Ctrl.xml
Created June 17, 2020 15:07 — forked from fljot/Mac OS X 10_5_ Windows Ctrl.xml
AutoHotkey mappings to emulate OSX keyboard shortcuts on Windows
<!-- put this to IDEA keymaps config folder. For v13 it is <userdir>\.IntelliJIdea13\config\keymaps\ -->
<?xml version="1.0" encoding="UTF-8"?>
<keymap version="1" name="Mac OS X 10.5+ Windows Ctrl" parent="Mac OS X 10.5+">
<action id="$Copy">
<keyboard-shortcut first-keystroke="meta C" />
<keyboard-shortcut first-keystroke="meta INSERT" />
<keyboard-shortcut first-keystroke="control C" />
<keyboard-shortcut first-keystroke="control INSERT" />
</action>
<action id="$Cut">
@deskid
deskid / BaseDao.kt
Created February 12, 2019 07:44
Room and SQLite do not have any built-in methods to upsert a row, but you can add your own. You can make all of the Room Daos extend a BaseDao which can contain our upsert method insertOrUpdate.
@Dao
abstract class BaseDao<T> {
@Insert(onConflict = OnConflictStrategy.IGNORE)
abstract fun insert(obj: T): Long
@Insert(onConflict = OnConflictStrategy.IGNORE)
abstract fun insert(obj: List<T>): List<Long>
@Update
abstract fun update(obj: T)
@deskid
deskid / RxJava.md
Created October 17, 2018 07:31 — forked from cesarferreira/RxJava.md
Party tricks with RxJava, RxAndroid & Retrolambda

View Click

Instead of the verbose setOnClickListener:

RxView.clicks(submitButton).subscribe(o -> log("submit button clicked!"));

Filter even numbers

Observable
    .just(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
@deskid
deskid / gitstars.json
Last active December 8, 2017 04:03
github stars manager for production
{"lastModified":1512705802483,"labels":[{"id":1510762778349,"name":"slides","repos":[2553927]},{"id":1510762785575,"name":"tool","repos":[2553927,108359461,102151460]},{"id":1510763489339,"name":"gfw","repos":[14971308,4086616]},{"id":1510763613176,"name":"iOS","repos":[2626208]},{"id":1510763800892,"name":"android","repos":[12924500,15653276,21787149,26710221,17197323,14393731,5279091,91065402,103920670,106181098,23092563,24186761,97011177,54115435,95357887,9234481]},{"id":1510764657487,"name":"C++","repos":[8730628]},{"id":1510764666333,"name":"book","repos":[8730628,11600244]},{"id":1510765324959,"name":"node.js","repos":[51840802,103633984]},{"id":1510765338471,"name":"font end","repos":[51840802,108373398,106344904,72493907,38460192,9185792,2096579]},{"id":1510765382754,"name":"wxxcx","repos":[108373398]},{"id":1510765445933,"name":"kotlin","repos":[24186761,75286010]}]}
@deskid
deskid / pre_commit.sh
Created September 2, 2017 19:05
auto change git user
#!/usr/bin/env bash
# 用 repo 的 "remote.origin.url" 来匹配user配置
git_remotes[0]="github"
git_remotes[1]="gitlab"
# user info配置
local_id_0[0]="github user"
local_id_0[1]="github email"
@deskid
deskid / prevent_double_click.js
Created August 28, 2017 06:05 — forked from pangui/prevent_double_click.js
Prevent double click!
// jQuery plugin to prevent double click
jQuery.fn.preventDoubleClick = function() {
$(this).on('click', function(e){
var $el = $(this);
if($el.data('clicked')){
// Previously clicked, stop actions
e.preventDefault();
e.stopPropagation();
}else{
// Mark to ignore next click
@deskid
deskid / Query
Created June 20, 2017 09:48
android-room-select-query-with-like
@Query("SELECT * FROM hamster WHERE name LIKE '%' || :arg0 || '%'")
fun loadHamsters(search: String?): Flowable<List<Hamster>>
@deskid
deskid / setMaxLengthFilter.java
Created September 22, 2016 08:22
EditText.setFilters always over write the origin filters,buggly...
public void setMaxLengthFilter(EditText editText, int maxLength) {
InputFilter curFilters[];
InputFilter.LengthFilter lengthFilter;
int i;
lengthFilter = new InputFilter.LengthFilter(maxLength);
curFilters = editText.getFilters();
if (curFilters != null) {
for (i = 0; i < curFilters.length; i++) {
if (curFilters[i] instanceof InputFilter.LengthFilter) {
curFilters[i] = lengthFilter;
@deskid
deskid / mlnotifications.py
Created September 19, 2016 09:36 — forked from baliw/mlnotifications.py
Mountain Lion Notification Center via Python
import Foundation
import objc
import AppKit
import sys
NSUserNotification = objc.lookUpClass('NSUserNotification')
NSUserNotificationCenter = objc.lookUpClass('NSUserNotificationCenter')
def notify(title, subtitle, info_text, delay=0, sound=False, userInfo={}):
notification = NSUserNotification.alloc().init()
/**
* Copyright 2016 Harish Sridharan
* <p/>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p/>
* http://www.apache.org/licenses/LICENSE-2.0
* <p/>
* Unless required by applicable law or agreed to in writing, software