Skip to content

Instantly share code, notes, and snippets.

@ysfzrn
ysfzrn / CounterManager.m
Created January 18, 2023 07:25 — forked from velopert/CounterManager.m
React Native iOS Native Component with Swift
#import <React/RCTViewManager.h>
@interface RCT_EXTERN_MODULE(CounterManager, RCTViewManager)
RCT_EXPORT_VIEW_PROPERTY(value, NSNumber)
RCT_EXPORT_VIEW_PROPERTY(leftButtonText, NSString)
RCT_EXPORT_VIEW_PROPERTY(rightButtonText, NSString)
RCT_EXPORT_VIEW_PROPERTY(onPressLeftButton, RCTDirectEventBlock)
RCT_EXPORT_VIEW_PROPERTY(onPressRightButton, RCTDirectEventBlock)
@ysfzrn
ysfzrn / polyline_decoder.js
Created March 25, 2021 12:32 — forked from ismaels/polyline_decoder.js
Javascript function to decode google maps api polyline
// source: http://doublespringlabs.blogspot.com.br/2012/11/decoding-polylines-from-google-maps.html
function decode(encoded){
// array that holds the points
var points=[ ]
var index = 0, len = encoded.length;
var lat = 0, lng = 0;
while (index < len) {
var b, shift = 0, result = 0;
function transformOrigin(matrix, origin) {
const { x, y, z } = origin;
const translate = MatrixMath.createIdentityMatrix();
MatrixMath.reuseTranslate3dCommand(translate, x, y, z);
MatrixMath.multiplyInto(matrix, translate, matrix);
const untranslate = MatrixMath.createIdentityMatrix();
MatrixMath.reuseTranslate3dCommand(untranslate, -x, -y, -z);
MatrixMath.multiplyInto(matrix, matrix, untranslate);
@ysfzrn
ysfzrn / change_primary_key.md
Created February 18, 2018 01:44 — forked from scaryguy/change_primary_key.md
How to change PRIMARY KEY of an existing PostgreSQL table?
-- Firstly, remove PRIMARY KEY attribute of former PRIMARY KEY
ALTER TABLE <table_name> DROP CONSTRAINT <table_name>_pkey;
-- Then change column name of  your PRIMARY KEY and PRIMARY KEY candidates properly.
ALTER TABLE <table_name> RENAME COLUMN <primary_key_candidate> TO id;
@ysfzrn
ysfzrn / .jsx
Created February 1, 2018 10:23
StyledSelectField
import React from "react";
import styled, { keyframes } from "styled-components";
import { observer } from "mobx-react";
import { detectmob } from "../utils/sharedStyle";
import { List, AutoSizer } from "react-virtualized";
let ClickOutComponent = require("react-onclickout");
const ArrowDown = require("../public/assets/arrow-down.png");
const isMob = detectmob();
//src/stores/gameStore.js
...
class GameStore{
...
@action("restart handler")
handleRestart(){
NavigationStore.handleChangeRoute('gameScreen');
this.intervalRate = 5;
this.currentDirection = "right";
this.lastSegment = 10;
//src/stores/gameStore.js
...
class GameStore{
...
@action("Snake is moving")
handleMoveSnake =() => {
...
//isGameOver control
for(let i = 1; i < this.snake.slice().length; i++){
if(this.snake[0].x === this.snake[i].x && this.snake[0].y === this.snake[i].y ){
@action("Did the snake eat the food ?")
handleEatFood() {
if (this.snake[0].x === this.food.x && this.snake[0].y === this.food.y) {
this.score = this.score + 1;
this.snake.push({
id: this.snake[this.snake.length - 1].id + 1,
x: this.snake[this.snake.length - 1].x,
y: this.snake[this.snake.length - 1].y
});
if( this.score % 3 === 0 ){
...
<Board>
{snake.map((segment, i) => {
return <Segment key={segment.id} id={segment.id} x={segment.x} y={segment.y} />;
})}
<Food x={ gameStore.food.x } y={ gameStore.food.y }/>
</Board>
...
// src/stores/gameStore.js
class GameStore {
...
@observable food = { x: 50, y: 50 }; //elmanın başlangıçta belireceği yer.
...
@action("make food")
handleMakeFood() {
const frameX = (boardWidth -10) / segmentRate;
const frameY = BoardHeight / segmentRate;
this.food.x = this.getRandomInt(0, frameX) * segmentRate;