Skip to content

Instantly share code, notes, and snippets.

View benjbaron's full-sized avatar

Benjamin Baron benjbaron

View GitHub Profile
@benjbaron
benjbaron / postgres_queries_and_commands.sql
Created January 15, 2021 22:41 — forked from rgreenjr/postgres_queries_and_commands.sql
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(clock_timestamp(), query_start), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
@benjbaron
benjbaron / redis_cheatsheet.bash
Created May 14, 2019 12:44 — forked from LeCoupa/redis_cheatsheet.bash
Redis Cheatsheet - Basic Commands You Must Know --> UPDATED VERSION --> https://github.com/LeCoupa/awesome-cheatsheets
# Redis Cheatsheet
# All the commands you need to know
redis-server /path/redis.conf # start redis with the related configuration file
redis-cli # opens a redis prompt
# Strings.
package types
import (
"encoding/json"
"time"
)
// FIXME: This does not currently work with JSON's omitempty.
// See: https://github.com/golang/go/issues/11939

IntelliJ shortcuts

Reference: https://vimeo.com/98922030

  1. Do not use tabs, deactivate them in the preference panel.
  2. Naviguate through files using CMD+E and CMD-SHIFT-E (last edited files)
  3. Highlight usages with SHIFT-CMD-F7
  4. Get rid of everything with SHIFT-CMD-F12 (full mode)
  5. Select blocks of text with ALT+UP ARROW
  6. Move blocks up and down with SHIFT+ALT+UP
func Benchmark_append(b *testing.B) {
b.StopTimer()
b.ReportAllocs()
b.StartTimer()
for i := 0; i < 1000; i++ {
var a []int
for i := 0; i < 100000; i++ {
a = append(a, i)
@benjbaron
benjbaron / .gitconfig
Created March 16, 2019 21:51
.gitconfig
[github]
user = benjbaron
[push]
default = current
[pull]
rebase = true
[alias]
st = status
stp = status --porcelain
ci = commit --amend --no-edit
@benjbaron
benjbaron / multiprocessing_two_processes.py
Created April 26, 2018 13:32
Use the `multiprocessing` lbrary to run two processes `f1` and `f2` in parallel and get their respective outputs.
import time
from multiprocessing import Pool
# can also work with ThreadPool, by importing
# from multiprocessing.dummy import Pool
def f1(a,b):
print("run f1(%s,%s)" % (a,b))
time.sleep(2)
print("end f1")
@benjbaron
benjbaron / The Technical Interview Cheat Sheet.md
Created May 22, 2016 07:58 — forked from tsiege/The Technical Interview Cheat Sheet.md
This is my technical interview cheat sheet. Feel free to fork it or do whatever you want with it. PLEASE let me know if there are any errors or if anything crucial is missing. I will add more links soon.

Studying for a Tech Interview Sucks, so Here's a Cheat Sheet to Help

This list is meant to be a both a quick guide and reference for further research into these topics. It's basically a summary of that comp sci course you never took or forgot about, so there's no way it can cover everything in depth. It also will be available as a gist on Github for everyone to edit and add to.

Data Structure Basics

###Array ####Definition:

  • Stores data elements based on an sequential, most commonly 0 based, index.
  • Based on tuples from set theory.
void OGRLayer::SetSpatialFilterRect( double dfMinX, double dfMinY,
double dfMaxX, double dfMaxY )
{
OGRLinearRing oRing;
OGRPolygon oPoly;
oRing.addPoint( dfMinX, dfMinY );
oRing.addPoint( dfMinX, dfMaxY );
oRing.addPoint( dfMaxX, dfMaxY );
@benjbaron
benjbaron / checkFile.cpp
Created July 16, 2015 17:06
Qt check whether there is a file with the given extensions
QString checkFile(QString foldername, QStringList exts, QString filename) {
foreach(auto ext, exts) {
QFileInfo check(foldername+"/"+filename+"."+ext);
if(check.exists() && check.isFile())
return check.absoluteFilePath();
return QString();
}
}