Skip to content

Instantly share code, notes, and snippets.

@eupharis
eupharis / rootscope_in_run.js
Last active December 24, 2015 10:59
Angular $rootScope in run method
var renderer2 = angular.module('pak', ['pak.filters', 'pak.services',...]);
renderer2.run(['$rootScope', function($rootScope) {
$rootScope.some_function = function() {
console.log('HELLO WORLD!!!!');
};
// function is available in all CHILD SCOPES
}]);
@eupharis
eupharis / django_template_datetime_in_code.py
Created October 23, 2013 23:05
A nice way to get Python strings to be that nice default Django template datetime format.
from django.template import defaultfilters
from django.utils import timezone
localtime = timezone.template_localtime(my_date)
template_style_date = defaultfilters.date(localtime, settings.DATETIME_FORMAT)
# settings.DATETIME_FORMAT is the Django default by default, but can be overwritten in your settings.py
@eupharis
eupharis / django_test_sqlite3.py
Last active December 27, 2015 15:09
faster django tests
if 'test' in sys.argv:
DATABASES['default']['ENGINE'] = 'django.db.backends.sqlite3'
.directive('addRemoveUsers', ['$state', function($state) {
return {
link: function(scope, element, attrs) {
element.on('click', function() {
scope.$apply(function() {
if (scope.circle.all_circle) {
var msg = [
"An admin group's all circle contains all its users.",
"To remove users from this circle, please remove them",
"from the admin group."
/* http://nanobar.micronube.com/ || https://github.com/jacoborus/nanobar/ MIT LICENSE */
var Nanobar = (function () {
'use strict';
var addCss, animation, transEvent, createBar, Nanobar,
css = '.nanobar{float:left;width:100%;height:4px;z-index:9999;}.nanobarbar{width:0;height:100%;float:left;transition:all .3s;}',
head = document.head || document.getElementsByTagName( 'head' )[0];
// Create and insert style element in head if not exists
total = 0
RATE_OF_RETURN = 0.10
for i in range(1, 11, 2):
total += 23000 * ((1 + RATE_OF_RETURN) ** i)
# total in Roth IRA after 5 years
print total
# just earnings
print total - (5 * 23000)
@eupharis
eupharis / angular-resolve.js
Created December 8, 2014 23:56
Example of angular resolve with "class" resolve and ensuring data is current on every route change.
(function() {
"use strict";
angular.module('JobListingApp')
.config(['$routeProvider', function($routeProvider) {
// ListingRoute "class" to ensure that all routes have
// current data in JobListings before they execute a route's controllers
var ListingRoute = function(params) {
angular.extend(this, params);
};
@eupharis
eupharis / states_by_fips.json
Last active January 19, 2022 19:36
State FIPS JSON (Abbreviation and Name)
{
"01": {
"abbreviation": "AL",
"name": "Alabama"
},
"02": {
"abbreviation": "AK",
"name": "Alaska"
},
"03": {
STATE_TZ_MAP = {
'AK': 'US/Alaska',
'AL': 'US/Central',
'AR': 'US/Central',
'AS': 'US/Samoa',
'AZ': 'America/Phoenix', # Arizona is weird!
'CA': 'US/Pacific',
'CO': 'US/Mountain',
'CT': 'US/Eastern',
'DC': 'US/Eastern',