Skip to content

Instantly share code, notes, and snippets.

View kissgyorgy's full-sized avatar

György Kiss kissgyorgy

View GitHub Profile
@majgis
majgis / encoders.py
Created December 4, 2012 04:07
JSON Encoder and Decoder for datetime and timedelta
# Taken from http://taketwoprogramming.blogspot.com/2009/06/subclassing-jsonencoder-and-jsondecoder.html
class DateTimeAwareJSONEncoder(JSONEncoder):
"""
Converts a python object, where datetime and timedelta objects are converted
into objects that can be decoded using the DateTimeAwareJSONDecoder.
"""
def default(self, obj):
if isinstance(obj, datetime):
return {
@btbytes
btbytes / openvpn_install.txt
Created June 2, 2012 00:51
OpenVPN install using homebrew
brew install openvpn
==> Installing openvpn dependency: lzo
==> Downloading http://www.oberhumer.com/opensource/lzo/download/lzo-2.06.tar.gz
######################################################################## 100.0%
==> ./configure --prefix=/usr/local/Cellar/lzo/2.06 --enable-shared
==> make
==> make check
==> make install
/usr/local/Cellar/lzo/2.06: 27 files, 544K, built in 42 seconds
==> Installing openvpn
@terryjray
terryjray / gist:3296171
Created August 8, 2012 15:55
Enabling hstore for new postgresql 9.1 and rails 3 install on ubuntu 12.04
RAILS_ENV=production rake db:setup
# produces the error below.....hmmm.....it's a no-worky
psql:/yourprojectpath/yourproject/db/structure.sql:29: ERROR: could not open extension control file "/usr/share/postgresql/9.1/extension/hstore.control": No such file or directory
# hstore postgresql extension needs to be installed, so....
sudo apt-get install postgresql-contrib
# now your extension should be available to enable so log in with psql
psql -d yourproject_production -U yourdbuser -W
@atoponce
atoponce / instructions.md
Last active March 8, 2022 08:04
Convert any binary to an image

Convert any binary to PNG

This walk through comes from @GalacticFurball who tweeted two images representing the youtube_dl source code as of 2020-09-20. They mentioned later in the thread that they struggled converting the gzip-compressed tarball of the source code with Imagemagick to a PNG, so they ended up using a 3rd party website to do the work. This Gist will show you how to do it cleanly and exactly.

Instructions

If you would like to convert any non-image binary into PNG, Imagemagick makes this trivial. I will be executing the commands on a Debian Linux system, so you may need to adjust the commands for BSD, macOS, or Windows as necessary.

@yevgenko
yevgenko / .Xdefaults
Created August 24, 2011 02:58
URxvt settings with solarized theme
!-------------------------------------------------------------------------------
! Xft settings
!-------------------------------------------------------------------------------
Xft.dpi: 96
Xft.antialias: false
Xft.rgba: rgb
Xft.hinting: true
Xft.hintstyle: hintslight
@whatnickcodes
whatnickcodes / base64.js
Created April 24, 2014 15:01
How to Encode and Decode Strings with Base64 in JavaScript
// Create Base64 Object
var Base64={_keyStr:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",encode:function(e){var t="";var n,r,i,s,o,u,a;var f=0;e=Base64._utf8_encode(e);while(f<e.length){n=e.charCodeAt(f++);r=e.charCodeAt(f++);i=e.charCodeAt(f++);s=n>>2;o=(n&3)<<4|r>>4;u=(r&15)<<2|i>>6;a=i&63;if(isNaN(r)){u=a=64}else if(isNaN(i)){a=64}t=t+this._keyStr.charAt(s)+this._keyStr.charAt(o)+this._keyStr.charAt(u)+this._keyStr.charAt(a)}return t},decode:function(e){var t="";var n,r,i;var s,o,u,a;var f=0;e=e.replace(/[^A-Za-z0-9\+\/\=]/g,"");while(f<e.length){s=this._keyStr.indexOf(e.charAt(f++));o=this._keyStr.indexOf(e.charAt(f++));u=this._keyStr.indexOf(e.charAt(f++));a=this._keyStr.indexOf(e.charAt(f++));n=s<<2|o>>4;r=(o&15)<<4|u>>2;i=(u&3)<<6|a;t=t+String.fromCharCode(n);if(u!=64){t=t+String.fromCharCode(r)}if(a!=64){t=t+String.fromCharCode(i)}}t=Base64._utf8_decode(t);return t},_utf8_encode:function(e){e=e.replace(/\r\n/g,"\n");var t="";for(var n=0;n<e.length;n++){var r=e.charCodeAt(n);if(r
@fire
fire / 01-elementaryos-zfs.md
Last active May 5, 2022 09:46
Install Elementary Freya on ZFS root

Experimental 2015-04-25

# Create a usb disk with Elementary OS and Startup Disk Creator
# Boot it
sudo -i
apt-add-repository --yes ppa:zfs-native/stable
apt-get update
apt-get install --yes spl-dkms zfs-dkms ubuntu-zfs    

setup zfs

@philsturgeon
philsturgeon / gist:5465246
Last active May 23, 2022 12:29
API Golden Rules

Never Expose DB Results Directly

  1. If you rename a field, then your users are fucked. Convert with a hardcoded array structure.
  2. Most DB drivers [for PHP] will show integers as numeric strings and false as "0", so you want to typecast them.
  3. Unless you're using an ORM with "hidden" functionality, people will see passwords, salts and all sorts of fancy codes. If you add one and forget to put it in your $hidden array then OOPS!

Use the URI sparingly, and correctly

  1. Use the query string for paired params instead of /users/id/5/active/true. Your API does not need to be SEO optimised.
  2. ?format=xml is stupid, use an Accept: application/xml header. I added this to the CodeIgniter Rest Server once for lazy people, and now people think it's a thing. It's not.
@paulhandy
paulhandy / cleanup-zfs-snapshots
Created September 18, 2017 19:19
Clean up old zfs snapshots
https://serverfault.com/questions/340837/how-to-delete-all-but-last-n-zfs-snapshots#340846
You may find something like this a little simpler
zfs list -t snapshot -o name | grep ^tank@Auto | tac | tail -n +16 | xargs -n 1 zfs destroy -r
output the list of snapshot (names only) with zfs list -t snaphot -o name
filter to keep only the ones that match tank@Auto with grep ^tank@Auto
reverse the list (previously sorted from oldest to newest) with tac
limit output to the 16th oldest result and following with tail -n +16
@jaycosaur
jaycosaur / fanout_queue.py
Last active July 18, 2022 19:26
Async and Sync queue message multicasting to multiple queues. This is the implementation of a message fanout strategy for worker threads and processes. Note this doesn't create worker threads / processes, it only manages (in a blocking way) multicasting messages.
from typing import Type, Set, Any
from multiprocessing import Queue
import asyncio
class MulticastQueue:
def __init__(self, queue_constructor: Type[Queue] = Queue) -> None:
self.subscribers: Set[Queue] = set()
self.constructor = queue_constructor
def register(self) -> Queue: