fabi.s

All generations.

generate functionSat, 05 Nov 2022

get date

func getDate() -> String { let date = Date() let calendar = Calendar.current let year = calendar.component(.year, from: date) let month = calendar.component(.month, from: date) let day = calendar.component(.day, from: date) return "\(month)/\(day)/\(year)" } getDate()

Swift
View
generate functionFri, 25 Nov 2022

quicksort

def quicksort(arr): if len(arr) <= 1: return arr pivot = arr[len(arr) // 2] left = [x for x in arr if x < pivot] middle = [x for x in arr if x == pivot] right = [x for x in arr if x > pivot] return quicksort(left) + middle + quicksort(right) print(quicksort([3,6,8,10,1,2,1]))

Python
View
docstringFri, 25 Nov 2022

def quicksort(arr): if len(arr) <= 1: return arr pivot = arr[len(arr) // 2] left = [x for x in arr if x < pivot] middle = [x for x in arr if x == pivot] right = [x for x in arr if x > pivot] return quicksort(left) + middle + quicksort(right)

def quicksort(arr): """Returns the sorted array.""" if len(arr) <= 1: return arr pivot = arr[len(arr) // 2] left = [x for x in arr if x < pivot] middle = [x for x in arr if x == pivot] right = [x for x in arr if x > pivot] return quicksort(left) + middle + quicksort(right)

docstringFri, 25 Nov 2022

def quicksort(arr): if len(arr) <= 1: return arr pivot = arr[len(arr) // 2] left = [x for x in arr if x < pivot] middle = [x for x in arr if x == pivot] right = [x for x in arr if x > pivot] return quicksort(left) + middle + quicksort(right)

def quicksort(arr): """ Sorts an array with quicksort algorithm. """ if len(arr) <= 1: return arr pivot = arr[len(arr) // 2] left = [x for x in arr if x < pivot] middle = [x for x in arr if x == pivot] right = [x for x in arr if x > pivot] return quicksort(left) + middle + quicksort(right)

generate functionTue, 16 Jan 2024

bubblesort

bubblesort(lst): for i in range(len(lst) - 1): for j in range(len(lst) - i - 1): if lst[j] > lst[j + 1]: lst[j], lst[j + 1] = lst[j + 1], lst[j] def main(): lst = [random.randint(0, 100

code to explanationThu, 20 Jul 2023

const techFromSlug = context.query.tecchunks = [] while len(text) > 500: last_period_index = text[:500].rfind('.') if last_period_index == -1: last_period_index = 500 chunks.append(text[:last_period_index]) text = text[last_period_index+1:] chunks.append(text)h.slice(-1)[0];

** Blog post data here ** --- ` const createPost = ({ posts, postsDirectory }) => { return new Promise((resolve, reject) => { const slug = nanoid() // create post const post = { id: slug, content, title, date, tags } // write post to posts directory fs.writeFile( path.join(postsDirectory, `${slug}.json`), JSON.stringify(post, null, 2), error => { if (error) { reject(error) } else { // add post to posts array posts.push(post) // write updated posts array to db.json fs.writeFile( path.join(dataDirectory, 'db.json'), JSON.stringify({ posts }, null, 2), error => { if (error) { reject(error) } else { resolve(post) } }

code to explanationMon, 10 Jul 2023

const techFromSlug = context.query.tecchunks = [] while len(text) > 500: last_period_index = text[:500].rfind('.') if last_period_index == -1: last_period_index = 500 chunks.append(text[:last_period_index]) text = text[last_period_index+1:] chunks.append(text)h.slice(-1)[0];

keeps the last object in the array `chunks` ### if you want to add a new article - create a folder with the name of the article in the directory `techarticles` - add an index.mdx with the content of the article ### if you want to add a new tutorial - create a folder with the name of the tutorial in the directory `techtutorials` - add an index.mdx with the content of the tutorial ## contact You have a question, would like to comment on something or just want to say hi? Visit [my twitter](https://twitter.com/paul_lilljedahl)

generate functionSat, 05 Nov 2022

nodejs async main function

function async_main() { var args = process.argv.slice(2); let [file_name, ...file_paths] = args; fs.readFile(file_name, (err, data) => { if (err) throw err; let new_data = data.toString(); for (let fp of file_paths) { console.log(new_data.replace("world", fp)); } }) }

Javascript
View
generate functionSat, 05 Nov 2022

get 5 random objs from array

func randomObjs(objs []interface{}) []interface{} { n := 5 if n > len(objs) { n = len(objs) } newObjs := make([]interface{}, n) for i := 0; i < n; i++ { rand.Seed(time.Now().UnixNano()) newObjs[i] = objs[rand.Intn(len(objs))] } return newObjs }

Questions about programming?Chat with your personal AI assistant