Skip to content

Instantly share code, notes, and snippets.

View jittdev's full-sized avatar

Subrosa Games LLC jittdev

View GitHub Profile
@jittdev
jittdev / VariableStorage1.cpp
Created March 14, 2023 13:58
Variable Storage :: #C++
/* 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
@jittdev
jittdev / AjaxToUpdateStockView1.rb
Created March 14, 2023 13:58
Ajax to update Stock view :: #api - ruby backend
# 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
@jittdev
jittdev / GrantAllPrivilegesToNewUser1.txt
Created March 14, 2023 13:58
Grant all privileges to new user :: #DataGrip
grant all privileges on database.* to username
@jittdev
jittdev / SafelyRemoveFileByInodenumber1.sh
Created March 14, 2023 13:58
SAFELY remove file by iNodeNumber :: #shell
sudo find . -inum 79707947 -exec rm -i {} \;
where 79707949 is InodeNumber that you found by using ls -il
@jittdev
jittdev / SettingItUp1.rb
Created March 14, 2023 13:58
setting it up :: #RSpec
# 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
@jittdev
jittdev / FromArrayImportArray1.py
Created March 14, 2023 13:58
from array import array :: #Python Advanced
# 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
@jittdev
jittdev / Enumerate1.py
Created March 14, 2023 13:57
enumerate :: #Python Basics
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}')
@jittdev
jittdev / TimeDecorator1.py
Created March 14, 2023 13:57
time decorator :: #Python Advanced
#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
@jittdev
jittdev / MethodResolutionOrderMro1.py
Created March 14, 2023 13:57
Method Resolution Order mro :: #Python Basics
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:
@jittdev
jittdev / Api.JsAndAxios1.js
Created March 14, 2023 13:57
api.js and axios :: #VUE
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);