Skip to content

Instantly share code, notes, and snippets.

View un33k's full-sized avatar
🎯
Focusing

Val N. un33k

🎯
Focusing
View GitHub Profile
@un33k
un33k / authentication.ts
Created December 14, 2016 16:51 — forked from btroncone/authentication.ts
Angular 2 application role access decorator, wrapping built in CanAccess functionality. Prevents view transitions when user roles are not appropriate.
import { Injectable } from 'angular2/core';
import { Storage } from './storage';
import { CurrentUser } from '../interfaces/common';
@Injectable()
export class Authentication{
private _storageService : Storage;
private _userKey : string = "CURRENT_USER";
constructor(storageService : Storage){
@un33k
un33k / osx-pdf-from-markdown.markdown
Created November 14, 2016 20:07 — forked from georgiana-gligor/osx-pdf-from-markdown.markdown
Markdown source for the "Create PDF files from Markdown sources in OSX" article

Create PDF files from Markdown sources in OSX

When [Markdown][markdown] appeared more than 10 years ago, it aimed to make it easier to express ideas in an easy-to-write plain text format. It offers a simple syntax that takes the writer focus away from the formatting, thus giving her time to focus on the actual content.

The market abunds of editors to be used for help with markdown. After a few attempts, I settled to Sublime and its browser preview plugin, which work great for me and have a small memory footprint to accomplish that. To pass the results around to other people, less technical, a markdown file and a bunch of images is not the best approach, so converting it to a more robust format like PDF seems like a much better choice.

[Pandoc][pandoc] is the swiss-army knife of converting documents between various formats. While being able to deal with heavy-weight formats like docx and epub, we will need it for the more lightweight markdown. To be able to generate PDF files, we need LaTeX. On OSX, the s

@un33k
un33k / hash-object.js
Created November 2, 2016 15:20 — forked from colelawrence/hash-object.js
Create an md5 hash string of a javascript object using crypto createHash, update, and digest hex
var crypto = require('crypto');
exports.hashObject = function (object) {
var hash = crypto.createHash('md5')
.update(JSON.stringify(object, function (k, v) {
if (k[0] === "_") return undefined; // remove api stuff
else if (typeof v === "function") // consider functions
return v.toString();
else return v;
}))
@un33k
un33k / autoscaling_boto.py
Created January 18, 2016 19:19 — forked from numan/autoscaling_boto.py
Example of setting up AWS auto scaling using boto API
"""
The MIT License (MIT)
Copyright (c) 2011 Numan Sachwani
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
@un33k
un33k / middleware.py
Created January 11, 2016 00:21 — forked from Miserlou/middleware.py
Django Profiler
# Orignal version taken from http://www.djangosnippets.org/snippets/186/
# Original author: udfalkso
# Modified by: Shwagroo Team and Gun.io
import sys
import os
import re
import hotshot, hotshot.stats
import tempfile
import StringIO
@un33k
un33k / install_postgresql9.3_postgis2.1_ubuntu.md
Created January 5, 2016 23:25 — forked from hewerthomn/install_postgresql9.3_postgis2.1_ubuntu.md
Installing PostgreSQL 9.3 and PostGIS on Ubuntu 14.04

Remove old PostGIS Installation

The first step is to remove older version of PostGIS if any.

sudo apt-get purge postgis

Setup repository

wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ trusty-pgdg main" >> /etc/apt/sources.list.d/postgresql.list'
@un33k
un33k / gist:2a563e83518ed00d9431
Created December 7, 2015 19:49 — forked from davidwtbuxton/gist:4135069
Demonstrates logic bug in scaling function
# Test for scaling function. Python 2.7.
# http://www.nerdydork.com/django-custom-upload-handler-to-compress-image-files.html
def scale_dimensions(width, height, longest_side):
if width > longest_side:
ratio = longest_side * 1. / width
return (int(width * ratio), int(height * ratio))
elif height > longest_side:
ratio = longest_side * 1. / height
return (int(width * ratio), int(height * ratio))
return (width, height)
@un33k
un33k / crop.py
Created October 30, 2015 02:28 — forked from lucidfrontier45/crop.py
Crop 4:3 picture to 16:9 without losing EXIF metadata
#!/usr/bin/python
from PIL import Image
from pyexiv2 import ImageMetadata
def is16to9(img):
img.size
return img.size[0] * 9 == img.size[1] * 16
def cropTo16to9(img):
@un33k
un33k / markdown.md
Last active September 7, 2015 01:35 — forked from jonschlinkert/markdown-cheatsheet.md
A better markdown cheatsheet. I used Bootstrap's Base CSS documentation as a reference.

Typography

Headings

Headings from h1 through h6 are constructed with a # for each level:

# h1 Heading
## h2 Heading
### h3 Heading
@un33k
un33k / sv-sign-up-form.jade
Last active August 29, 2015 14:27 — forked from SvitlanaShepitsena/sv-sign-up-form.jade
Lumx form (Tutorial: Advanced form validation with AngularJs using compile service. AngularJs tutorial )
div(flex-container='column')
.card
div(class='p+')
span.display-block.fs-title.mb {{title|translate}}
.divider.divider--dark
form.mt(name='signUpForm' novalidate sv-form-val)
div(flex-container='column' flex)
div(flex-item='')
lx-text-field(label='{{name|translate}}')
input(type='text'