Skip to content

Instantly share code, notes, and snippets.

View myobie's full-sized avatar

Nathan myobie

View GitHub Profile
@myobie
myobie / useStateWithReactiveInput.ts
Last active July 7, 2023 16:02 — forked from schickling/useStateWithReactiveInput.ts
Reactive `useState` variant
import React from 'react'
/**
* A variant of `React.useState` which allows the `inputState` to change over time as well.
* Important: This hook is synchronous / single-render-pass (i.e. doesn't use `useEffect` or `setState` directly).
*/
const useStateWithReactiveInput = <T>(inputState: T): [T, (newState: T | ((prev: T) => T)) => void] => {
const [_, rerender] = React.useState(0)
const stateRef = React.useMemo<{ current: T }>(() => ({ current: inputState }), [])
@myobie
myobie / slugify.sql
Created June 1, 2019 16:19 — forked from kez/slugify.sql
Generating Slugs in Postgres
CREATE EXTENSION IF NOT EXISTS "unaccent"
CREATE OR REPLACE FUNCTION slugify("value" TEXT)
RETURNS TEXT AS $$
-- removes accents (diacritic signs) from a given string --
WITH "unaccented" AS (
SELECT unaccent("value") AS "value"
),
-- lowercases the string
"lowercase" AS (
global
#debug
#daemon
log 127.0.0.1 local0
defaults
log global
option httplog
frontend unsecured *:80
class TasksController
def index
Task.where(IndexParams.new(params).params)
end
def create
Task.create!(CreateParams.new(params).params)
end
private
@myobie
myobie / nginx.conf
Created December 31, 2012 19:12 — forked from anonymous/nginx.conf
# ...
location @app {
# ...
if (-f $document_root/system/maintenance.html) {
return 503;
}
# proxy_pass ...
class Payment
include DataMapper::Resource
belongs_to :payee, User
belongs_to :payer, User
property :id, Serial
# ...
end
@myobie
myobie / gist:49759
Created January 21, 2009 00:03 — forked from eltiare/gist:49680
chars = ('A'..'Z').to_a + ('a'..'z').to_a + ('0'..'9').to_a
str = (1..50).map { chars[rand(chars.size)] }.join
# Rails initializer for CouchDB
begin
config = YAML::load(File.open('config/couchdb.yml'))
rescue
puts "ERROR: Could not read config/couchdb.yml"
exit(1)
end
begin
RelaxDB.configure(config[RAILS_ENV])
@myobie
myobie / gist:37528
Created December 18, 2008 15:29 — forked from wmoxam/gist:37525
#!/usr/bin/env ruby
#
# Be sure to configure this node in the plugin configuration
# Memory stats must be run by root
# Ex:
# [passenger_memory]
# user root
# env.memory_stats_command path_to_passenger-memory-stats
#
@myobie
myobie / init.rb
Created October 31, 2008 21:20 — forked from zackchandler/init.rb
# works
require 'rest_client'
# broken
dependency 'rest-client'
# broken
dependency 'rest_client'
# this might work!?