Skip to content

Instantly share code, notes, and snippets.

View iuliaL's full-sized avatar
♾️

Iulia Maria Lungu iuliaL

♾️
View GitHub Profile
@iuliaL
iuliaL / txt-to-markdown.sh
Created January 26, 2023 17:00
Recursively rename all .txt files in the current directory to .md.
find . -iname "*.txt" -exec bash -c 'mv "$0" "${0%\.txt}.md"' {} \;
@iuliaL
iuliaL / index.tsx
Last active April 13, 2022 11:44
two-way databinding with Jotai atoms
/*
* This atom, when you set its value, triggers the custom write function we provide,
* and can modify the atoms it relies on. It's basically two-way data binding.
*/
import { atom, useAtom } from 'jotai';
const priceAtom = atom(10);
const priceModifier = atom(
(get) => get(priceAtom) * 2, // this is called derived atom
@iuliaL
iuliaL / palindromeCheck.elm
Last active November 28, 2019 12:10
Palindrome
transformer word =
String.toLower word
|> String.split " "
|> String.join ""
|> String.filter (\char -> char /= ',')
palindrome w = transformer w == (String.reverse <| transformer w)
isPalindrome = if palindrome "As I pee sir, I see Pisa " == True then "PALINDROME" else "NOT PALINDROME"
@iuliaL
iuliaL / isMatchingBrackets.js
Created March 2, 2019 13:29
Is matching brackets
function isMatchingBrackets(str) {
let stack = [];
const map = {
'(': ')',
'[': ']',
'{': '}'
};
let answer = false;
for (let c of [...str]) {
@iuliaL
iuliaL / day1-advent-of-code.py
Last active December 8, 2018 16:06
advent of code day 1
import datetime
input = "+15 -7 +16 +5 +12 +16 -4 +10 -1 +14 -16 +6 +4 +11 -2 +5 +4 +12 +13 +5 +16 +18 -3 -2 +9 -10 +12 -10 -17 +12 -14 -14 +11 +1 -16 +11 -5 +20 -1 +14 -15 -10 -5 +4 -17 -13 -2 -12 -15 +12 +8 -3 +13 +17 +21 +21 +8 +9 -5 -15 -19 -9 -17 -5 +15 +12 +14 +19 -2 +15 -6 +19 -2 +4 -5 -8 -4 +10 +1 -5 +10 +12 +14 -2 +11 -3 -15 -6 +14 +3 +8 +10 +14 +11 +18 +3 -4 -5 -13 +17 -12 -8 -5 +7 +7 -10 -19 +17 +1 +17 -5 -9 -10 -9 -1 -3 -14 +11 +1 +11 +1 +2 -17 +4 +19 +17 +6 +18 -4 +3 -13 +7 -3 +19 +5 +2 +6 +12 +5 -7 +10 +16 -9 -16 +11 +10 +2 +7 -16 +6 +16 +17 +11 +11 -14 +11 -16 -13 +6 +8 +10 -4 -5 +2 +5 -18 +19 -11 -5 -5 -5 -16 -5 +16 +7 -10 -20 -14 -18 +13 +9 -10 +18 -7 -8 -4 +13 +9 +18 +20 -10 -14 -22 -21 -10 +20 -7 -9 +1 +11 +6 +12 +14 -5 +16 +13 +8 -2 -13 -2 +11 +21 +9 -5 +1 +18 +6 +18 -17 +3 +7 -2 -3 +1 +7 +17 +16 +4 +13 +7 +17 -18 +17 +2 +19 -11 +2 +2 +1 -16 -19 -4 -17 -8 -5 +12 -8 +19 +3 +17 +3 +3 +8 +3 -13 +12 -7 +9 +16 +15 +3 -6 -10 +14 -13 -8 +4 +12 +19 +17 +18 -12 -11 +7 -1 -7 -28 -19 -6 +2 +15 +3 -1
@iuliaL
iuliaL / react-font-face.tsx
Created May 4, 2018 12:27
react-font-face rewritten in typescript
import * as React from 'react';
import { Helmet } from 'react-helmet';
import { Maybe } from 'tsmonad';
export {
ReactFontFace as OurReactFontFace
};
interface Config {
readonly google?: ReadonlyArray<string>;
@iuliaL
iuliaL / duration.ts
Last active March 28, 2018 13:10
Duration or time elapsed formatter using moment js (i.e 34 hours and 5 minutes, 1 hour 1 minute)
function getDuration(startTime: Date, endTime: Date): string {
const milliseconds = moment(endTime).diff(startTime);
const duration = moment.duration(milliseconds);
const durationAsHours: number = Math.floor(duration.asHours());
const restInMinutes: number = duration.minutes();
const hours: string =
durationAsHours > 1
? `${durationAsHours} hours and `
: durationAsHours > 0
? `${durationAsHours} hour and `
const moment = require('moment');
const dateFromElastic = 1521806390519;
let dateUTC = moment.utc(dateFromElastic).format('YYYY-MM-DD HH:mm');
// for interface display
let dateLocal = moment.utc(dateUTC).local().format('YYYY-MM-DD HH:mm');
// for timeFilter to use as query
let dateBackToUTC = moment(dateLocal).utc().format('YYYY-MM-DD HH:mm');
function splitArrayInArraysBySection (arr) {
const returnsObject = arr.reduce((newArrSofar, item) => {
const toAdd = newArrSofar[item.section] ? [...newArrSofar[item.section], item] : [item]
return {
...newArrSofar,
[item.section]: toAdd
}
},{});
return Object.values(returnsObject); // to return array actually
}
@iuliaL
iuliaL / .bash_profile
Last active January 9, 2018 14:33
Append git branch name to prompt (only) when in git repository
git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
export PS1="\u@\[\033[32m\]\w\[\033[33m\]\$(git_branch)\[\033[00m\]\$ "