Skip to content

Instantly share code, notes, and snippets.

@yoavniran
yoavniran / addFrameConsciousEvent.js
Created November 1, 2015 09:04
ES6 animation frame conscious event listener
const addFrameConsciousEvent = (obj, event, handler) => { //adapted from: https://developer.mozilla.org/en-US/docs/Web/Events/resize#Example
let isRunning = false;
const handlerWrapper = (e)=> {
if (!isRunning){
isRunning = true;
requestAnimationFrame(()=>{ //throttling so only execute when the browser is ready to re-render
isRunning = false;
handler(e);
})
@yairEO
yairEO / concatWithoutDups.js
Created November 6, 2021 18:58
Concatenates N arrays without dupplications
/**
* Concatenates N arrays without dups.
* If an array's item is an Object, compare by `value`
* @param {*} k
*/
export const concatWithoutDups = (...key) => {
const result = (...args) => {
const newArr = [],
existingObj = {};
@yairEO
yairEO / removeStyleProp.js
Last active May 6, 2024 12:37
Remove a single property from DOM element "style" attribute
const removeStyleProp = (elm, prop) =>
elm.style.cssText = elm.style.cssText // cssText automatically (luckily) adds spaces between declarations
.split('; ')
.filter(p => !p.startsWith(prop) )
.join(';');
@yairEO
yairEO / math.css
Created February 3, 2022 14:31
CSS math
/***** ceil ******/
/* For a value between 0 - 1, where 1 is the maximum possible */
--ceil: clamp(0, calc((1 - var(--value)) * 100), 1);
/***** floor ******/
/* For a value between 0 - 1, where 1 is the maximum possible, use a value just a tiny bit below the maximum for the
math to work, so the output will be either positive or negative when magnified by a factor of 999999*/
@rgreenjr
rgreenjr / postgres_queries_and_commands.sql
Last active May 6, 2024 12:37
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(clock_timestamp(), query_start), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
@KobayashiRui
KobayashiRui / ROS_PS3contl.md
Last active May 6, 2024 12:37
rosやgazeboについて自分に有益なものをまとめる 参考文献 ・ROSではじめるロボットプログラミング ・プログラミングROS 参考サイト ・https://sites.google.com/site/robotlabo/time-tracker/ros/modeling_robothttp://products.rt-net.jp/micromouse/archives/3316http://wiki.ros.org/simmechanics_to_urdf/Tutorials/

PS3コントローラーの使い方(ubuntu16.04)

  1. USBでPCと接続する
  2. sudo sixpairを実行しペアリングをする
  3. USBとPCから取外す
  4. sudo sixad -sを実行しPS3の真ん中のボタンを押しBluetoothにて接続する
@yairEO
yairEO / conditional-styles.scss
Created February 5, 2022 20:50
Toggle CSS block with a single variable
// https://css-tricks.com/css-switch-case-conditions
// simplified version of my method:
.foo {
--feature: 1; // 1 is "on", 0 is "off"
animation: foo_styles 1s calc(-1s * (var(--feature) - 1)) paused;
@keyframes foo_styles {
0% {
@yairEO
yairEO / for.async.js
Created March 19, 2022 14:40
Async iterators
const delay = ms => new Promise(resolve => setTimeout(resolve, ms))
const inc = async i => (await delay(500), ++i)
const foo = async () => {
for(let i = 1; i <= 5; i = await inc(i))
console.log(i) // prints 1, 2, 3, 4, 5 with a delay
}
foo()
@yairEO
yairEO / JSON.parse.js
Created January 5, 2023 09:25
Safe javascript JSON.parse which never throws exceptions
JSON.parse = (JP => (...args) => {
try { return JP(...args) } catch{}
})(JSON.parse)
@yairEO
yairEO / sb.mdx.file-code.js
Last active May 6, 2024 12:36
storybook MDX - show code block of imported file
import { Meta, Description, Props, Source, Canvas } from '@storybook/addon-docs/blocks';
import Comp from './Comp';
import CompRaw from '!raw-loader!./Comp.jsx';
import readme from '!raw-loader!./readme.md';
<Meta
title="Comp/MDX"
component={Comp}
/>