Skip to content

Instantly share code, notes, and snippets.

View teyfix's full-sized avatar

Halil Teyfik teyfix

  • Istanbul, Turkey
View GitHub Profile
@teyfix
teyfix / setUser.js
Created June 21, 2021 18:54
vuex - setting user info
const store = Vuex.Store({
state: {
user: null,
},
mutations: {
setUser(state, user) {
state.user = user;
},
},
});
@teyfix
teyfix / authorize.js
Created June 21, 2021 19:01
vuex - authorizing user
const authorize = async (username, password) => {
const response = await fetch('/login', {
method: 'post',
body: {
username,
password,
},
});
const session = await response.json();
@teyfix
teyfix / login.js
Last active June 21, 2021 19:05
vuex - logging user in with an action
const store = Vuex.Store({
state: {
user: null,
},
mutations: {
setUser(state, user) {
state.user = user;
},
},
actions: {
@teyfix
teyfix / appLogin.js
Last active June 21, 2021 19:18
vuex - login component
Vuex.component('app-login', {
template: `
<section>
<header>
<h1>Giriş yap</h1>
</header>
<main v-if="user">
<p>{{ user.username }} olarak giriş yapıldı</p>
</main>
@teyfix
teyfix / helloWorld.jsx
Last active June 23, 2021 05:32
react - hello world
const HelloWorld = () => (
<section>
<h1>Merhaba dünya!</h1>
</section>
);
ReactDOM.render(
HelloWorld,
document.getElementById('root'),
);
@teyfix
teyfix / useState.jsx
Last active June 23, 2021 05:32
react - use state
const HelloWorld = () => {
const [show, setShow] = useState(false);
return (
<section>
<h1>Merhaba dünya!</h1>
{show ? <p>Günaydın.</p> : null}
<button onClick={() => setShow(!show)}>Merhaba!</button>
</section>
);
@teyfix
teyfix / props.jsx
Created June 23, 2021 05:32
react - using props
const HelloWorld = () => {
const [show, setShow] = useState(false);
return (
<section>
<h1>Merhaba dünya!</h1>
<GoodMorning show={show} />
<button onClick={() => setShow(!show)}>Merhaba!</button>
</section>
);
@teyfix
teyfix / api.js
Created June 23, 2021 06:10
react - json placeholder api helper
const api = async (endpoint) => {
const url = new URL(
endpoint,
'https://jsonplaceholder.typicode.com',
).toString();
const response = await fetch(url);
if (response.status === 200) {
return response.json();
}
@teyfix
teyfix / steam.js
Created September 29, 2022 05:57
User Scripts/Steam History - Calculates the payment history at https://store.steampowered.com/account/history
(() => {
const pattern = new RegExp("https://store.steampowered.com/account/history");
if (!pattern.test(window.location.href)) {
return;
}
let last;
const content = (item) =>
(item.querySelector("div") ?? item).innerText.replace(/\s+/g, " ").trim();
@teyfix
teyfix / bh_ranked.js
Created September 29, 2022 05:59
User Scripts/Brawlhalla - Calculates the winrate of the users in ranked list on https://www.brawlhalla.com/rankings
setTimeout(() => {
const domain = 'https://www.brawlhalla.com/rankings';
if (!window.location.href.startsWith(domain)) {
return;
}
const input = document.querySelector("input[name=p]");
if (input) {