Skip to content

Instantly share code, notes, and snippets.

🤖
👨‍💻

Radoslav Stankov RStankov

🤖
👨‍💻
View GitHub Profile
View sort_idented_todo_list.js
function buildNode(todo) {
return {
todo,
children: [],
};
}
function buildTree(todos) {
const root = buildNode();
View state_machine.js
/*
Do you use?:
Question
Alternative(product)
Note(product)
Thanks
Add to Stack:
ProductSearch
View draft.tsx
export default miniStateMachine<IComponentProps>({
initialState,
actions,
components: {
search: Search,
newProduct: NewProduct,
product: Poduct,
},
// WIP
View toast.tsx
import Flex from '~/components/Flex';
import Font from '~/components/Font';
import IconClose from './IconClose.svg';
import React from 'react';
import classNames from 'classnames';
import styles from './styles.module.css';
type IToastType = 'notice' | 'success' | 'alert';
type ICloseFn = () => void;
View initApollo.ts
import {
ApolloClient,
InMemoryCache,
HttpLink,
IntrospectionFragmentMatcher,
} from 'apollo-boost';
import { GRAPHQL_URI } from '~/config';
function createClient(initialState: any, { fetch }: { fetch: any }) {
const headers: any = {
View ibooks_clear_clipboards.rb
# frozen_string_literal: true
require 'open3'
module Clipboard
extend self
def paste
`pbpaste`
end
View next_9_2_css_modules.rb
# frozen_string_literal: true
# NOTE(rstankov): styles ignored intentionally
files = %w(components routes utils layouts hooks).map { |dir| Dir["frontend/#{dir}/**/*.css"] }.flatten
files.each do |file|
next if file.end_with?('.module.css')
`git mv #{file} #{file.gsub('.css', '.module.css')}`
`git mv #{file + '.d.ts'} #{file.gsub('.css', '.module.css.d.ts')}`
View support_graphql.rb
module SpecSupport
module GraphHelper
def execute_mutation(current_user: nil, context: {}, **inputs)
context = Graph::Context.new(
query: OpenStruct.new(schema: YourSchema),
values: context.merge(current_user: current_user),
object: nil,
)
described_class.new(object: nil, context: context, field: nil).resolve(inputs)
end
View friend_clusters.rb
# frozen_string_literal: true
require 'csv'
require 'ostruct'
require 'prettyprint'
users = {}
CSV.foreach('data.csv', headers: true) do |row|
users[row['id'].to_i] = row['friend_ids'].gsub('{', '').gsub('}', '').split(',').map(&:to_i)
end
View featureSwitch.ts
// profiles/[slug]/index.tsx
import dynamic from 'next/dynamic';
import featureSwitch from '~/utls/featureSwitch';
const page = dynamic(() => import('~/routes/profiles/show'), {
loading: () => null,
}) as any;
const legacy = dynamic(() => import('~/routes/profiles/legacy-show'), {
loading: () => null,
You can’t perform that action at this time.