Skip to content

Instantly share code, notes, and snippets.

View bryder's full-sized avatar

Bill Ryder bryder

View GitHub Profile
class TrapInfo {
# Trap name - eg 18 or 16-1 etc
$Name
# if it was checked
$Done
# What was found
$Catch
# free form notes
$Notes

It seems that it does not matter what timezone is on the server as long as you have the time set right for the current timezone, know the timezone of the datetime columns that you store, and are aware of the issues with daylight savings time.

On the other hand if you have control of the timezones of the servers you work with then you can have everything set to UTC internally and never worry about timezones and DST.

Here are some notes I collected of how to work with timezones as a form of cheatsheet for myself and others which might influence what timezone the person will choose for his/her server and how he/she will store date and time.

MySQL Timezone Cheatsheet

@bryder
bryder / json_object_encoder.py
Created May 16, 2017 21:08
An object encoder that will recursively encode arbitrary python objects
# This is a minor modification of http://stackoverflow.com/a/35483750/1543555
class JSONObjectEncoder(json.JSONEncoder):
def default(self, obj):
if hasattr(obj, "to_json"):
return self.default(obj.to_json())
else:
if isinstance(obj, dict):
return obj
elif isinstance(obj, datetime.datetime):
@bryder
bryder / find_bad_sqlite3_chrome_databases.sh
Created February 1, 2017 01:23
find bad sqlite3 chrome databases
cd ~/.config/google-chrome/Default # or wherever
find . -type f -print0 | xargs --null -n 1 file | grep -i sql | cut -d: -f1 | tr '\n' '\0' > /tmp/list
cat /tmp/list | xargs --null -t -n 1 -I'{}' sqlite3 '{}' "PRAGMA integrity_check"
@bryder
bryder / query_planner.markdown
Created January 16, 2017 21:45 — forked from hgmnz/query_planner.markdown
PostgreSQL query plan and SQL performance notes

Types of index scans

Indexes

Sequential Scan:

  • Read every row in the table
  • No reading of index. Reading from indexes is also expensive.
@bryder
bryder / print_prepared_statement_as_sql.java
Created December 18, 2016 01:47
Prepare a sql statement in java and print it as a string
List<Object> params = Lists.newArrayList();
if (logger.isDebugEnabled()){
try {
PreparedStatement ps = this.getConnection().prepareStatement(q);
for (int i=0 ; i < params.size(); i++){
ps.setObject(i+1, params.get(i));
}
logger.debug("Build this {}", ps);
@bryder
bryder / makeLambdableMethod.java
Last active January 9, 2017 03:29
How to define an interface and use it for a lamba
private interface NameOfInterface {
public List getAList(Object anArgument);
}
public void useThePassedMethod(NameOfInterface thingToRun) {
Integer thing = 1;
List createdList = thingToRun.getAList(thing);
}
public void callTheThingUsingTheInterface(){
@bryder
bryder / getLoggerForCurrentClass.java
Created December 18, 2016 00:03
Get a logger for the current class name automatically
private static final org.slf4j.Logger logger =
org.slf4j.LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
// When called in a lambda the logger name changed to java.lang.introspection.MethodHandles$lookup
@bryder
bryder / getSetPrivateFieldForTesting.java
Last active March 3, 2017 00:37
how to change private variables in java
// Using java.lang.reflect
Field field = instanceOfAClass.getClass().getDeclaredField("nameOfThePrivateVariable");
field.setAccessible(true);
Map<UUID, Long> nameOfThePrivateVariable = (Map<UUID, Long>)field.get(instanceOfAClass);
nameOfThePrivateVariable.put(aNewKey, aNewValue);
// Using org.springframework.test.util.ReflectionTestUtils
// There may be typos in the below!
Cache<UUID, UUID> aCache = (Cache<UUID, UUID>)ReflectionTestUtils.getField(instanceOfObjectWithCacheAsPrivateField, "aCache");
aCache.invalidateAll();