Skip to content

Instantly share code, notes, and snippets.

View cymruu's full-sized avatar

filip cymruu

  • 22:07 (UTC +02:00)
View GitHub Profile
@timvisee
timvisee / falsehoods-programming-time-list.md
Last active July 24, 2024 22:18
Falsehoods programmers believe about time, in a single list

Falsehoods programmers believe about time

This is a compiled list of falsehoods programmers tend to believe about working with time.

Don't re-invent a date time library yourself. If you think you understand everything about time, you're probably doing it wrong.

Falsehoods

  • There are always 24 hours in a day.
  • February is always 28 days long.
  • Any 24-hour period will always begin and end in the same day (or week, or month).
@joepie91
joepie91 / random.md
Last active July 13, 2024 16:15
Secure random values (in Node.js)

Not all random values are created equal - for security-related code, you need a specific kind of random value.

A summary of this article, if you don't want to read the entire thing:

  • Don't use Math.random(). There are extremely few cases where Math.random() is the right answer. Don't use it, unless you've read this entire article, and determined that it's necessary for your case.
  • Don't use crypto.getRandomBytes directly. While it's a CSPRNG, it's easy to bias the result when 'transforming' it, such that the output becomes more predictable.
  • If you want to generate random tokens or API keys: Use uuid, specifically the uuid.v4() method. Avoid node-uuid - it's not the same package, and doesn't produce reliably secure random values.
  • If you want to generate random numbers in a range: Use random-number-csprng.

You should seriously consider reading the entire article, though - it's

# GIT heart FZF
# -------------
is_in_git_repo() {
git rev-parse HEAD > /dev/null 2>&1
}
fzf-down() {
fzf --height 50% --min-height 20 --border --bind ctrl-/:toggle-preview "$@"
}
@brennanMKE
brennanMKE / hero.ts
Last active July 15, 2024 15:25
Example of Mongoose with TypeScript and MongoDb
import * as mongoose from 'mongoose';
export let Schema = mongoose.Schema;
export let ObjectId = mongoose.Schema.Types.ObjectId;
export let Mixed = mongoose.Schema.Types.Mixed;
export interface IHeroModel extends mongoose.Document {
name: string;
power: string;
@ae6rt
ae6rt / AngularJS-apply.scope
Last active August 30, 2018 22:37
An AngularJS websocket service that updates a controller scope variable
var app = angular.module('app', []);
app.controller('controller', function ($scope, websocketService) {
$scope.msg = "...";
websocketService.start("ws://localhost:8080/events", function (evt) {
var obj = JSON.parse(evt.data);
$scope.$apply(function () {
$scope.msg = obj.message
});
@codecat
codecat / imgur-uploader
Created July 4, 2012 22:23 — forked from robertbasic/imgur-uploader
xfce4-screenshooter to imgur
#!/bin/bash
# Ubuntu Keyboard settings shortcut:
# xfce4-screenshooter -r -o "sh /location/to/imgur-uploader.sh"
API_KEY=YOUR_API_KEY_GOES_HERE
URL=http://api.imgur.com/2/upload
RESPONSE=$(curl -s -F "key=$API_KEY" -F "image=@$1" $URL)
echo "$RESPONSE" | grep -o -E "<original>.*</original>" | grep -o -E "http://.*\.png" | xsel -i -b