Skip to content

Instantly share code, notes, and snippets.

@oinopion
oinopion / read-access.sql
Created Oct 5, 2016
How to create read only user in PostgreSQL
View read-access.sql
-- Create a group
CREATE ROLE readaccess;
-- Grant access to existing tables
GRANT USAGE ON SCHEMA public TO readaccess;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO readaccess;
-- Grant access to future tables
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO readaccess;
@peterhurford
peterhurford / num_rows_csv.R
Last active Feb 25, 2021
What's the fastest way to determine the number of rows of a CSV in R?
View num_rows_csv.R
# What's the fastest way to determine the number of rows of a CSV in R?
# ...Reading the entire CSV to only get the dimensions is likely too slow. Is there a faster way?
# Benchmarks done on a EC2 r3.8xlarge
# Cowritten with Abel Castillo <github.com/abelcastilloavant>
m <- 1000000
d <- data.frame(id = seq(m), a = rnorm(m), b = runif(m))
dim(d)
# [1] 1000000 3
pryr::object_size(d)
@e-mon
e-mon / Dinic.py
Created May 28, 2015
Dinic's Algorithm
View Dinic.py
class Dinic:
class Edge:
def __init__(self, to, cap, rev):
self.to = to
self.cap = cap
self.rev = rev
def __repr__(self):
return "(to: {0} cap: {1} rev: {2})".format(self.to, self.cap, self. rev)
View My Exiftool Cheatsheet.md

Last updated: 2017-03-18

Searching for Files

Find images in a directory that don't have a DateTimeOriginal

exiftool -filename -filemodifydate -createdate -r -if '(not $datetimeoriginal) and $filetype eq "JPEG"' .

###Output photos that don't have datetimeoriginal to a CSV### Note this can take a long time if you have a lot of jpgs

@FichteFoll
FichteFoll / find_scopes.py
Last active May 8, 2016 — forked from sparr/scopecount
Download color schemes and count the occuring atomic scopes
View find_scopes.py
#!/usr/bin/env python3
import requests
import plistlib
from collections import Counter
import posixpath
from urllib.parse import urlsplit
import sys
import os
@sparr
sparr / scopecount
Last active May 8, 2016
SublimeText theme gallery scope usage count
View scopecount
574 : string [std]
311 : source
278 : entity [std]
253 : keyword [std]
242 : comment [std]
236 : entity.name.tag
229 : constant [std]
212 : support.function [std]
209 : storage [std]
209 : entity.other.attribute-name
@wch
wch / speed.r
Last active Oct 23, 2020
Modifying objects in loops in R, and other speed pitfalls
View speed.r
# =============================================
# Modifying a data frame in place
# =============================================
library(ggplot2)
str(diamonds)
# Modify data frame in place, in loop
# This is super, super slow
system.time({
@kosh04
kosh04 / sizseof.c
Created Sep 15, 2011
sizeof演算子で変数の大きさを調べる
View sizseof.c
#include <stdio.h>
#include <stdint.h>
#include <stddef.h>
#include <sys/types.h>
#include <wchar.h>
#include <time.h>
// XXX: "%zd" format cannot work in VC, MinGW
#define prints(type) printf(#type "\t\t" "%lu\n", (unsigned long)sizeof(type))