This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }), []) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
global | |
#debug | |
#daemon | |
log 127.0.0.1 local0 | |
defaults | |
log global | |
option httplog | |
frontend unsecured *:80 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TasksController | |
def index | |
Task.where(IndexParams.new(params).params) | |
end | |
def create | |
Task.create!(CreateParams.new(params).params) | |
end | |
private |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ... | |
location @app { | |
# ... | |
if (-f $document_root/system/maintenance.html) { | |
return 503; | |
} | |
# proxy_pass ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Payment | |
include DataMapper::Resource | |
belongs_to :payee, User | |
belongs_to :payer, User | |
property :id, Serial | |
# ... | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
chars = ('A'..'Z').to_a + ('a'..'z').to_a + ('0'..'9').to_a | |
str = (1..50).map { chars[rand(chars.size)] }.join |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 | |
# | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# works | |
require 'rest_client' | |
# broken | |
dependency 'rest-client' | |
# broken | |
dependency 'rest_client' | |
# this might work!? |
NewerOlder