Skip to content

Instantly share code, notes, and snippets.

View sjbitcode's full-sized avatar
:octocat:

Sangeeta Jadoonanan sjbitcode

:octocat:
View GitHub Profile
@TunedMystic
TunedMystic / changefileperms.sh
Created June 3, 2019 03:47
Change File Permissions
alias changefileperms='find . -type d -perm 777 -exec chmod 755 {} \; && find . -type f -perm 777 -exec chmod 644 {} \;'
@TunedMystic
TunedMystic / random_name_adj_noun.py
Created March 8, 2018 22:03
Generate a name from a random adjective and a random noun.
import random
adjectives = ['ashy', 'black', 'blue', 'gray', 'green', 'icy', 'lemon', 'mango', 'orange', 'purple', 'red', 'salmon', 'white', 'yellow', 'aggressive', 'agreeable', 'ambitious', 'brave', 'calm', 'delightful', 'eager', 'faithful', 'gentle', 'happy', 'jolly', 'kind', 'lively', 'nice', 'obedient', 'polite', 'proud', 'silly', 'thankful', 'victorious', 'witty', 'wonderful', 'zealousangry', 'bewildered', 'clumsy', 'defeated', 'embarrassed', 'fierce', 'grumpy', 'helpless', 'itchy', 'jealous', 'lazy', 'mysterious', 'nervous', 'obnoxious', 'panicky', 'pitiful', 'repulsive', 'scary', 'thoughtless', 'uptight', 'worried']
nouns = ['antelope', 'badger', 'mastif', 'bear', 'beaver', 'bobcat', 'chipmunk', 'coyote', 'deer', 'mule', 'elk', 'fox', 'gopher', 'lion', 'mouse', 'cactus', 'pinyon', 'pocket', 'muskrat', 'otter', 'porcupine', 'rabbit', 'cottontail', 'jack', 'raccoon', 'rat', 'kangaroo', 'pack', 'wood', 'ringtail', 'vagrant', 'skunk', 'hooded', 'striped', 'spotted', 'squirrel']
def random_name():
adj
from click import command, option, Option, UsageError
class MutuallyExclusiveOption(Option):
def __init__(self, *args, **kwargs):
self.mutually_exclusive = set(kwargs.pop('mutually_exclusive', []))
help = kwargs.get('help', '')
if self.mutually_exclusive:
ex_str = ', '.join(self.mutually_exclusive)
kwargs['help'] = help + (
@cecilemuller
cecilemuller / letsencrypt_2020.md
Last active April 15, 2024 02:19
How to setup Let's Encrypt for Nginx on Ubuntu 18.04 (including IPv6, HTTP/2 and A+ SSL rating)

How to setup Let's Encrypt for Nginx on Ubuntu 18.04 (including IPv6, HTTP/2 and A+ SLL rating)


Virtual hosts

Let's say you want to host domains first.com and second.com.

Create folders for their files:

@awesomebytes
awesomebytes / ipython_to_file.md
Created March 16, 2016 10:38
Save iPython session to a python file as code

Save an iPython session commands/code to a file

You must use the magic method %save:

In [1]: %save?
Type:       Magic function
String Form:<bound method CodeMagics.save of <IPython.core.magics.code.CodeMagics object at 0x7fb5d25bb1d0>>
Namespace:  IPython internal
File: /usr/lib/python2.7/dist-packages/IPython/core/magics/code.py
@chantastic
chantastic / on-jsx.markdown
Last active May 30, 2024 13:11
JSX, a year in

Hi Nicholas,

I saw you tweet about JSX yesterday. It seemed like the discussion devolved pretty quickly but I wanted to share our experience over the last year. I understand your concerns. I've made similar remarks about JSX. When we started using it Planning Center, I led the charge to write React without it. I don't imagine I'd have much to say that you haven't considered but, if it's helpful, here's a pattern that changed my opinion:

The idea that "React is the V in MVC" is disingenuous. It's a good pitch but, for many of us, it feels like in invitation to repeat our history of coupled views. In practice, React is the V and the C. Dan Abramov describes the division as Smart and Dumb Components. At our office, we call them stateless and container components (view-controllers if we're Flux). The idea is pretty simple: components can't

@benbacardi
benbacardi / gist:227f924ec1d9bedd242b
Last active May 12, 2024 09:55
Django reverse with a querystring
from django.utils.http import urlencode
def reverse_querystring(view, urlconf=None, args=None, kwargs=None, current_app=None, query_kwargs=None):
'''Custom reverse to handle query strings.
Usage:
reverse('app.views.my_view', kwargs={'pk': 123}, query_kwargs={'search': 'Bob'})
'''
base_url = reverse(view, urlconf=urlconf, args=args, kwargs=kwargs, current_app=current_app)
if query_kwargs:
return '{}?{}'.format(base_url, urlencode(query_kwargs))
@shrayasr
shrayasr / bulk-insert-sa.md
Last active December 11, 2020 16:04
Bulk Inserts via SQLAlchemy and Flask-SQLAlchemy

Bulk Inserts via SQLAlchemy and Flask-SQLAlchemy

Problem

I ran into an issue today where I had to perform a bulk insert into a postgres DB. I was already using SQLAlchemy and Flask-SQLAlchemy to manage the connections to the db and I didn't want to have to use things like psycopg2 directly.

Solution

Note: SQLAlchemy provides an ORM. It isn't just an ORM. That is an important thing to be kept in mind. This means that you can bypass choose to not use the ORM layer when you don't want it. The idea with an ORM is to track changes to objects and when you have a case like that is when you'd use the ORM. In a bulk upload scenario, you don't need to track changes to objects. All you care is that everything be pushed into the DB.

@adamghill
adamghill / views.js
Last active March 15, 2024 22:00
Django AJAX forms. Uses a bunch of requirements installed in https://github.com/adamghill/django-template.
(function() {
$('a.button').click(function(e) {
var $form = $("#form");
$('#error').hide();
$('input').removeClass('error');
var handleError = function() {
$('#error').show();
}
@adamghill
adamghill / messages_and_errors_django_template.html
Created January 3, 2014 21:20
Show messages and errors in Django templates. Useful to just throw in a base template.
{% if messages %}
{% for message in messages %}
<div class="alert {% if message.tags %} alert-{{ message.tags }}{% endif %}">{{ message|safe }}</div>
{% endfor %}
{% endif %}
{% if form.errors %}
<div class="alert alert-error">
<h4>Please fix the following errors</h4>
<ul>