Skip to content

Instantly share code, notes, and snippets.

View luxcem's full-sized avatar
🚀

A luxcem

🚀
View GitHub Profile
function parseHashBangArgs(aURL) {
aURL = aURL || window.location.href;
var vars = {};
var hashes = aURL.slice(aURL.indexOf('#') + 1).split('&');
for (var i = 0; i < hashes.length; i++) {
var hash = hashes[i].split('=');
@luxcem
luxcem / gist:eda431ad0c3cd8cbada0
Created February 23, 2015 17:34
Django model inheritance: create a subclass using existing super class
# https://stackoverflow.com/questions/9821935/django-model-inheritance-create-a-subclass-using-existing-super-class
class Place(models.Model):
name = models.CharField(max_length=50)
address = models.CharField(max_length=80)
class Restaurant(Place):
serves_hot_dogs = models.BooleanField()
serves_pizza = models.BooleanField()
@luxcem
luxcem / create_child_instance_from_parent.py
Last active August 29, 2015 14:23
Django Create child instance from parent instance
def create_child_instance_from_parent(child_cls, parent_instance):
parent_cls = parent_instance.__class__
field = child_cls._meta.get_ancestor_link(parent_cls).column
# We could specify a parent_identifier which is a unique field in
# the parent class that link child to parent
if hasattr(child_cls, 'parent_identifier'):
try:
child_instance = child_cls.objects.get(
**{child_cls.child_parent_identifier:
def html_diff(val1, val2):
from difflib import SequenceMatcher
if val1 is None or val2 is None:
return (val1, val2)
diff = SequenceMatcher(None, val1, val2)
op_codes = diff.get_opcodes()
offset1 = 0
offset2 = 0
for op_code in op_codes:
# encoding: utf-8
import os
import argparse
import exifread
from path import path
import dateutil.parser
def main():
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
/*
* This file handle the calls to the api and manage validation (csrf token)
* */
import 'whatwg-fetch';
export default {
getCookie(name) {
let cookieValue = null;
if (document.cookie && document.cookie !== '') {
@luxcem
luxcem / self-signed-certificate-with-custom-ca.md
Created April 4, 2018 09:27 — forked from fntlnz/self-signed-certificate-with-custom-ca.md
Self Signed Certificate with Custom Root CA

Create Root CA (Done once)

Create Root Key

Attention: this is the key used to sign the certificate requests, anyone holding this can sign certificates on your behalf. So keep it in a safe place!

openssl genrsa -des3 -out rootCA.key 4096
@luxcem
luxcem / debounced-search.js
Last active April 4, 2019 12:41
Example of a React custom hooks for searching an api.
import axios from "axios";
import { useState } from "react";
import { useDebouncedCallback } from "use-debounce";
function useSearch() {
const [value, setValue] = useState("");
const [results, setResults] = useState([]);
const [debouncedCallback] = useDebouncedCallback(value => {
axios.get("/s/?q=" + value).then(res => {
setResults(res.data.map(e => e.ref));

How to setup AWS lambda function to talk to the internet and VPC

I'm going to walk you through the steps for setting up a AWS Lambda to talk to the internet and a VPC. Let's dive in.

So it might be really unintuitive at first but lambda functions have three states.

  1. No VPC, where it can talk openly to the web, but can't talk to any of your AWS services.
  2. VPC, the default setting where the lambda function can talk to your AWS services but can't talk to the web.
  3. VPC with NAT, The best of both worlds, AWS services and web.