Skip to content

Instantly share code, notes, and snippets.

View suneg's full-sized avatar

Sune Gynthersen suneg

  • Copenhagen, Denmark
View GitHub Profile
@stekhn
stekhn / post-to-slack.sh
Created March 2, 2020 12:21
Post to Slack using curl on the command line. The incoming webhook for your Slack team needs to be created beforehand.
# Read more about Slack webhooks here: https://api.slack.com/messaging/webhooks
curl -X POST \
-H 'Content-type: application/json; charset=utf-8' \
--data '{ "channel": "#mychannel", "username": "superbot", "icon_emoji": ":bot:", "text": "Foo" }' \
https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX
@SimGus
SimGus / maps.ts
Created January 8, 2020 20:42
Maps (dicts) in TypeScript
// When programming, there will certainly be times you will want to associate values to other values,
// that is building a dictionary.
// In TypeScript, a `Map<K, V>` exists (it seems it actually is the one defined in JavaScript ES6).
// However, at least in TypeScript 3.1.6, objects from this class are not very reliable:
// You will sometimes get errors such as "TypeError: map.get is not a function", at seemingly random times.
// A solution is to replace `Map<string, V>` by plain objects defined as `{ [key: string]: V }`.
// Another solution seems to be to replace them by `Record<string, V>`.
@treecy
treecy / .eslintrc.js
Last active May 29, 2023 14:19
ESLint for both js and ts
module.exports = {
parser: 'babel-eslint',
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true,
"experimentalObjectRestSpread": true
}
},
@elderbas
elderbas / class_controller.ex
Last active April 5, 2024 03:35
Elixir — Inserting Multiple Changesets Into Database - create batch
def create_batch(conn, %{"people" => people_params}) do
changesets = Enum.map(people_params, fn class ->
Person.changeset(%Person{}, person)
end)
result = changesets
|> Enum.with_index()
|> Enum.reduce(Ecto.Multi.new(), fn ({changeset, index}, multi) ->
Ecto.Multi.insert(multi, Integer.to_string(index), changeset)
end)
@kyletaylored
kyletaylored / image.html
Created November 16, 2016 21:00
Jekyll: HD images with Retina.js
{% comment %}
We're splitting off the file extension in order to add "@2x"
if the image is retina ready, else use a regular image with "data-no-retina".
Image extension is assumed 3 characters. PNG, JPG, GIF (no JPEG).
{% endcomment %}
{% capture img_length %}{{ include.src | size | minus:4 }}{% endcapture%}
{% assign img_ext = include.src | slice: -4,4 %}
{% assign img_name = include.src | slice: 0,img_length %}
@oinopion
oinopion / read-access.sql
Created October 5, 2016 13:00
How to create read only user in PostgreSQL
-- Create a group
CREATE ROLE readaccess;
-- Grant access to existing tables
GRANT USAGE ON SCHEMA public TO readaccess;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO readaccess;
-- Grant access to future tables
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO readaccess;
@cmawhorter
cmawhorter / troubleshooting.md
Last active February 28, 2024 16:28
Solution to AWS Lambda node.js UnrecognizedClientException "The security token included in the request is invalid."

Troubleshooting AWS unauthorized errors in lambda requests

This is mainly for node.js but might apply to other environments. Unsure.

If you are running a AWS Lambda function that calls another AWS service and getting an error about invalid tokens or other access denied errors, do this:

Check IAM

The role assigned to your lambda function will need permission to perform the actions. Check IAM and make sure the role has all the permissions.

@jesperronn
jesperronn / idea.sh
Last active October 13, 2015 16:28
IDEA vmoptions
#Line below added by jesper in idea.sh
IDEA_JDK="/opt/tools/jdk1.7.0_09"
#end line add
@carlosmcevilly
carlosmcevilly / gist:2221249
Created March 27, 2012 22:55
fix git commit with wrong email address in git config, before pushing
If:
- you add and commit with the wrong email address in git, and
- your remote has a hook set up to prevent you from pushing with the bad address
Then you need to amend the author of your commit before push can succeed:
1. fix your email address in git config:
$ git config user.name "Your Name"
@nrstott
nrstott / app.js
Created September 21, 2011 15:01
Bogart CouchDB Blog code translated to use MongoDB
var bogart = require('bogart');
var Q = require('promised-io/lib/promise');
var mongoose = require('mongoose');
var PostSchema = new mongoose.Schema({
title: String,
body: String,
comments: [ CommentSchema ]
});