Skip to content

Instantly share code, notes, and snippets.

View beginor's full-sized avatar
💭
Coding for code!

beginor beginor

💭
Coding for code!
View GitHub Profile
@beginor
beginor / snowflake-id.sql
Last active April 18, 2024 20:13
Twitter Snowflake ID for PostgreSQL
CREATE SEQUENCE public.global_id_seq;
ALTER SEQUENCE public.global_id_seq OWNER TO postgres;
CREATE OR REPLACE FUNCTION public.id_generator()
RETURNS bigint
LANGUAGE 'plpgsql'
AS $BODY$
DECLARE
our_epoch bigint := 1314220021721;
seq_id bigint;
@beginor
beginor / turn-on-wifi-hot-spot.sh
Created November 4, 2018 09:18
Trun on wifi spot by adb.
# open setting
adb shell am start -n com.android.settings/.TetherSettings
# down
adb shell input keyevent 20
# enter
adb shell input keyevent 66
@beginor
beginor / RSACryptoService.cs
Created November 8, 2016 21:48
C# RSACryptoService with openssl rsa key
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
namespace CMCloud.SaaS
{
using System.Xml;
using AutoMapper;
namespace AutoMapperTest;
public class Entity {
public XmlDocument Statement { get; set; }
}
public class Model {
@beginor
beginor / pnpm-ng-cli.sh
Created November 16, 2021 02:59
Create angular app with pnpm package manager.
#!/bin/bash -e
mv ng-seed-cli/.git _git
rm -rf ng-seed-cli
pnpm --package=@angular/cli dlx ng new ng-seed-cli --create-application false --skip-git --minimal --package-manager pnpm
cd ng-seed-cli
cp ../ng-seed/.eslintrc.json ./
cp ../ng-seed/.editorconfig ./
pnpm exec ng add @angular-eslint/schematics@next --skip-confirmation
pnpm exec ng g @angular-eslint/schematics:lib app-shared
pnpm exec ng g @angular-eslint/schematics:app handset --style scss --routing true --skip-tests true
@beginor
beginor / main.c
Last active October 20, 2021 05:58
Windows Service with c
#include <windows.h>
#include <stdio.h>
#define SLEEP_TIME 5000
#define LOGFILE "C:\\memstatus.txt"
int WriteToLog(char* str) {
FILE* log;
log = fopen(LOGFILE, "a+");
if (log == NULL)
@beginor
beginor / fix-geometries.py
Created April 13, 2021 00:05 — forked from jsanz/fix-geometries.py
Python - QGIS - Fix geometries
"""
Small script to fix geometries of the first file argument
using the native QGIS processing algorithm. You may need
to adjust the path to you installation.
"""
import sys
sys.path.append('/usr/share/qgis/python/plugins')
from processing.core.Processing import Processing
@beginor
beginor / dynamic-query.md
Last active December 3, 2020 09:38
dynamic query demo
public void SearchUser(
    string userName,
    int? age
) {
    // 以 NHibernate 的动态查询示例
    ISession session = OpenSession();
    IQueryable<User> query = session.Query<User>();
    // 根据参数动态构建表达式树
 if (userName.IsNotNullOrEmpty()) {
@beginor
beginor / angular-require-shim.js
Created November 11, 2014 06:42
RequireJS Shim for AngularJS 1.3.0
requirejs.config({
baseUrl: 'scripts',
paths: {
'angular': 'lib/angular/angular',
'angular-animate': 'lib/angular/angular-animate',
'angular-aria': 'lib/angular/angular-aria',
'angular-cookies': 'lib/angular/angular-cookies',
'angular-messages': 'lib/angular/angular-messages',
'angular-mocks': 'lib/angular/angular-mocks',
'angular-resource': 'lib/angular/angular-resource',
/****************************************************************************
* Author: Alberto Gutiérrez Jácome <agjacome@gmail.com>
* Date: 16/09/2012
*
* Compilation: javac KdTree.java
* Execution: not applicable
* Dependencies: Point2D.java RectHV.java StdDraw.java Queue.java
*
* Description: A mutable data type that uses a 2d-tree to represent a set of
* points in the unit square. A 2d-tree is a generalization of a BST to