Skip to content

Instantly share code, notes, and snippets.

View yoniLavi's full-sized avatar
:octocat:
Figuring things out

Yoni Lavi yoniLavi

:octocat:
Figuring things out
View GitHub Profile
@yoniLavi
yoniLavi / djangolight_onefile.py
Last active February 27, 2017 16:19
Example of simplest possible Django Project
# Based on the book 'Lightweight Django'
# by Mark Lavin & Julia Elman
# See the following Repo for this example broken into multiple files.
# https://github.com/richardadalton/djangolight
from django.core.management import execute_from_command_line
from django.conf import settings
from django.conf.urls import url
from django.http import HttpResponse
@yoniLavi
yoniLavi / angular-jqlite.adoc
Created June 16, 2017 12:19 — forked from esfand/angular-jqlite.adoc
Angular jqLite

Angular jqLite

jQuery and Angular

Angular doesn’t depend on jQuery. In fact, the Angular source contains an embedded lightweight alternative: jqLite. Still, when Angular detects the presence of a jQuery version in your page, it uses that full jQuery implementation in lieu of jqLite. One direct way in which this manifests itself is with Angular’s element abstraction. For example, in a directive you get access to the element that the directive applies to:

"""A very basic url-based chat"""
from flask import Flask, redirect
app = Flask(__name__) # the flask application object
messages = ['System: Hi everyone'] # a global object for all chat messages
def all_messages():
"""Helper function to get a string of all chat messages, one per line"""
return '<br>'.join(messages)
"""A very basic url-based chat"""
from flask import Flask, redirect
app = Flask(__name__) # the flask application object
messages = ['System: Hi everyone'] # a global object for all chat messages
def all_messages():
"""Helper function to get a string of all chat messages, one per line"""
return '<br>'.join(messages)
@yoniLavi
yoniLavi / set_python3.sh
Last active August 14, 2017 17:14
Set Python 3 as the default and enable virtualenvwrapper
set -e # we exit on error, but otherwise all the commands are quiet
sudo pip -q install virtualenvwrapper
grep -q 'VIRTUALENV_PYTHON' ~/.bashrc || (echo 'export VIRTUALENV_PYTHON=/usr/bin/python3' >>~/.bashrc)
grep -q 'virtualenvwrapper.sh' ~/.bashrc || (echo 'source /usr/local/bin/virtualenvwrapper.sh' >>~/.bashrc)
grep -q 'Welcome to your Code Institute' ~/.bashrc || (echo 'echo "Hi $C9_USER, welcome to your Code Institute Python workspace in c9, remember to use the mkvirtualenv and workon commands for your projects"' >>~/.bashrc)
source ~/.bashrc
@yoniLavi
yoniLavi / tabclosing.html
Created October 2, 2017 12:47
Tab closing in JS
<!DOCTYPE html>
<html>
<head>
<title>Tab closing in JS</title>
<script >
function openTab() {
open(location.href+"#jsopened");
}
function closeTab() {
if (location.hash.endsWith("jsopened")) {
from functools import lru_cache
@lru_cache(maxsize=1000)
def coincount(coinlist, amount):
if not amount:
return 1
if not coinlist:
return 0
Afghanistan
Albania
Algeria
Angola
Antarctica
Argentina
Armenia
Australia
Austria
Azerbaijan
@yoniLavi
yoniLavi / toggleNames.js
Created August 31, 2018 17:24
Toggle names on Class Profiles
// Go to the Class Profiles page in your desktop browser (doesn't matter which one you use):
// https://sisweb.ucd.ie/usis/W_HU_REPORTING.P_DISPLAY_QUERY?p_code1=B036Y1&p_query=OB200-1
// Open the developer tools console, every browser has a slightly different way to open it
// Paste the following into it, and then close it.
// From now on, pressing the Spacebar will toggle the visibiltiy of the names on the page.
// This only applies to that particular session, and will be forgotten when you reopen the page.
$(document).keypress(function(event) {
if (event.keyCode == 32) { // Spacebar
@yoniLavi
yoniLavi / surveymonkeyextract.js
Created November 7, 2018 22:34
Some hacky code to copy an individual respondent's data out of surveymonkey
function extractRespondentAnswers(respondentElem) {
let answers = Array.from(respondentElem.querySelectorAll('.response-text'));
return answers
.map(elem =>
elem.parentElement.parentElement.parentElement.parentElement.parentElement
.querySelector('.response-question-title-text').innerText
+ (elem.previousElementSibling ? ">" + elem.previousElementSibling.innerText : "")
+ '\t' + elem.innerText
).join('\n');