Skip to content

Instantly share code, notes, and snippets.

@jmcclell
jmcclell / stackoverflow_rep.py
Created December 14, 2011 16:57
Django template tag for retrieving Stackoverflow reputation score via Py-StackExchange
'''
Template tag for returning Stackoverflow reputation
Requires Py-StackExchange (https://github.com/lucjon/Py-StackExchange/)
This isn't really meant to be consumed as-is for the following reasons:
1. Built in logic for caching isn't ideal for making this distributable
2. Having a template tag reach out to a 3rd party server could cause
performance issues when rendering a template if the 3rd party server 404s
@jmcclell
jmcclell / django-paginator-bootstrap.html
Created January 6, 2012 06:02
Django Paginator Bootstrap Compatible Template Snippet
{#
This template snippet will take a page from a django Paginator and create a Twitter Bootstrap pagination HTML snippet.
To use:
{% include "path/to/django-paginator-bootstrap.html with page=contextVar only %}
Optional variables:
alignment - Accepts "centered" or "right". Other values have no affect. Default is left aligned.
# FOS Rest
fos_rest:
param_fetcher_listener: true
body_listener: true
format_listener:
rules:
path: ~
host: ~
priorities:
name: [json, html]
class Rational(initialNumer: Int = 1, initialDenom: Int = 1) {
require(initialDenom != 0, "denominator must be nonzero")
private val gcd = {
def gcdRec(x: Int, y: Int): Int = {
if(y == 0) x else gcdRec(y, x % y)
}
abs(gcdRec(initialNumer, initialDenom))
}
@jmcclell
jmcclell / gist:9749594
Created March 24, 2014 21:31
sysadmin tips
Delete a line in a file (great for removing offending keys in known_hosts)
sed -i.bak -e '134d' /root/.ssh/known_hosts
will delete line #134 and back p the file as known_hosts.bak
<?php
namespace JLM\SerializerExpressionBundle\ExpressionLanguage;
use Symfony\Component\ExpressionLanguage\ExpressionLanguage as BaseExpressionLanguage;
use Symfony\Component\ExpressionLanguage\Expression;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\ExpressionLanguage\ParserCache\ParserCacheInterface;
{% for image in images %}
{% image image.input
filter='jpegoptim' output=image.output %}
<img src="{{ asset_url }}" alt={{ image.alt }}"/>
{% endimage %}
// image.input ex: @AcmeFooBundle/Resources/public/images/example.jpg
// iamge.output ex: /images/example.jpg
/**
* @Route("/contact", name="_demo_contact")
* @Template()
*/
public function contactAction(Request $request)
{
$contact = new Contact();
// Set a default for message inside the data object itself.
// I expect that if message is missing in the request, this value will be used as the default
$contact->setMessage("Default message from controller");

Advanced Functional Programming with Scala - Notes

Copyright © 2017 Fantasyland Institute of Learning. All rights reserved.

1. Mastering Functions

A function is a mapping from one set, called a domain, to another set, called the codomain. A function associates every element in the domain with exactly one element in the codomain. In Scala, both domain and codomain are types.

val square : Int => Int = x => x * x
@jmcclell
jmcclell / Patterns.md
Last active March 20, 2018 20:08
Concurrency Patterns in Go-Lang

Concurrency Patterns in Go-Lang

Channels Primer

Creating Channels

Channels are created via the builtin make function. We specify the type as chan {datatype} where by {datatype} represents the type of data that can be written to and read from the channel.