This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* In C++, an instance of a variable can be stored directly in memory, accessed by pointer, or accessed by reference: | |
Cube c; | |
Cube *ptr = &c; | |
Cube &r = c; */ | |
// A reference variable has no memory/size; it is only an alias to another variable. | |
// Storage by pointer | |
Cube *c; // Pointer to a Cube in memory | |
int *i; // Pointer to an integer in memory |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# submit the form as an Ajax request instead of regular form submission. | |
# this is called an XHR request | |
# then add Javascript to update only part of the page | |
# move the view block to a partial | |
_result.html.erb | |
<div class="results-block"> | |
<%= render 'layouts/messages' %> #when using ajax, must redefine error flash path |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
grant all privileges on database.* to username |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sudo find . -inum 79707947 -exec rm -i {} \; | |
where 79707949 is InodeNumber that you found by using ls -il | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# when creating new rails app add -T to skip minitest | |
rails new app_name -T | |
#in Gemfile under group :test do | |
gem 'rspec-rails' | |
# should also have gem 'capybara', gem 'selenium-webdriver', gem 'webdrivers' | |
#then run | |
bundle install |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://docs.python.org/3/library/array.html#module-array | |
from array import array | |
#arrays take up less memory than lists and perform more quickly | |
# array(type_code, []) | |
arr = array('i', [1,2,3]) #i = signed integer type_code |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for i,char in enumerate('Helllooo'): | |
print(i, char) | |
# if you need the index counter of what you're iterating through | |
for i,char in enumerate(list(range(10))): | |
print(i, char) | |
if char == 5: | |
print(f'index of 50 is: {i}') | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Decorator | |
from time import time #built in module | |
def performance(fn): | |
def wrapper(*args, **kwargs): | |
t1 = time() | |
result = fn(*args, **kwargs) | |
t2 = time() | |
print(f'took {t2-t1} s') | |
return result | |
return wrapper |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class X:pass | |
class Y:pass | |
class Z:pass | |
class A(X,Y):pass | |
class B(Y,Z):pass | |
class M(B,A,Z):pass #B is passed before A | |
print(M.__mro__) | |
# or can use this syntax for mro: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import axios from 'axios'; | |
export function listTasks () { | |
return axios.get('/jasks.json').then(function(response){ | |
return response.data; | |
}) | |
} | |
listTasks().then(function(response){ | |
console.log(response); |