Skip to content

Instantly share code, notes, and snippets.

View hunterwei's full-sized avatar

Hunter Wei hunterwei

View GitHub Profile
@hunterwei
hunterwei / CopyValueFromOneFeatureToAnother.py
Created January 18, 2018 00:01
ArcPy snippet to copy values from one feature class to another feature class
import arcpy
rows = arcpy.InsertCursor("TARGET_FEATURE")
sourcerows = arcpy.SearchCursor("SOURCE_FEATURE")
fields = arcpy.ListFields("SOURCE_FEATURE")
for sourcerow in sourcerows:
row = rows.newRow()
for field in fields:
if field.name != "OBJECTID":
row.setValue(field.name, sourcerow.getValue(field.name))
@hunterwei
hunterwei / GetFeatureExtent.py
Created January 19, 2018 16:02
A python script snippet to quickly get the extent of polygon feature(s)
import arcpy
LAYER_NAME="Your layer name"
FIELD_NAME="Your field name"
shapeFieldName = arcpy.Describe(LAYER_NAME).shapeFieldName
rows = arcpy.SearchCursor(LAYER_NAME)
for row in rows:
fieldValue = row.getValue(FIELD_NAME).strip()
feat = row.getValue(shapeFieldName)
@hunterwei
hunterwei / AccessUpdateWithJoin.sql
Created January 19, 2018 16:11
Update a table with joined table(s) in Microsoft Access database
UPDATE ((TableA A
INNER JOIN TableB B ON A.ID = B.AID)
INNER JOIN TableC C ON B.ID = C.BID)
SET A.DESC = C.DESC
@hunterwei
hunterwei / ReadGigaDataFile.cs
Created April 17, 2018 18:10
Read Extremely large file efficiently in C#
using (FileStream fs = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
using (BufferedStream bs = new BufferedStream(fs))
using (StreamReader sr = new StreamReader(bs))
{
string line;
while ((line = sr.ReadLine()) != null)
{
}
}
@hunterwei
hunterwei / DataFileProcessProgress.cs
Created April 17, 2018 18:18
Calculate the data file processing percentage based of stream position.
public void bgWorker_DoWork(object sender, DoWorkEventArgs e)
{
// Details of obtaining file paths omitted for brevity
using (StreamWriter sw = new StreamWriter(outputFilePath, true)) //You can use this constructor instead of FileStream, it does the same operation.
using (StreamReader sr = new StreamReader(inputFilePath))
{
int lastPercentage = 0;
String line;
while ((line = sr.ReadLine()) != null)
# Example 1a adapted from https://www.reddit.com/r/gis/comments/4rhvhh/map_automation_arcpymapping_make_lyr/
#
# Reference: 1) http://desktop.arcgis.com/en/arcmap/latest/analyze/arcpy-mapping/layer-class.htm
# 2) https://docs.python.org/2/library/json.html
import arcpy
import json
lyr = # Layer object, typically from arcpy.mapping.ListLayers (arcpy._mapping.Layer)
@hunterwei
hunterwei / BootAppJNDI.java
Last active June 28, 2019 21:57
Register JNDI in Tomcat container
@Bean
public TomcatServletWebServerFactory tomcatFactory() {
return new TomcatServletWebServerFactory() {
@Override
protected TomcatWebServer getTomcatWebServer(Tomcat tomcat) {
tomcat.enableNaming();
return super.getTomcatWebServer(tomcat);
}
@Override
@hunterwei
hunterwei / npm-using-https-for-git.sh
Created June 28, 2019 22:38 — forked from taoyuan/npm-using-https-for-git.sh
Force git to use https:// instead of git://
git config --global url."https://github.com/".insteadOf [email protected]:
git config --global url."https://".insteadOf git://
@hunterwei
hunterwei / DoubleTapAutoShift.c
Last active April 26, 2021 19:39
QMK micro to shift letters by double tap
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
uint8_t basic_keycode = 0;
if (keycode >= QK_LAYER_TAP && keycode <= QK_LAYER_TAP_MAX){
basic_keycode = (uint8_t)(keycode & 0xFF);
}
switch(keycode) {
case LT(0,KC_A):
if (record->event.pressed) {
if (record->tap.count == 2) {
@hunterwei
hunterwei / README.md
Created July 30, 2021 15:47 — forked from leonardofed/README.md
A curated list of AWS resources to prepare for the AWS Certifications


A curated list of AWS resources to prepare for the AWS Certifications

A curated list of awesome AWS resources you need to prepare for the all 5 AWS Certifications. This gist will include: open source repos, blogs & blogposts, ebooks, PDF, whitepapers, video courses, free lecture, slides, sample test and many other resources.