Skip to content

Instantly share code, notes, and snippets.

@markembling
markembling / hosts.ps1
Created August 24, 2009 13:38
Powershell script for adding/removing/viewing entries to the hosts file.
#
# Powershell script for adding/removing/showing entries to the hosts file.
#
# Known limitations:
# - does not handle entries with comments afterwards ("<ip> <host> # comment")
#
$file = "C:\Windows\System32\drivers\etc\hosts"
function add-host([string]$filename, [string]$ip, [string]$hostname) {
@ryanflorence
ryanflorence / static_server.js
Last active April 26, 2024 16:18
Node.JS static file web server. Put it in your path to fire up servers in any directory, takes an optional port argument.
var http = require("http"),
url = require("url"),
path = require("path"),
fs = require("fs")
port = process.argv[2] || 8888;
http.createServer(function(request, response) {
var uri = url.parse(request.url).pathname
, filename = path.join(process.cwd(), uri);
@liddellj
liddellj / DateTimeExtensions.cs
Created May 19, 2011 11:39
C# DateTime to Unix Timestamp Extension Method
public static class DateTimeExtensions
{
public static long ToUnixTimestamp(this DateTime d)
{
var duration = d - new DateTime(1970, 1, 1, 0, 0, 0);
return (long)duration.TotalSeconds;
}
}
@CristinaSolana
CristinaSolana / gist:1885435
Created February 22, 2012 14:56
Keeping a fork up to date

1. Clone your fork:

git clone git@github.com:YOUR-USERNAME/YOUR-FORKED-REPO.git

2. Add remote from original repository in your forked repository:

cd into/cloned/fork-repo
git remote add upstream git://github.com/ORIGINAL-DEV-USERNAME/REPO-YOU-FORKED-FROM.git
git fetch upstream
@respectTheCode
respectTheCode / static_server.js
Created February 27, 2012 20:36 — forked from ryanflorence/static_server.js
Node.JS static file web server. Put it in your path to fire up servers in any directory, takes an optional port argument.
var http = require("http"),
url = require("url"),
path = require("path"),
fs = require("fs"),
mime = require("mime")
port = process.argv[2] || 8888;
http.createServer(function(request, response) {
var uri = url.parse(request.url).pathname
@prabirshrestha
prabirshrestha / socket.io.cs
Created May 22, 2012 15:56
socket.io 4 .net
namespace WebSocketHelloEchoServer.SocketIo
{
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Net.WebSockets;
using System.Reflection;
@andsens
andsens / dump.sh
Last active October 24, 2023 07:04
Backup all MySQL databases into separate files
#!/bin/sh
## backup each mysql db into a different file, rather than one big file
## as with --all-databases. This will make restores easier.
## To backup a single database simply add the db name as a parameter (or multiple dbs)
## Putting the script in /var/backups/mysql seems sensible... on a debian machine that is
## Create the user and directories
# mkdir -p /var/backups/mysql/databases
# useradd --home-dir /var/backups/mysql --gid backup --no-create-home mysql-backup
## Remember to make the script executable, and unreadable by others
@dhlavaty
dhlavaty / AbsoluteUrl.cs
Last active August 30, 2021 07:46
How to get an Absolute URLs in ASP.NET MVC without HttpContext and/or UrlHelper
public static class AbsoluteUrl
{
private static bool initializedAlready = false;
private static Object initlock = new Object();
// AbsoluteUrl without parameters
public static string MVC_Home_Index;
public static string MVC_MyArea_Settings_Index;
// AbsoluteUrl with parameters
@kmaida
kmaida / convert-UNIX-timestamp.js
Last active March 16, 2023 09:31
Convert a UNIX timestamp to user's local time via JavaScript
function convertTimestamp(timestamp) {
var d = new Date(timestamp * 1000), // Convert the passed timestamp to milliseconds
yyyy = d.getFullYear(),
mm = ('0' + (d.getMonth() + 1)).slice(-2), // Months are zero based. Add leading 0.
dd = ('0' + d.getDate()).slice(-2), // Add leading 0.
hh = d.getHours(),
h = hh,
min = ('0' + d.getMinutes()).slice(-2), // Add leading 0.
ampm = 'AM',
time;
@plentz
plentz / nginx.conf
Last active May 17, 2024 09:08
Best nginx configuration for improved security(and performance)
# to generate your dhparam.pem file, run in the terminal
openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048