Skip to content

Instantly share code, notes, and snippets.

@endolith
endolith / gcd_and_lcm.py
Last active June 22, 2022 23:33
GCD and LCM functions in Python for several numbers
# Greatest common divisor of 1 or more numbers.
from functools import reduce
def gcd(*numbers):
"""
Return the greatest common divisor of 1 or more integers
Examples
--------
@oodavid
oodavid / README.md
Last active June 12, 2024 00:28 — forked from aronwoost/README.md
Deploy your site with git

Deploy your site with git

This gist assumes:

  • you have a local git repo
  • with an online remote repository (github / bitbucket etc)
  • and a cloud server (Rackspace cloud / Amazon EC2 etc)
    • your (PHP) scripts are served from /var/www/html/
    • your webpages are executed by apache
  • apache's home directory is /var/www/
@ngopal
ngopal / alarm_clock_spotify.scpt
Created August 13, 2012 21:02
Setup your mac to use Spotify as your alarm clock
# In order to use this script, you must replace 'YOURUSERNAMEHERE' with your Spotify username.
# Execute this script like so: 'osascript alarm_clock_spotify.scpt' (without single-quotes obviously)
# Full explanation here: http://www.nikhilgopal.com/2011/08/show-and-tell-applescript-spotify-alarm.html
# If you would like to specify a playlist, please refer to this gist: https://gist.github.com/3344118
set volume 2
open location "spotify:user:YOURUSERNAMEHERE:playlist:muzic"
tell application "Spotify"
set the sound volume to 0
play
@kvnsmth
kvnsmth / example-subtree-usage.md
Last active March 5, 2023 21:58
A real world usage for git subtrees.

Let's say you have an iOS project, and you want to use some external library, like AFNetworking. How do you integrate it?

With submodules

Add the project to your repo:

git submodule add git@github.com:AFNetworking/AFNetworking.git Vendor/AFNetworking

or something to that effect.

Falsehoods programmers believe about prices

  1. You can store a price in a floating point variable.
  2. All currencies are subdivided in 1/100th units (like US dollar/cents, euro/eurocents etc.).
  3. All currencies are subdivided in decimal units (like dinar/fils)
  4. All currencies currently in circulation are subdivided in decimal units. (to exclude shillings, pennies) (counter-example: MGA)
  5. All currencies are subdivided. (counter-examples: KRW, COP, JPY... Or subdivisions can be deprecated.)
  6. Prices can't have more precision than the smaller sub-unit of the currency. (e.g. gas prices)
  7. For any currency you can have a price of 1. (ZWL)
  8. Every country has its own currency. (EUR is the best example, but also Franc CFA, etc.)
@rduplain
rduplain / README.md
Last active December 6, 2023 15:08
Demo of the Python `code` module, for interaction and DSLs.

import code

This is a demonstration of the Python [code][1] module, which allows for an interactive interpreter to be embedded into a Python program.

code.interact(banner=None, readfunc=None, local=None)

Convenience function to run a read-eval-print loop. This creates a new instance of [InteractiveConsole][2] and sets readfunc to be used as the

@hnakamur
hnakamur / main.go
Last active February 12, 2023 00:15
A go example to stop a worker goroutine when Ctrl-C is pressed (MIT License)
package main
import (
"fmt"
"os"
"os/signal"
"time"
"golang.org/x/net/context"
)

Deploy your site with git securely

This gist assumes:

  • you have a local git repo
  • you have an online remote repository (github)
  • you have a server running Apache with git already installed

you should be able to do the same with Java, Perl, RoR, JSP etc. however you'll need to recreate the (rather simple) PHP script

@coderofsalvation
coderofsalvation / export_process
Last active February 22, 2022 15:38
updates an environment variable of a running process
# updates an environment variable of a running process (needs sudo)
# example: sudo export_pid <variable=value> <pid>
export_process(){
script=/tmp/.gdb.$2
echo -e "attach $2\ncall putenv (\"$1\")\ndetach\n" > $script
gdb -q -batch -x $script &>/dev/null
rm $script
}
@kkiernan
kkiernan / vuejs-filter-snake-to-title.js
Last active December 6, 2021 12:34
A Vue.js filter that converts snake case to title case.
/**
* Converts a snake case string to title case.
* Example: snake_case => Snake Case
*
* @param {String} str the string to convert
* @return {String}
*/
Vue.filter('snakeToTitle', function (str) {
return str.split('_').map(function (item) {
return item.charAt(0).toUpperCase() + item.substring(1);