Skip to content

Instantly share code, notes, and snippets.

View ushu's full-sized avatar

Aurélien Noce ushu

View GitHub Profile
@ushu
ushu / useSafeState.ts
Last active April 24, 2020 19:24
A(nother) version of setState that won't raise an error when called on an unmounted component, TypeScript version
import {
useState,
Dispatch,
SetStateAction,
useRef,
useEffect,
useCallback,
} from "react"
function useSafeState<S = undefined>(
@ushu
ushu / generate_app_json.rb
Created February 14, 2019 11:57
Generate a new app.json file for the current project
#!/usr/bin/env ruby
require 'json'
# Grab info from the heroku cli
info = JSON.load(`heroku info --json`)
env_variables = JSON.load(`heroku config --json`)
buildpacks = `heroku buildpacks`.lines[1..].map{ |l| { 'url' => l[3..].chop }}
addons = JSON.load(`heroku addons --json`).inject(Hash.new{ |h, k| h[k] = [] }) { |h, e|
name = e['addon_service']['name']
plan = e['plan']['name']
@ushu
ushu / hello_world.asm
Last active September 25, 2017 12:19
Hello World on NASM that runs on a Mac
; Basic Hello World that compiles on MacOS
; nasm -fmacho64 test.asm && cc test.o -Wl,-no_pie && ./a.out
global _main
extern _puts, _exit
section .text
_main:
; Saves the stack, not really useful here but will ensure the stack is 16 bits-aligned
@ushu
ushu / init.coffee
Last active June 9, 2016 07:33
Atom Settings
# Your init script
#
# Atom will evaluate this file each time a new window is opened. It is run
# after packages are loaded/activated and after the previous editor state
# has been restored.
#
# An example hack to log to the console when each text editor is saved.
#
# atom.workspace.observeTextEditors (editor) ->
# editor.onDidSave ->
@ushu
ushu / commit-msg
Created January 6, 2016 10:18
Commit hooks to prepend jira tags to commits (using the name of the current branch)
#!/usr/bin/env ruby
# Avoid commiting when the commit message contains ONLY the JIRA tag
# Get the name of the current branch
current_branch = `git symbolic-ref --short HEAD`
# Check if we are on a JIRA branch
TAG_REGEX = /^([[:alpha:]]+)[-_](\d+)$/
if current_branch =~ TAG_REGEX
file_name = ARGV[0]
[
{
"Author": "MissHannahMinx",
"Title": "Japanese Word of The Day - Saikou 最高!",
"VideoUrl": "https://www.youtube.com/watch?v=3an7Nd_UJMQ",
"PlaceholderUrl": "https://i.ytimg.com/vi/LzOihTM-6SQ/mqdefault.jpg"
},
{
"Author": "MissHannahMinx",
"Title": "Japanese Word of the Day - TEENY TINY 小さい!",
@ushu
ushu / gist:5bb4ea0c4ef9a8299437
Created October 16, 2014 16:08
Another Dockerfile to run compiled program
FROM ubuntu:trusty
RUN apt-get update
# C/C++
RUN apt-get install -y build-essential
# Ruby
RUN apt-get install -y ruby
@ushu
ushu / code.rb
Created October 16, 2014 16:04
A dumb program that sums its input
input = STDIN.read.split("\n")
input.shift # skip first line
puts input.map { |x| Integer(x) }.inject(&:+)
@ushu
ushu / build.sh
Created October 16, 2014 16:01
Run a given program against an input
#!/bin/bash
cd /code
if [ -e code.c ]; then
gcc -o runner code.c || exit 1
cat input | runner
elif [ -e code.cpp ]; then
cat input | runner
elif [ -e code.rb ]; then
@ushu
ushu / Dockerfile
Last active August 29, 2015 14:07
Simple Dockerfile with compilers/interpreters
FROM ubuntu:trusty
RUN apt-get update
# basic build tools
RUN apt-get install -y build-essential
# Ruby
RUN apt-get install -y ruby