Skip to content

Instantly share code, notes, and snippets.

View danieldram's full-sized avatar

Daniel Ram danieldram

View GitHub Profile
@danieldram
danieldram / fuzzySearch.sql
Created February 16, 2023 04:36
Fuzzy Search with SQL
// Serach for SANDRA across multiple tables and columns
SELECT * FROM (
SELECT *,
(
CASE
WHEN first_name LIKE '%SANDRA%' THEN 1
ELSE 0
END
) AS match_strength
FROM actor
@danieldram
danieldram / Terminal Window
Created December 29, 2022 04:55
Kill Ports - Mac OSX Terminal
netstat -vanp tcp | grep 7203 <--- Port Number
Kill -9 7203
@danieldram
danieldram / insecure-chrome
Created August 22, 2022 21:07
open a new insecure chrome window.
open -n -a /Applications/Google\ Chrome.app --args --user-data-dir="/tmp/someFolderName" --disable-web-security
@danieldram
danieldram / prop-to-css.js
Last active April 23, 2018 10:04
convert prop camelCase css names into standard dashed css properties to easily use in styled-components and etc.
export const PROPtoCSS = (props) => {
if(Object.keys(props).length==0) return {}
const css ={}
for(let propName in props){
const chars = propName.split(/([A-Z])/g)
const names = chars.map((v, i, arr)=>{
if(v.match(/[A-Z]/)){
arr[i+1] = `${v.toLowerCase()}${arr[i+1]}`
}
@danieldram
danieldram / Either.js
Last active April 4, 2017 06:36
Either Functional Error Handling Strategy
const Right = x =>
({
map: f => Right(f(x)),
fold: (f,g) => g(x),
inspect: f => f(`Right(${x})`)
})
const Left = x =>
({
@danieldram
danieldram / memoize_example.js
Created March 30, 2017 15:44
simple memoize sample
const memoize = (fn) => {
const cache = {}
return (...args) => {
const key = args.toString()
if(cache[key] == undefined){
cache[key] = fn(...args)
}
return cache[key]
@danieldram
danieldram / example.js
Created November 18, 2016 20:19
Recursive Random Time Function Cxecution with JavaScript ES6 Generators
function* gen(){
var rand = _.random(1000,5000);
return ()=>{
return setTimeout(()=>{
console.log('hi');
console.log(rand);
return gen().next().value();
}, rand)
}
}