Skip to content

Instantly share code, notes, and snippets.

describe('ProductService', () => {
let service: ProductService
let servicMock: Partial<ProductService>
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
imports: [AppModule],
}).compile()
service = module.get<ProductService>(ProductService)
{
"id": "msg_01TioynCv5SbDGXsLLUnUPTL",
"type": "message",
"role": "assistant",
"model": "claude-3-5-sonnet-20240620",
"content": [
{
"type": "text",
"text": "AN AMAZING DESCRIPTION"
}
@Akifcan
Akifcan / product.service.ts
Created October 29, 2024 21:39
product.service.ts
import Anthropic from '@anthropic-ai/sdk'
@Injectable()
export class ProductService {
@Inject() configService: ConfigService
createProductDescription(productName: string){
const anthropicConfig = this.configService.get<AntrhopicConfig>('anthropic')
const anthropic = new Anthropic({ apiKey: anthropicConfig.secret })
@Akifcan
Akifcan / HOC
Created July 28, 2024 15:28
my map polypill
const nums = [17, 1, 2, 3, -1]
const obj = (x) => {
return {initial: x, square: x*x, positive: Math.sign(x) > 0 ? true : false}
}
Array.prototype.myMap = function(cb){
const output = []
for(let i = 0; i<this.length; i++){
output.push(cb(this[i]))
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>UFA Interactive SVG</title>
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
<link rel="apple-touch-icon" href="/apple-touch-icon.png" />
<style>
@Akifcan
Akifcan / script.js
Created December 24, 2023 21:08
react-native-image-color-pick-3
let imagePath: string = ''
const resp = await RNFetchBlob.config({
fileCache: true,
}).fetch('GET', url)
imagePath = resp.path()
const base64 = await resp.readFile('base64')
fs.unlink(imagePath)
@Akifcan
Akifcan / script.js
Created December 24, 2023 21:05
react-native-image-color-pick-2
<WebView
originWhitelist={['*']}
source={{ html: script }}
javaScriptEnabled={true}
onMessage={(event) => {
if (!event.nativeEvent?.data) {
return;
}
console.log(event.nativeEvent.data);
}}
@Akifcan
Akifcan / script.js
Created December 24, 2023 21:04
react-native-image-color-pick
const script = `
<script>
function get_average_rgb(img) {
var context = document.createElement('canvas').getContext('2d');
var src = img;
img = new Image;
img.setAttribute('crossOrigin', '');
img.src = "data:image/png;base64," + src;
img.onload = function () {
context.imageSmoothingEnabled = true;
@Akifcan
Akifcan / swiper.clone.js
Created January 18, 2023 19:13
Swiper clone
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
.slider {
@Akifcan
Akifcan / cache.interceptor.ts
Last active October 20, 2022 20:07
Cache interceptor
import {Injectable, NestInterceptor, ExecutionContext, CallHandler, Inject, Logger} from '@nestjs/common'
import {map, Observable, tap} from 'rxjs'
import {RedisService} from './redis.service'
@Injectable()
export class CacheInterceptor implements NestInterceptor {
@Inject() redisService: RedisService
async intercept(context: ExecutionContext, next: CallHandler): Promise<Observable<any>> {
if (process.env.NODE_ENV.includes('development')) {