Skip to content

Instantly share code, notes, and snippets.

@DesignFront
DesignFront / detect-dark-mode.js
Last active September 12, 2021 20:04
Detect Darkmode
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
// dark mode
}
// to watch for changes:
window.matchMedia('(prefers-color-scheme: dark)').addListener(function (e) {
console.log(`changed to ${e.matches ? "dark" : "light"} mode`)
});
@MrKioZ
MrKioZ / Simple CSS
Created November 19, 2019 19:00
My first css page
<!DOCTYPE html>
<html>
<title>Internet Jobs</title>
<style type="text/css">
::selection {
background: #ffb7b7; /* WebKit/Blink Browsers */
}
::-moz-selection {
background: #ffb7b7; /* Gecko Browsers */
@gunjanpatel
gunjanpatel / revert-a-commit.md
Last active December 3, 2024 15:11
Git HowTo: revert a commit already pushed to a remote repository

Revert the full commit

Sometimes you may want to undo a whole commit with all changes. Instead of going through all the changes manually, you can simply tell git to revert a commit, which does not even have to be the last one. Reverting a commit means to create a new commit that undoes all changes that were made in the bad commit. Just like above, the bad commit remains there, but it no longer affects the the current master and any future commits on top of it.

git revert {commit_id}

About History Rewriting

Delete the last commit

Deleting the last commit is the easiest case. Let's say we have a remote origin with branch master that currently points to commit dd61ab32. We want to remove the top commit. Translated to git terminology, we want to force the master branch of the origin remote repository to the parent of dd61ab32:

@dbrgn
dbrgn / create_django_session.py
Last active August 12, 2024 04:27
Manually create a Django session
from django.contrib import auth
from django.contrib.sessions.backends.db import SessionStore
session = SessionStore(None)
session.clear()
session.cycle_key()
session[auth.SESSION_KEY] = user._meta.pk.value_to_string(user)
session[auth.BACKEND_SESSION_KEY] = 'django.contrib.auth.backends.ModelBackend'
session[auth.HASH_SESSION_KEY] = user.get_session_auth_hash()
session.save()
@max-kov
max-kov / matrix.py
Last active July 2, 2022 02:13
matrix falling code in python using pygame
import pygame, pygame.font
import random
def IsWritten():
defTemp = True
for x in xrange((lettersOnScreen[0] / 2) - (len(str) / 2), (lettersOnScreen[0] / 2) + (len(str) / 2) + 1):
if xHeads[x] == -1:
defTemp = False
return defTemp
@ascv
ascv / calc.py
Last active March 17, 2022 04:06
A simple python calculator to demo recursive descent parsing. Execute the script to use the calculator. It accepts only well formed input. Use parentheses to specify operator precedence.
"""
exp ::= term | exp + term | exp - term
term ::= factor | factor * term | factor / term
factor ::= number | ( exp )
"""
class Calculator():
def __init__(self, tokens):
self._tokens = tokens
self._current = tokens[0]
@larsar
larsar / shared_folder_centos_virtualbox.txt
Created January 27, 2012 08:04
Mount shared folder on CentOS in VirtualBox
# The VirtualBox documentation[1] for how to install guest additions
# for Linux on a virtual host is somewhat messy. So here is what
# I did to make it work.
# Install the packages required
yum update
yum install gcc kernel-devel make
reboot
@epicserve
epicserve / ubuntu-server-django-guide.rst
Last active December 6, 2024 20:55
Ubuntu Server Setup Guide for Django Websites