Skip to content

Instantly share code, notes, and snippets.

@lcomplete
lcomplete / -Spring-JPA-Dynamic-Query-With-Limit
Created September 21, 2022 09:31 — forked from tcollins/-Spring-JPA-Dynamic-Query-With-Limit
Spring Data JPA - Limit results when using Specifications without an unnecessary count query being executed
If you use the findAll(Specification, Pageable) method, a count query is first executed and then the
data query is executed if the count returns a value greater than the offset.
For what I was doing I did not need pageable, but simply wanted to limit my results. This is easy
to do with static named queries and methodNameMagicGoodness queries, but from my research (googling
for a few hours) I couldn't find a way to do it with dynamic criteria queries using Specifications.
During my search I found two things that helped me to figure out how to just do it myself.
1.) A stackoverflow question.
@lcomplete
lcomplete / rss_link_hunt.py
Created May 9, 2022 12:32
通过 OPML xml 文件解析 RSS feed,从 feed 中获取被推荐最多的链接
@lcomplete
lcomplete / sub-directory-pull-all.sh
Last active December 27, 2021 08:39
更新所有子目录的git仓库
# 更新所有子目录的git仓库
for dir in $(find . -maxdepth 2 -mindepth 2 -type d | xargs); do (echo "$dir" && cd "$dir" && git pull); done
# 按月统计所有仓库的提交次数
for dir in $(find . -maxdepth 2 -mindepth 2 -type d | xargs); do (echo "$dir" && cd "$dir" && git-quick-stats -m | sed '1,3d' | awk '{print $1, $2}' >> /mnt/e/report/commit.txt); done
@lcomplete
lcomplete / hosts.ps1
Created December 23, 2021 03:21 — forked from markembling/hosts.ps1
Powershell script for adding/removing/viewing entries to the hosts file.
#
# Powershell script for adding/removing/showing entries to the hosts file.
#
# Known limitations:
# - does not handle entries with comments afterwards ("<ip> <host> # comment")
#
$file = "C:\Windows\System32\drivers\etc\hosts"
function add-host([string]$filename, [string]$ip, [string]$hostname) {
@lcomplete
lcomplete / gist:dffeffeff313ce3fa9298013a6f48cbf
Created July 7, 2021 10:12 — forked from handrus/gist:8835872
Faster git clone for large repositories
git clone --depth 1 https://github.com/CocoaPods/Specs
USE db
SET NOCOUNT ON
DECLARE @TableName nvarchar(256), @ColumnName nvarchar(600),@TableRowCount int,@ColumnKey nvarchar(128),@DbName nvarchar(50);
SET @TableName = ''
WHILE @TableName IS NOT NULL
BEGIN
SET @ColumnName = '';
@lcomplete
lcomplete / 数据库中搜索字符串.sql
Created August 26, 2020 12:28
Sql Server 数据库中搜索字符串
USE DATABASE_NAME
DECLARE @SearchStr nvarchar(100) = 'SEARCH_TEXT'
DECLARE @Results TABLE (ColumnName nvarchar(370), ColumnValue nvarchar(3630))
SET NOCOUNT ON
DECLARE @TableName nvarchar(256), @ColumnName nvarchar(128), @SearchStr2 nvarchar(110)
SET @TableName = ''
SET @SearchStr2 = QUOTENAME('%' + @SearchStr + '%','''')
@lcomplete
lcomplete / Count lines in Git repo
Created July 10, 2020 14:29 — forked from mandiwise/Count lines in Git repo
A command to calculate lines of code in all tracked files in a Git repo
// Reference: http://stackoverflow.com/questions/4822471/count-number-of-lines-in-a-git-repository
$ git ls-files | xargs wc -l
@lcomplete
lcomplete / 爱因斯坦斑马难题.md
Last active June 28, 2020 07:56
使用prolog解决爱因斯坦斑马难题

爱因斯坦逻辑难题

5个不同国家且工作各不相同的人分别住在一条街上的5所房子里,每所房子的颜色不同,每个人都有自己养的不同宠物,喜欢喝不同的饮料。根据以下提示,你能告诉我哪所房子里的人养斑马,哪所房子里的人喜欢喝矿泉水吗?

  1. 英国人住在红色的房子里
  2. 西班牙人养了一条狗
  3. 日本人是一个油漆工
  4. 意大利人喜欢喝茶
  5. 挪威人住在左边的第一个房子里
  6. 绿房子在白房子的右边
@lcomplete
lcomplete / crawl_image.rb
Created June 28, 2020 07:53
ruby抓取图片(早期代码,已经无法使用)
#encoding: utf-8
require 'net/http'
require 'open-uri'
require 'nokogiri' # 用于解析html的模块
# sudo apt-get install libxslt-dev libxml2-dev
# sudo gem install nokogiri
require 'pathname'
class JanDanSpider