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
// Contrary to what the expo-location documentation says: | |
// > To use Background Location methods, the following requirements apply: | |
// > Location permissions must be granted. On iOS it must be granted with Always option. | |
// It is possible to use expo-location to follow location updates in the background or from the lock screen, with the WhenInIUse permission. | |
// The trick is to only request foreground permissions, but use `startLocationUpdatesAsync` and `expo-task-manager`. | |
// This context demonstrates how: | |
import * as Location from 'expo-location'; | |
import * as TaskManager from 'expo-task-manager'; | |
import React, { useState, useEffect } from 'react'; |
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 Express, { Application, Request, Response, NextFunction } from 'express'; | |
import Koa, { Context, Next } from 'koa'; | |
const middleware = async (req: Request | Context['request'], res: Response | Context['response'], next: NextFunction) => { | |
console.log('Time:', Date.now()); | |
await next(); | |
} | |
interface Options {} |
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
# nohup ./daylight.sh 1.33 >> daylight.log 2>&1 & | |
( | |
echo "Getting daylight $1 planet file" | |
wget -c --quiet https://daylight-map-distribution.s3.amazonaws.com/release/v$1/planet-v$1.osm.pbf | |
) &\ | |
( | |
( | |
echo "Getting daylight $1 buildings file" | |
wget -c --quiet https://daylight-map-distribution.s3.amazonaws.com/release/v$1/ml-buildings-v$1.osm.pbf | |
) &\ |
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 OR REPLACE FUNCTION numPadEnc( | |
IN source NUMERIC DEFAULT (extract(epoch from now())*1000000)::bigint, | |
IN prefix TEXT DEFAULT '', | |
IN pad TEXT DEFAULT '123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz', | |
IN seed INTEGER DEFAULT floor(random() * 10 + 1)::int | |
) RETURNS TEXT AS $$ | |
DECLARE | |
calc TEXT := source::text; | |
output TEXT := prefix; | |
chr TEXT := ''; |
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
// ****************************** | |
// Serverless Vue Webpack Config | |
// ****************************** | |
const Path = require('path') | |
const TerserJSPlugin = require('terser-webpack-plugin'); | |
const MiniCssExtractPlugin = require('mini-css-extract-plugin'); | |
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin'); |
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 TRIGGER person_notify AFTER INSERT OR UPDATE OR DELETE ON income | |
FOR EACH ROW EXECUTE PROCEDURE notify_trigger( | |
'id', | |
'email', | |
'username' | |
); | |
CREATE TRIGGER income_notify AFTER INSERT OR UPDATE OR DELETE ON income | |
FOR EACH ROW EXECUTE PROCEDURE notify_trigger( | |
'id', |
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
Let's say you got a Job model and you want to track index_count, show_count, etc. | |
Why not use Hstore? | |
Add a migration: | |
class AddHstoreCountsOnJobs < ActiveRecord::Migration | |
def change | |
add_column :jobs, :index_count, :hstore, default: {} | |
add_column :jobs, :show_count, :hstore, default: {} |
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
validate_form = -> | |
$('form').submit (event) -> | |
$.each $(this).find('input'), (i,el) -> | |
validate_field(el); | |
$(el).on 'blur', -> validate_field(el) ; | |
window.validate_form = validate_form | |
validate_field = (el) -> | |
if ($(el)[0].checkValidity()) |
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 OR REPLACE FUNCTION time_ago_in_words(timestamp with time zone) | |
RETURNS text | |
LANGUAGE SQL | |
AS $$ | |
SELECT CASE | |
WHEN date_part('year', age(current_timestamp, $1)) = 1 THEN concat(date_part('year', age(current_timestamp, $1)), ' year ago') | |
WHEN date_part('year', age(current_timestamp, $1)) > 1 THEN concat(date_part('year', age(current_timestamp, $1)), ' years ago') | |
WHEN date_part('month', age(current_timestamp, $1)) = 1 THEN concat(date_part('month', age(current_timestamp, $1)), ' month ago') | |
WHEN date_part('month', age(current_timestamp, $1)) > 1 THEN concat(date_part('month', age(current_timestamp, $1)), ' months ago') | |
WHEN date_part('day', age(current_timestamp, $1)) = 1 THEN concat(date_part('day', age(current_timestamp, $1)), ' day ago') |
NewerOlder