Skip to content

Instantly share code, notes, and snippets.

View sashadev-sky's full-sized avatar

sashadev-sky

  • New York, NY
View GitHub Profile
@sashadev-sky
sashadev-sky / if_while_assignment.md
Created June 3, 2020 17:12
One of these things is not like the other.

"if" statement assignment:

x = 0
y = if x == 0
  puts "test"
  'pizza'
end

# test
@sashadev-sky
sashadev-sky / download.rb
Created June 3, 2020 17:15 — forked from robertjwhitney/download.rb
simple script to download an array of images over http
require 'net/http'
require 'yaml'
files = YAML.load_file("image_list.yml")
i = 1
files.each do |file|
# use root url without protocol
response = Net::HTTP.start("farm5.static.flickr.com") do |http|
http.get("#{file}")
end
puts "#{response}"
// app/assets/javascripts/beeper.js
const audio = new Audio('http://soundbible.com/grab.php?id=1815&type=mp3');
document.addEventListener('click', (event)=>{
let el = event.target;
if (el.matches('.beeper')) {
console.log("beep!");
audio.play();
el.classList.toggle("disabled");
}
});
begin
require "bundler/inline"
rescue LoadError => e
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler"
raise e
end
gemfile(true) do
source "https://rubygems.org"
gem "rails"
@sashadev-sky
sashadev-sky / jupyter_fun.ipynb
Last active December 10, 2020 07:06
Pretty Print All Cell’s Outputs (and not just the last output of the cell)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import uuid
import csv
def my_random_string(string_length=10):
"""Returns a random string of length string_length."""
random = str(uuid.uuid4()) # Convert UUID format to a Python string.
random = random.upper() # Make all characters uppercase.
random = random.replace("-", "") # Remove the UUID '-'.
return random[0:string_length] # Return the random string.
@sashadev-sky
sashadev-sky / get_exceptions_tree.py
Last active March 23, 2021 20:32
Useful exception tree reference for Python3
def print_exceptions_tree(exception_class, level=0):
if level > 1:
print(" |" * (level - 1), end="")
if level > 0:
print(" +---", end="")
print(exception_class.__name__)
for subclass in exception_class.__subclasses__():
print_exceptions_tree(subclass, level + 1)
@sashadev-sky
sashadev-sky / launch.json
Created March 27, 2021 04:18
fix error couldn't set PYTHONPATH of undefined in VSCode
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
@sashadev-sky
sashadev-sky / render_json.py
Created March 27, 2021 05:01 — forked from nerevar/render_json.py
Pretty print json in jupyter/ipython notebook
import json
import uuid
from IPython.display import display_javascript, display_html, display
class RenderJSON(object):
def __init__(self, json_data):
if isinstance(json_data, dict) or isinstance(json_data, list):
self.json_str = json.dumps(json_data)
else:
self.json_str = json_data
@sashadev-sky
sashadev-sky / blueprint.py
Created March 31, 2021 16:46 — forked from brenj/blueprint.py
Store application configuration in a Flask blueprint.
@blueprint.record_once
def record_params(state):
"""Store app.config in blueprint when blueprint is registered on app."""
app = state.app
blueprint.config = {key: value for key, value in app.config.iteritems()}