Skip to content

Instantly share code, notes, and snippets.

DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 YOUR_NAME_HERE <YOUR_URL_HERE>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
defmodule ZigZagConversion do
@moduledoc """
Qqwy's solution to https://leetcode.com/problems/zigzag-conversion/
"""
@doc """
Converts a string into a zig-zagged string:
- the characters of string is distributed over `num_rows`, as follows:
defmodule Modulo do
defmacro guard_safe_int_max(a, b) do
quote do
div(unquote(a)+unquote(b) + abs(unquote(a) - unquote(b)), 2)
end
end
defmacro int_sign(x) do
quote do
@Qqwy
Qqwy / early_exit.cc
Created September 12, 2016 14:45
Shows why early exit on failure is a good code style strategy.
/*
In this snippet, the failure cases are not close to the conditions they belong to.
This makes it hard to track when which error case is triggered (especially when they are more than a screen height apart).
It also adds a lot of `{}` and indentation.
*/
int someFunction(int foo, int bar, int baz)
{
if (foo == 1)
{
@Qqwy
Qqwy / scream.ex
Last active July 19, 2017 03:15
How exclamation marks are supposed to be used in Elixir
defmodule Scream do
defmacro scream!(ast) do
{exclams, res} = count_exclams(ast, 0)
case exclams do
_ when exclams < 5 ->
quote do "You say: #{inspect(unquote(res))}." end
_ when exclams < 10 ->
quote do "You yell: #{inspect(unquote(res))}!" end
_ when exclams < 15 ->
quote do "You scream: #{inspect(unquote(res))}!!" end
@Qqwy
Qqwy / IsPrime.hs
Last active February 12, 2018 18:09
Prime Checker without doing any division or modulo
{-#OPTIONS_GHC -O2 -optc-O3 #-}
{-
Author: Wiebe-Marten Wijnja
Date: 2018-02-12
This simple program is a Prime Checker.
It is special, in that does not perform any
division or modulo operations to check if a number is a prime,
which most prime checkers or prime sieves do.
@Qqwy
Qqwy / LICENSE.txt
Last active March 8, 2018 11:40 — forked from 140bytes/LICENSE.txt
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 YOUR_NAME_HERE <YOUR_URL_HERE>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@Qqwy
Qqwy / classical_star_phase.c
Last active November 27, 2018 09:26
Bytebeat implementation of a classical piece of music, using a single sinusoid and comparing the naive, discontinuous signal with an improved, phase-accumulation based version.
/*
* Date: 2018-11-26
* Author of this C code: Wiebe-Marten Wijnja (Qqwy).
* Author of original JavaScript-version: Unknown.
*
* This version uses phase-accumulation to ensure that the signal remains continuous throughout,
* and that there are no nasty clicks when we change to the next note.
* You can add the directive `DISCONTINUOUS VERSION` (using e.g. the `-D` flag of `gcc` and `clang`)
* to compile it as the original version, that bases its samples only directly on the current sample,
* and therefore includes clicks whenever the note changes.
function base64ImageUploader(dialog) {
var reader, image_url, img;
var canvas = document.createElement("canvas");
var canvas_context = canvas.getContext('2d');
function rotateImage(direction){
//These are swapped when rotating
{-# LANGUAGE DataKinds, KindSignatures, TypeFamilies, PolyKinds, GADTs #-}
module Example where
import qualified Control.Arrow
import qualified Prelude
import Prelude hiding (id, (.))
import qualified Control.Category
-- | Example type: A Qfun is a function with a Quality: Either 'Good' or 'Bad'.